Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
gbouras13 committed Sep 9, 2023
1 parent 8721db9 commit cb81260
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 247 deletions.
88 changes: 52 additions & 36 deletions src/plassembler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import Path

import click
from Bio import SeqIO
from loguru import logger

from plassembler.utils.assembly import run_flye, run_raven
Expand All @@ -31,6 +32,7 @@
run_blast,
run_canu,
)
from plassembler.utils.run_dnaapler import run_dnaapler
from plassembler.utils.run_mash import mash_sketch, run_mash
from plassembler.utils.run_unicycler import run_unicycler
from plassembler.utils.sam_to_fastq import (
Expand Down Expand Up @@ -1172,54 +1174,68 @@ def long(
canu_nano_or_pacbio = "nanopore"
canu_output_dir: Path = Path(outdir) / "canu"
run_canu(threads, logdir, plasmidfastqs, canu_output_dir, canu_nano_or_pacbio)
make_blastdb(canu_output_dir, logdir)
run_blast(canu_output_dir, threads, logdir)
process_blast_output(canu_output_dir, outdir)

# dnaapler
# check canu outdir has a plasmid
canu_fasta: Path = Path(canu_output_dir) / "canu.contigs.fasta"
contig_count = 0
for record in SeqIO.parse(canu_fasta, "fasta"):
contig_count += 1

logger.info(f"Canu assembled {contig_count} contigs.")

if contig_count == 0: # end
logger.info("Your sample probably has no plasmids.")


else: # at least 1 canu contig
# run and parse blast
make_blastdb(canu_output_dir, logdir)
run_blast(canu_output_dir, threads, logdir)
process_blast_output(canu_output_dir, outdir)

# dnaapler
run_dnaapler(threads, logdir, outdir)
plasmids_for_sketching: Path = (
Path(outdir) / "dnaapler" / "dnaapler_all_reoriented.fasta"
)

# depth
plass.get_depth_long(logdir, pacbio_model, threads)
# depth
plass.get_depth_long(logdir, pacbio_model, threads, plasmids_for_sketching)

# run mash
logger.info("Calculating mash distances to PLSDB.")
# mash sketches the plasmids
mash_sketch(outdir, os.path.join(outdir, "plasmids_canu.fasta"), logdir)
# runs mash
run_mash(outdir, database, logdir)
# run mash
logger.info("Calculating mash distances to PLSDB.")
# mash sketches the plasmids
mash_sketch(outdir, plasmids_for_sketching, logdir)
# runs mash
run_mash(outdir, database, logdir)

# processes output
plass.process_mash_tsv(database)
# processes output
plass.process_mash_tsv(database)

# combine depth and mash tsvs
plass.combine_depth_mash_tsvs(prefix)
# combine depth and mash tsvs
plass.combine_depth_mash_tsvs(prefix)

# rename contigs and update copy number with plsdb
plass.finalise_contigs_long(prefix)
# rename contigs and update copy number with plsdb
plass.finalise_contigs_long(prefix)

# cleanup files
move_and_copy_files(
outdir,
prefix,
False, # unicycler success
False, # keep fastqs
False, # assembled mode
True, # long only
use_raven,
)
# wrap up
# cleanup files
move_and_copy_files(
outdir,
prefix,
False, # unicycler success
False, # keep fastqs
False, # assembled mode
True, # long only
use_raven,
)

remove_intermediate_files(
outdir,
keep_chromosome,
False, # assembled mode
True, # long only
use_raven,
)
remove_intermediate_files(
outdir,
keep_chromosome,
False, # assembled mode
True, # long only
use_raven,
)

# end plassembler
end_plassembler(start_time)
Expand Down
2 changes: 1 addition & 1 deletion src/plassembler/utils/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.1
1.2.0
7 changes: 7 additions & 0 deletions src/plassembler/utils/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ def remove_intermediate_files(
if keep_chromosome is False:
remove_file(os.path.join(out_dir, "chromosome.fasta"))

# canu
# remove_directory(os.path.join(out_dir, "canu"))
remove_file(os.path.join(out_dir, "long_combined.fasta"))

# dnaapler
remove_directory(os.path.join(out_dir, "dnaapler"))


def move_and_copy_files(
out_dir,
Expand Down
11 changes: 11 additions & 0 deletions src/plassembler/utils/input_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,17 @@ def check_dependencies():
except Exception:
logger.error("canu not found")

# dnaapler
try:
process = sp.Popen(["dnaapler", "--version"], stdout=sp.PIPE, stderr=sp.PIPE)
dnaapler_out, _ = process.communicate()
dnaapler_out = dnaapler_out.decode()
dnaapler_out = dnaapler_out.split("\n")[0].split("version ")[1]
message = f"dnaapler v{dnaapler_out} found."
logger.info(message)
except Exception:
logger.error("dnaapler not found")

# blast

try:
Expand Down
4 changes: 2 additions & 2 deletions src/plassembler/utils/plass_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,17 +413,17 @@ def get_depth(self, logdir, pacbio_model, threads):
summary_depth_df_short, summary_depth_df_long, circular_status
)

def get_depth_long(self, logdir, pacbio_model, threads):
def get_depth_long(self, logdir, pacbio_model, threads, plas_fasta):
"""wrapper function to get depth of each plasmid
:param pacbio_model: pacbio_model
:param threads: threads
:param logdir: logdir
:plas_fasta: plasmids from dnaapler
:return:
"""
outdir = self.outdir

input_long_reads: Path = Path(outdir) / "chopper_long_reads.fastq.gz"
plas_fasta: Path = Path(outdir) / "plasmids_canu.fasta"
chromosome: Path = Path(outdir) / "chromosome.fasta"
combined_fasta: Path = Path(outdir) / "long_combined.fasta"
sam_file: Path = Path(outdir) / "combined_long.sam"
Expand Down
Loading

0 comments on commit cb81260

Please sign in to comment.