Skip to content

Commit

Permalink
Switch to tab delimited output files, with semi-colons for further di…
Browse files Browse the repository at this point in the history
…visions
  • Loading branch information
xapple committed Jul 9, 2021
1 parent 6f63a5f commit 74b7698
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
# The results of the pytest cases #
search.hits
assignments.txt
otus_by_rank.csv
otus_cumulative.csv
otus_by_rank.tsv
otus_cumulative.tsv
10 changes: 6 additions & 4 deletions crest4/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,12 @@ def __call__(self):
self.out_file.writelines(query.tax_string for query in self.queries)
# Special case where an OTU table was passed #
if self.otu_table:
otus_by_rank = self.output_dir + 'otus_by_rank.csv'
otus_cumulative = self.output_dir + 'otus_cumulative.csv'
self.otu_info(cumulative=False).to_csv(otus_by_rank, index=False)
self.otu_info(cumulative=True).to_csv(otus_cumulative, index=False)
path_by_rank = self.output_dir + 'otus_by_rank.tsv'
path_cumulative = self.output_dir + 'otus_cumulative.tsv'
otus_by_rank = self.otu_info.otus_by_rank
otus_cumulative = self.otu_info.otus_cumulative
otus_by_rank.to_csv(path_by_rank, index=False, sep='\t')
otus_cumulative.to_csv(path_cumulative, index=False, sep='\t')
# Print a success message #
msg = "Classification ran successfully. Results are placed in '%s'."
print(msg % self.out_file)
Expand Down
8 changes: 4 additions & 4 deletions crest4/otu_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,22 @@ def __call__(self, cumulative=False):
# By default the root is at the end
tax = list(reversed(tax))
# Make a string #
tax_name = ' / '.join(tax)
tax_name = '; '.join(tax)
# Add the current counts to that particular taxonomy #
result[tax_name] += otu_counts
# If we have the cumulative option then propagate up the tree #
if cumulative:
for step in range(1, len(tax)):
tax_name = ' / '.join(tax[0:-step])
tax_name = '; '.join(tax[0:-step])
result[tax_name] += otu_counts
# Convert to a DataFrame #
result = pandas.DataFrame(result).T
# Have the assignment as a separate column #
result = result.reset_index()
result = result.rename(columns = {'index': 'taxonomy'})
# Add the rank column that tells you if it's a genus or a family #
# Add the rank column that tells the user if it's a genus or a family #
rank_names = self.classify.database.rank_names
tax_to_rank = lambda t: rank_names[len(t.split('/')) - 1]
tax_to_rank = lambda t: rank_names[len(t.split(';')) - 1]
ranks = result.taxonomy.apply(tax_to_rank)
result.insert(loc=0, column='rank', value=ranks)
# Sort the table by the taxonomy string #
Expand Down
4 changes: 2 additions & 2 deletions crest4/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def tax_string(self):
the full assigned taxonomy along with the original name of the
sequence classified.
"""
# Make a comma separated string #
tax = ','.join(reversed(self.taxonomy))
# Make a semi colon separated string #
tax = '; '.join(reversed(self.taxonomy))
# Add the name of the query to the beginning line #
return self.name + '\t' + tax + '\n'

0 comments on commit 74b7698

Please sign in to comment.