Skip to content

Commit

Permalink
fix sorting redundant output by taxonomic level
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanf committed Feb 17, 2021
1 parent 8e0158e commit f7f2175
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Guilds_v1.1.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@
for record in db_url:
# current_record = json.loads(record)
current_record = record
# needs to be int for sorting later
current_record['taxonomicLevel'] = int(current_record['taxonomicLevel'])
if current_record['taxonomicLevel'] == 20: # If species level
current_record['taxon'] = current_record['taxon'].replace(' ', '_')
try:
Expand Down Expand Up @@ -187,6 +189,7 @@
#print(header)
index_tax = header.index(lookup)
index_notes = header.index('Notes')
index_level = header.index('Taxon Level')

#Abort if the column 'taxonomy' is not found
if index_tax == -1:
Expand Down Expand Up @@ -254,7 +257,7 @@
#Dereplicate and write to output file##########################################################
#Sort by OTU names and Level. Level is sorted from species to kingdom.
otu_sort = otu_redundant[:]
otu_sort.sort(key = itemgetter(index_tax), reverse = True) # Sort the redundant OTU table by Taxonomic Level.
otu_sort.sort(key = itemgetter(index_level), reverse = True) # Sort the redundant OTU table by Taxonomic Level.
otu_sort.sort(key = itemgetter(0)) # Sort the redundant OTU table by OTU ID.

#Dereplicate the OTU table, unique OTU ID with lowest taxonomic level will be kept.
Expand Down

0 comments on commit f7f2175

Please sign in to comment.