Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inver the order of the taxonomic lineages on the output files #129

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions bin/contig_taxonomic_assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def main(args):
for name, *_, avg_cds, std_cds, _, mult_factor in csv_reader
}

file_header = ["contig_ID", "genus", "subfamily", "family", "order", "class"]
file_header = ["contig_ID", "superkingdom", "kingdom", "phylum", "subphylum", "class", "order", "suborder", "family", "subfamily", "genus"]

output_gen = contig_tax(input_df, args.ncbi_db, args.tax_thres, factor_dict)
output_gen = contig_tax(input_df, args.ncbi_db, args.tax_thres, factor_dict, file_header)

print(args.input_file)

Expand All @@ -46,12 +46,12 @@ def main(args):
tsv_writer.writerow(item)


def contig_tax(annot_df, ncbi_db, tax_thres, taxon_factor_dict):
def contig_tax(annot_df, ncbi_db, tax_thres, taxon_factor_dict, output_taxa_order):
"""This function takes the annotation table generated by viral_contig_maps.py and generates a table that
provides the taxonomic lineage of each viral contig, based on the corresponding ViPhOG annotations"""

ncbi = NCBITaxa(dbfile=ncbi_db)
tax_rank_order = ["genus", "subfamily", "family", "order", "class"]
viphog_rank = ["genus", "subfamily", "family", "order"]
contig_set = set(annot_df["Contig"])

for contig in contig_set:
Expand All @@ -60,7 +60,7 @@ def contig_tax(annot_df, ncbi_db, tax_thres, taxon_factor_dict):
total_prot = len(contig_df)
annot_prot = sum(contig_df["Best_hit"] != "No hit")
if annot_prot == 0:
contig_lineage.extend([""] * 4)
contig_lineage.extend([""] * len(output_taxa_order[1:]))
else:
contig_hits = contig_df[pd.notnull(contig_df["Label"])]["Label"].values
taxid_list = [
Expand All @@ -70,11 +70,11 @@ def contig_tax(annot_df, ncbi_db, tax_thres, taxon_factor_dict):
{
y: ncbi.get_taxid_translator([x])[x]
for x, y in ncbi.get_rank(ncbi.get_lineage(item)).items()
if y in tax_rank_order[:-1]
if y in viphog_rank
}
for item in taxid_list
]
for rank in tax_rank_order[:-1]:
for rank in output_taxa_order[::-1][:-1]:
taxon_list = [item.get(rank) for item in hit_lineages]
total_hits = sum(pd.notnull(taxon_list))
if total_hits == 0:
Expand Down Expand Up @@ -123,12 +123,11 @@ def contig_tax(annot_df, ncbi_db, tax_thres, taxon_factor_dict):
taxon_lineage_dict = {
y: ncbi.get_taxid_translator([x])[x]
for x, y in ncbi.get_rank(taxon_lineage).items()
if y in tax_rank_order[tax_rank_order.index(rank) :]
}
taxon_lineage_list = [
taxon_lineage_dict.get(item, "")
for item in tax_rank_order[
tax_rank_order.index(rank) :
for item in output_taxa_order[
1:output_taxa_order.index(rank)+1
]
]
break
Expand Down
Loading