Skip to content

Commit

Permalink
refact: Add alternative strategy for merging mobsuite results (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvfe committed Jul 22, 2024
1 parent c9eeaca commit a54d8a1
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions bin/create_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ def create_report(ann, diamond_outs, rgi, vfdb_fasta, phispy, mobsuite):
mobrecon_sum, on=["genome_id", "contig_id"], how="inner"
)

non_contig_merge = False
if w_mobrecon.empty:
non_contig_merge = True
w_mobrecon = ann_sum.merge(
mobrecon_sum.drop(['contig_id'], axis=1), on=["genome_id"], how="inner"
)

full_contigs = w_mobrecon

if phispy is not None:
Expand All @@ -202,15 +209,27 @@ def create_report(ann, diamond_outs, rgi, vfdb_fasta, phispy, mobsuite):
phispy_sum, on=["genome_id", "contig_id"], how="inner"
)

full_contigs = w_phispy.merge(
full_contigs,
on=["genome_id", "orf", "contig_id", "Start", "Stop"],
how="outer",
if non_contig_merge:
full_contigs = w_phispy.merge(
full_contigs.drop(['contig_id'], axis=1),
on=["genome_id", "orf", "Start", "Stop"],
how="outer",
)
else:
full_contigs = w_phispy.merge(
full_contigs,
on=["genome_id", "orf", "contig_id", "Start", "Stop"],
how="outer",
)

if non_contig_merge:
merged_full = full_contigs.merge(
w_vfdb.drop(['contig_id'], axis=1), on=["genome_id", "orf", "Start", "Stop"], how="outer"
)
else:
merged_full = full_contigs.merge(
w_vfdb, on=["genome_id", "orf", "contig_id", "Start", "Stop"], how="outer"
)

merged_full = full_contigs.merge(
w_vfdb, on=["genome_id", "orf", "contig_id", "Start", "Stop"], how="outer"
)

merged_full.to_csv(
path_or_buf="annotation_report.tsv.gz", sep="\t", index=False
Expand Down

0 comments on commit a54d8a1

Please sign in to comment.