def blast_db(self):
     """
     Create the BLAST database of the genomes
     """
     logging.info('Creating BLAST databases from sequence files')
     for query_file in self.query_files:
         # Remove the file extension from the file name
         output = os.path.splitext(query_file)[0]
         cmd = 'makeblastdb -in {fasta} -parse_seqids -max_file_sz 2GB -dbtype nucl -out {output}' \
             .format(fasta=query_file,
                     output=output)
         # Check if database already exists
         if not os.path.isfile('{output}.nhr'.format(output=output)):
             run_subprocess(cmd)
 def primer_trim(self):
     """
     Use cutadapt to trim the raw FASTQ sequence with the 5` and 3` primer files
     """
     # Run cutadapt with the following arguments: -g: 5` adapters, -a: 3` adapters, -n: remove up to two adapters
     # from the read,
     for sample in self.samples:
         # Create the necessary attributes
         sample.trimmed_fastq = os.path.join(
             self.sequencepath, '{sn}_trimmed.fastq'.format(sn=sample.name))
         sample.cutadapt_report = os.path.join(
             self.sequencepath,
             '{sn}_cutadapt_report.txt'.format(sn=sample.name))
         sample.cutadapt_out = str()
         sample.cutadapt_err = str()
         sample.cutadapt_cmd = 'cutadapt -g file:{forward_primers} -a file:{reverse_primers} -n 2 ' \
                               '{fastq_file} -o {trimmed_fastq} 1> {report}'\
             .format(forward_primers=self.forward_primers,
                     reverse_primers=self.reverse_primers,
                     fastq_file=sample.fastq,
                     trimmed_fastq=sample.trimmed_fastq,
                     report=sample.cutadapt_report)
         # Run the system call if the trimmed output file doesn't exist
         if not os.path.isfile(sample.trimmed_fastq):
             # Store the stdout and stderr to attributes
             sample.cutadapt_out, sample.cutadapt_err = run_subprocess(
                 command=sample.cutadapt_cmd)
Ejemplo n.º 3
0
 def sketch(self):
     while True:
         sample = self.sketchqueue.get()
         if not os.path.isfile(sample.paratyper.sketchfile):
             # Run the command
             out, err = run_subprocess(sample.commands.sketch)
             write_to_logfile(out='{cmd}\n{out}'.format(
                 cmd=sample.commands.sketch, out=out),
                              err=err,
                              logfile=self.logfile,
                              samplelog=sample.general.logout,
                              sampleerr=sample.general.logerr,
                              analysislog=None,
                              analysiserr=None)
         self.sketchqueue.task_done()
Ejemplo n.º 4
0
    def normalise_reads(self):
        """

        """
        for sample in self.metadata:
            sample.general.normalised_reads = os.path.join(
                sample.general.outputdirectory,
                '{sn}_normalised.fastq.gz'.format(sn=sample.name))
            sample.commands.normalise = 'bbnorm.sh in1={forward} in2={reverse} maxdepth=50 mindepth=10 ecc=t out={out}'\
                .format(forward=sample.general.fastqfiles[0],
                        reverse=sample.general.fastqfiles[1],
                        out=sample.general.normalised_reads)
            if not os.path.isfile(sample.general.normalised_reads):
                out, err = run_subprocess(sample.commands.normalise)
                write_to_logfile(out='{cmd}\n{out}'.format(
                    cmd=sample.commands.normalise, out=out),
                                 err=err,
                                 logfile=self.logfile,
                                 samplelog=sample.general.logout,
                                 sampleerr=sample.general.logerr,
                                 analysislog=None,
                                 analysiserr=None)