Skip to content

Commit

Permalink
Fix issue #7
Browse files Browse the repository at this point in the history
Fix the IndexError: list index out of range that happens when some midori sequences exceed the maximum taxonomic path length
  • Loading branch information
xapple committed Feb 28, 2024
1 parent 039441d commit 49f3f1a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 1 addition & 4 deletions crest4/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,7 @@ def rank_names(self):
'Family', # 8
'Genus', # 9
'Species', # 10
'Strain', # 11
'Strain', # 12
'Strain', # 13 (There is a problem with too many ranks
'Strain'] # 14 in some databases requiring this)
'Strain'] # 11

###############################################################################
# As our databases should only be stored on disk once, so we have singletons #
Expand Down
13 changes: 10 additions & 3 deletions crest4/otu_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,17 @@ def __call__(self, cumulative=False):
# Have the assignment as a separate column and not as an index #
result = result.reset_index()
result = result.rename(columns = {'index': 'taxonomy'})
# Add the rank column that tells the user if it's a genus or a family #
# Function that takes the length of the taxonomic path and tells
# us which rank it represents
rank_names = self.classify.database.rank_names
tax_to_rank = lambda t: rank_names[len(t.split(';')) - 1]
ranks = result.taxonomy.apply(tax_to_rank)
def tax_to_rank(t):
# There is a problem with too many ranks in some databases
# requiring this.
length = len(t.split(';')) - 1
if length > len(rank_names) - 1: return "Strain"
else: return rank_names[length]
# Add the rank column that tells the user if it's a genus or a family #
ranks = result.taxonomy.apply(tax_to_rank)
result.insert(loc=0, column='rank', value=ranks)
# Sort the table by the taxonomy string #
result = result.sort_values(by=['taxonomy'])
Expand Down

0 comments on commit 49f3f1a

Please sign in to comment.