Skip to content

Commit

Permalink
Perform referenceless contig stitching in sample.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Donaim committed Jan 2, 2025
1 parent 1db40d9 commit 72fcbfc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion micall/drivers/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from micall.utils.driver_utils import makedirs
from micall.utils.fasta_to_csv import fasta_to_csv
from micall.utils.referencefull_contig_stitcher import referencefull_contig_stitcher
from micall.utils.referenceless_contig_stitcher import referenceless_contig_stitcher
from contextlib import contextmanager

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -426,10 +427,14 @@ def run_denovo(self, excluded_seeds):
merged_contigs_csv,
)

with open(self.unstitched_contigs_fasta, 'r') as unstitched_contigs_fasta, \
open(self.stitched_contigs_fasta, 'w') as stitched_contigs_fasta:
referenceless_contig_stitcher(unstitched_contigs_fasta, stitched_contigs_fasta)

with open(self.unstitched_contigs_csv, 'w') as unstitched_contigs_csv, \
open(self.merged_contigs_csv, 'r') as merged_contigs_csv, \
open(self.blast_csv, 'w') as blast_csv:
fasta_to_csv(Path(self.unstitched_contigs_fasta),
fasta_to_csv(Path(self.stitched_contigs_fasta),
unstitched_contigs_csv,
merged_contigs_csv,
blast_csv=blast_csv,
Expand Down
10 changes: 6 additions & 4 deletions micall/utils/referenceless_contig_stitcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from fractions import Fraction
from Bio import SeqIO, Seq
from Bio.SeqRecord import SeqRecord
from micall.utils.contig_stitcher_context import StitcherContext

from micall.utils.contig_stitcher_contigs import Contig
from micall.utils.find_maximum_overlap import find_maximum_overlap
Expand Down Expand Up @@ -144,10 +145,11 @@ def stitch_consensus(contigs: Iterable[Contig]) -> Iterable[Contig]:


def write_contigs(output_fasta: TextIO, contigs: Iterable[Contig]):
records = (SeqRecord(Seq.Seq(contig.seq),
name=contig.unique_name)
for contig in contigs)
SeqIO.write(records, output_fasta, "fasta")
with StitcherContext.fresh():
records = (SeqRecord(Seq.Seq(contig.seq),
name=contig.unique_name)
for contig in contigs)
SeqIO.write(records, output_fasta, "fasta")


def read_contigs(input_fasta: TextIO) -> Iterable[Contig]:
Expand Down

0 comments on commit 72fcbfc

Please sign in to comment.