Skip to content

Commit

Permalink
Merge 9118da7 into 0bceac4
Browse files Browse the repository at this point in the history
  • Loading branch information
ebolyen committed Mar 15, 2019
2 parents 0bceac4 + 9118da7 commit 3b6e358
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
33 changes: 23 additions & 10 deletions q2_shogun/_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

import itertools

from qiime2.plugin import model


Expand All @@ -20,13 +22,24 @@ def _validate_(self, level):


class Bowtie2IndexDirFmt(model.DirectoryFormat):
idx1 = model.File(r'.+(?<!\.rev)\.1\.bt2', format=Bowtie2IndexFileFormat)
idx2 = model.File(r'.+(?<!\.rev)\.2\.bt2', format=Bowtie2IndexFileFormat)
ref3 = model.File(r'.+\.3\.bt2', format=Bowtie2IndexFileFormat)
ref4 = model.File(r'.+\.4\.bt2', format=Bowtie2IndexFileFormat)
rev1 = model.File(r'.+\.rev\.1\.bt2', format=Bowtie2IndexFileFormat)
rev2 = model.File(r'.+\.rev\.2\.bt2', format=Bowtie2IndexFileFormat)

def get_name(self):
filename = str(self.idx1.path_maker().relative_to(self.path))
return filename.rsplit('.1.bt2')[0]
idx1 = model.File(r'.+(?<!\.rev)\.1\.bt2l?', format=Bowtie2IndexFileFormat)
idx2 = model.File(r'.+(?<!\.rev)\.2\.bt2l?', format=Bowtie2IndexFileFormat)
ref3 = model.File(r'.+\.3\.bt2l?', format=Bowtie2IndexFileFormat)
ref4 = model.File(r'.+\.4\.bt2l?', format=Bowtie2IndexFileFormat)
rev1 = model.File(r'.+\.rev\.1\.bt2l?', format=Bowtie2IndexFileFormat)
rev2 = model.File(r'.+\.rev\.2\.bt2l?', format=Bowtie2IndexFileFormat)

def get_basename(self):
paths = [str(x.relative_to(self.path)) for x in self.path.iterdir()]
prefix = _get_prefix(paths)
return prefix[:-1] # trim trailing '.'


# SO: https://stackoverflow.com/a/6718380/579416
def _get_prefix(strings):
def all_same(x):
return all(x[0] == y for y in x)

char_tuples = zip(*strings)
prefix_tuples = itertools.takewhile(all_same, char_tuples)
return ''.join(x[0] for x in prefix_tuples)
4 changes: 1 addition & 3 deletions q2_shogun/_shogun.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ def setup_database_dir(tmpdir, database, refseqs, reftaxa):
reftaxa.to_csv(os.path.join(tmpdir, 'taxa.tsv'), sep='\t')
shutil.copytree(str(database), os.path.join(tmpdir, BOWTIE_PATH),
copy_function=duplicate)
# 'bowtie2': os.path.join(BOWTIE_PATH, database.get_name())
params = {
'general': {
'taxonomy': 'taxa.tsv',
'fasta': 'refseqs.fna'
},
'bowtie2': os.path.join(BOWTIE_PATH, 'genomes.small')
'bowtie2': os.path.join(BOWTIE_PATH, database.get_basename())
}
with open(os.path.join(tmpdir, 'metadata.yaml'), 'w') as fh:
yaml.dump(params, fh, default_flow_style=False)
Expand Down Expand Up @@ -87,7 +86,6 @@ def minipipe(query: DNAFASTAFormat, reference_reads: DNAFASTAFormat,
threads: int = 1, percent_id: float = 0.98) -> (
biom.Table, biom.Table, biom.Table, biom.Table):
with tempfile.TemporaryDirectory() as tmpdir:
# database_dir = tmpdir.name
setup_database_dir(tmpdir,
database, reference_reads, reference_taxonomy)

Expand Down

0 comments on commit 3b6e358

Please sign in to comment.