|
38 | 38 | from plassembler.utils.plass_class import Assembly, Plass |
39 | 39 | from plassembler.utils.qc import chopper, copy_sr_fastq_file, fastp, gzip_file |
40 | 40 | from plassembler.utils.run_canu import ( # make_blastdb,; process_blast_output,; run_blast, |
| 41 | + canu_read_type_and_error_rate, |
41 | 42 | filter_entropy, |
42 | 43 | filter_entropy_fastqs, |
43 | 44 | run_canu, |
@@ -1575,19 +1576,11 @@ def long( |
1575 | 1576 | plasmidfastqs: Path = Path(outdir) / "plasmid_long.fastq" |
1576 | 1577 | extract_long_fastqs_fast(samfile, plasmidfastqs, threads) |
1577 | 1578 |
|
1578 | | - # to set error rate |
1579 | | - canu_nano_or_pacbio = "nanopore" |
1580 | | - |
1581 | | - if pacbio_model != "nothing": |
1582 | | - if pacbio_model == "pacbio-hifi": |
1583 | | - canu_nano_or_pacbio = "pacbio-hifi" |
1584 | | - corrected_error_rate = 0.005 |
1585 | | - else: |
1586 | | - canu_nano_or_pacbio = "pacbio" |
1587 | | - corrected_error_rate = 0.045 |
1588 | | - else: |
1589 | | - canu_nano_or_pacbio = "nanopore" |
1590 | | - # corrected error rate default will be 0.12 |
| 1579 | + # map the validated --pacbio_model to canu's read-type flag, error rate, |
| 1580 | + # and whether read correction should be skipped (HiFi reads) |
| 1581 | + canu_nano_or_pacbio, corrected_error_rate, skip_canu_correct = ( |
| 1582 | + canu_read_type_and_error_rate(pacbio_model, corrected_error_rate) |
| 1583 | + ) |
1591 | 1584 |
|
1592 | 1585 | if canu_flag is True: |
1593 | 1586 | assembler = "canu" |
@@ -1641,28 +1634,38 @@ def long( |
1641 | 1634 | ) |
1642 | 1635 | filter_entropy_fastqs(plasmidfastqs, entropy_filtered_fastq) |
1643 | 1636 |
|
1644 | | - logger.info("Correcting reads with canu prior to running Unicycler.") |
1645 | | - |
1646 | | - try: |
1647 | | - run_canu_correct( |
1648 | | - threads, |
1649 | | - logdir, |
1650 | | - entropy_filtered_fastq, |
1651 | | - canu_output_dir, |
1652 | | - canu_nano_or_pacbio, |
1653 | | - total_flye_plasmid_length, |
1654 | | - corrected_error_rate, |
1655 | | - coverage, |
1656 | | - ) |
1657 | | - # convert the corrected .fasta.gz from Canu to fastq |
1658 | | - canu_reads: Path = ( |
1659 | | - Path(canu_output_dir) / "canu.correctedReads.fasta.gz" |
| 1637 | + if skip_canu_correct: |
| 1638 | + # PacBio HiFi reads are already high-accuracy; canu -correct |
| 1639 | + # rejects them ("Cannot correct already corrected reads"), so |
| 1640 | + # skip correction and assemble the entropy-filtered reads (#84). |
| 1641 | + logger.info( |
| 1642 | + "PacBio HiFi reads detected - skipping canu read correction." |
1660 | 1643 | ) |
1661 | | - corrected_fastqs: Path = Path(outdir) / "corrected_plasmid_long.fastq" |
1662 | | - corrected_fasta_to_fastq(canu_reads, corrected_fastqs) |
1663 | | - except Exception: |
1664 | | - logger.warning("Advancing with uncorrected reads") |
1665 | 1644 | corrected_fastqs = entropy_filtered_fastq |
| 1645 | + else: |
| 1646 | + logger.info("Correcting reads with canu prior to running Unicycler.") |
| 1647 | + try: |
| 1648 | + run_canu_correct( |
| 1649 | + threads, |
| 1650 | + logdir, |
| 1651 | + entropy_filtered_fastq, |
| 1652 | + canu_output_dir, |
| 1653 | + canu_nano_or_pacbio, |
| 1654 | + total_flye_plasmid_length, |
| 1655 | + corrected_error_rate, |
| 1656 | + coverage, |
| 1657 | + ) |
| 1658 | + # convert the corrected .fasta.gz from Canu to fastq |
| 1659 | + canu_reads: Path = ( |
| 1660 | + Path(canu_output_dir) / "canu.correctedReads.fasta.gz" |
| 1661 | + ) |
| 1662 | + corrected_fastqs: Path = ( |
| 1663 | + Path(outdir) / "corrected_plasmid_long.fastq" |
| 1664 | + ) |
| 1665 | + corrected_fasta_to_fastq(canu_reads, corrected_fastqs) |
| 1666 | + except Exception: |
| 1667 | + logger.warning("Advancing with uncorrected reads") |
| 1668 | + corrected_fastqs = entropy_filtered_fastq |
1666 | 1669 |
|
1667 | 1670 | # remove canu directory |
1668 | 1671 | remove_directory(canu_output_dir) |
|
0 commit comments