Beispiel #1
0
def runSicklePaired(pe1InputFilePath: str,
                    pe2InputFilePath: str,
                    outputFolder: str = None):
    if not os.path.isfile(pe1InputFilePath):
        raise FileNotFoundError(
            "Unable to find pe1 input file for adapter trimming at %s" %
            pe1InputFilePath)
    if not os.path.isfile(pe2InputFilePath):
        raise FileNotFoundError(
            "Unable to find pe2 input file for adapter trimming at %s" %
            pe1InputFilePath)
    outputFolder, inputFastq = fileHandling.fastqBasicPrep(
        pe1InputFilePath, outputFolder)
    pe1OutputFileName = fileHandling.stripFastqExtensions(
        os.path.split(pe1InputFilePath)[1]) + ".qualTrim.fastq.gz"
    pe2OutputFileName = fileHandling.stripFastqExtensions(
        os.path.split(pe2InputFilePath)[1]) + ".qualTrim.fastq.gz"
    singletonFileName = fileHandling.stripFastqExtensions(
        os.path.split(pe1InputFilePath)[1]) + ".singleton.qualTrim.fastq.gz"
    pe1OutputFilePath = os.path.join(outputFolder, pe1OutputFileName)
    pe2OutputFilePath = os.path.join(outputFolder, pe2OutputFileName)
    singletonOutputFilePath = os.path.join(outputFolder, singletonFileName)
    sickleCommand = "%s pe -f %s -r %s -o %s -p %s -s %s -t %s -l %s -q %s -g" % (
        sickleExecutable, pe1InputFilePath, pe2InputFilePath,
        pe1OutputFilePath, pe2OutputFilePath, singletonOutputFilePath,
        qualityEncoding, lengthThreshold, qualityThreshold)
    print("RUN: %s" % sickleCommand)
    exitStatus = os.system(sickleCommand)
    if exitStatus != 0:
        raise RuntimeError(
            "Sickle command failed with non-zero exit status of %s" %
            exitStatus)
    return pe1OutputFilePath, pe2OutputFilePath, singletonOutputFilePath
def runScythe(inputFilePath: str,
              outputFolder: str = None,
              adaptersFilePath: str = None):
    if not os.path.isfile(inputFilePath):
        raise FileNotFoundError(
            "Unable to find input file for adapter trimming at %s" %
            inputFilePath)
    if not adaptersFilePath:
        return False
    if not os.path.isfile(adaptersFilePath):
        raise FileNotFoundError("Unable to find adapters file at %s" %
                                adaptersFilePath)
    outputFolder, inputFastq = fileHandling.fastqBasicPrep(
        inputFilePath, outputFolder)
    outputFileName = fileHandling.stripFastqExtensions(
        inputFastq) + ".adapterTrim.fastq"
    outputFilePath = os.path.join(outputFolder, outputFileName)
    scytheCommand = "%s -a %s -o %s %s" % (scytheExecutable, adaptersFilePath,
                                           outputFilePath, inputFilePath)
    print("RUN: %s" % scytheCommand)
    exitStatus = os.system(scytheCommand)
    if exitStatus != 0:
        raise RuntimeError(
            "Scythe command failed with non-zero exit status of %s" %
            exitStatus)
    return outputFilePath
def runCutadapt(inputFilePath:str, outputFolder:str=None, adaptersFilePath:str=None):
    if not os.path.isfile(inputFilePath):
        raise FileNotFoundError("Unable to find input file for adapter trimming at %s" % inputFilePath)
    if not adaptersFilePath:
        return False
    if not os.path.isfile(adaptersFilePath):
        raise FileNotFoundError("Unable to find adapters file at %s" %adaptersFilePath)
    outputFolder, inputFastq = fileHandling.fastqBasicPrep(inputFilePath, outputFolder)
    outputFileName = fileHandling.stripFastqExtensions(inputFastq) + ".adapterTrim.fastq.gz"
    outputFilePath = os.path.join(outputFolder, outputFileName)
    cutadaptCommand = "conda activate %s; cutadapt -j %s -a FILE:%s -o %s %s; cutadapt conda deactivate" %(cutadaptEnvironmentName, cpuCount, adaptersFilePath, outputFilePath, inputFilePath)
    print("RUN: %s" %cutadaptCommand)
    exitStatus = os.system(cutadaptCommand)
    if exitStatus != 0:
        raise RuntimeError("Scythe command failed with non-zero exit status of %s" %exitStatus)
    return outputFilePath
def bwaAlignAndCompress(
    pe1Reads: str,
    pe2Reads: str = "",
    outputFilePath: str = None,
    referenceGenome: str = referenceGenomeEnv
):  #keep pe2 file defaulting to empty string for proper BWA command
    if not outputFilePath:
        outputFilePath = fileHandling.stripFastqExtensions(pe1Reads) + ".bam"
    bwaCommand = "%s mem -t %s %s %s %s" % (
        bwaExecutable, cpuCount, referenceGenome, pe1Reads, pe2Reads)
    samtoolsBAMCommand = "%s view -@%s -bS - > %s" % (samtoolsExecutable,
                                                      cpuCount, outputFilePath)
    fullCommand = "%s | %s" % (bwaCommand, samtoolsBAMCommand)
    print("RUN: %s" % fullCommand)
    exitStatus = os.system(fullCommand)
    if exitStatus != 0:
        raise RuntimeError(
            "Alignment and compression command returned a non-zero exit status."
        )
    return outputFilePath