Skip to content

Commit

Permalink
avoids showing trailing underscore for taxa that do not have taxonomy
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosp420 committed Oct 2, 2015
1 parent 2d27722 commit 8e43c46
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions dataset_creator/nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def convert_to_string(self, block):
if not out:
out = '[{0}]\n'.format(seq_record.gene_code)
taxonomy_as_string = self.flatten_taxonomy(seq_record)
taxon_id = '{0}_{1}'.format(seq_record.voucher_code, taxonomy_as_string)
taxon_id = '{0}{1}'.format(seq_record.voucher_code, taxonomy_as_string)

if self.aminoacids is True:
seq = seq_record.translate()
Expand All @@ -91,14 +91,13 @@ def flatten_taxonomy(self, seq_record):
return out
else:
if 'family' in seq_record.taxonomy:
out += seq_record.taxonomy['family']
out += '_' + seq_record.taxonomy['family']
if 'genus' in seq_record.taxonomy:
out += '_' + seq_record.taxonomy['genus']
if 'species' in seq_record.taxonomy:
out += '_' + seq_record.taxonomy['species']

removed_double_underscores = re.sub('_+', '_', out)
return re.sub('^_', '', removed_double_underscores)
return re.sub('_+', '_', out)


class DatasetFooter(object):
Expand Down

0 comments on commit 8e43c46

Please sign in to comment.