Source code for pacbio_data_processing.ccs

#######################################################################
#
# Copyright (C) 2021, 2022 David Palao
#
# This file is part of PacBioDataProcessing.
#
#  PacBioDataProcessing is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  PacBio data processing is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with PacBioDataProcessing. If not, see <http://www.gnu.org/licenses/>.
#
#######################################################################

from pathlib import Path
import subprocess
import logging
from typing import Optional

from .types import PathOrStr


[docs]def ccs(infilename: PathOrStr, outfilename: PathOrStr) -> Optional[Path]: """It calls the ``ccs`` program. On success, a ``Path`` instance to ``outfilename`` is returned. On failure, ``None`` is returned. """ # logging.debug( # "[CCS] Starting computation of Circular Consensus Sequence") infilename = Path(infilename) outfilename = Path(outfilename) ccs_proc = subprocess.run( ("ccs", infilename, outfilename), capture_output=True) if outfilename.exists(): logging.info(f"[ccs] File '{outfilename}' generated") if ccs_proc.returncode != 0: logging.error( f"[ccs] Although the file '{outfilename}' has been generated, " "there was an error." ) logging.error( "[ccs] It is advisable to check the generated ccs file, to see " "if it is correct." ) logging.error("[ccs] The following command was used to produce it:") logging.error(f"[ccs] 'ccs {infilename} {outfilename}'") else: logging.error(f"[ccs] Could not generate '{outfilename}'") outfilename = None if ccs_proc.returncode == 0: logging.error(f"[ccs] ...but the ccs program did not report any error.") if ccs_proc.returncode != 0: msg = ccs_proc.stderr.decode().strip() logging.error(f"[ccs] ...the error was: '{msg}'") return outfilename