text
stringlengths 0
828
|
---|
make_path(sample.general.assembly_output) |
sample.general.assemblyfile = os.path.join(sample.general.assembly_output, |
'{name}_unfiltered.fasta' |
.format(name=sample.name)) |
sample.general.bestassemblyfile = os.path.join(sample.general.assembly_output, |
'{name}.fasta' |
.format(name=sample.name)) |
fastqfiles = sample.general.trimmedcorrectedfastqfiles |
# Set the the forward fastq files |
sample.general.assemblyfastq = fastqfiles |
forward = fastqfiles[0] |
gz = True if '.gz' in forward else False |
# If there are two fastq files |
if len(fastqfiles) == 2: |
# Set the reverse fastq name https://github.com/ncbi/SKESA/issues/7 |
sample.commands.assemble = 'skesa --fastq {fastqfiles} --cores {threads} ' \ |
'--use_paired_ends --vector_percent 1 ' \ |
'--contigs_out {contigs}'\ |
.format(fastqfiles=','.join(fastqfiles), |
threads=self.cpus, |
contigs=sample.general.assemblyfile) |
# Same as above, but use single read settings for the assembler |
else: |
sample.commands.assemble = 'skesa --fastq {fastqfiles} --cores {threads} ' \ |
'--vector_percent 1 --contigs_out {contigs}'\ |
.format(fastqfiles=','.join(fastqfiles), |
threads=self.cpus, |
contigs=sample.general.assemblyfile) |
# If there are no fastq files, populate the metadata appropriately |
else: |
sample.general.assembly_output = 'NA' |
sample.general.assemblyfastq = 'NA' |
sample.general.bestassemblyfile = 'NA' |
except AttributeError: |
sample.general.assembly_output = 'NA' |
sample.general.assemblyfastq = 'NA' |
sample.general.trimmedcorrectedfastqfiles = 'NA' |
sample.general.bestassemblyfile = 'NA' |
if sample.commands.assemble and not os.path.isfile(sample.general.assemblyfile): |
# Run the assembly |
out, err = run_subprocess(sample.commands.assemble) |
write_to_logfile(sample.commands.assemble, |
sample.commands.assemble, |
self.logfile, |
sample.general.logout, |
sample.general.logerr, |
None, |
None) |
write_to_logfile(out, |
err, |
self.logfile, |
sample.general.logout, |
sample.general.logerr, |
None, |
None)" |
65,"def merge(self, sample): |
"""""" |
Use bbmerge to merge paired FASTQ files for use in metagenomics pipelines. Create a report with the |
total number of reads, and the number of reads that could be paired |
:param sample: metadata sample object flagged as a metagenome |
"""""" |
# Set the assembly file to 'NA' as assembly is not desirable for metagenomes |
sample.general.assemblyfile = 'NA' |
# Can only merge paired-end |
if len(sample.general.fastqfiles) == 2: |
outpath = os.path.join(sample.general.outputdirectory, 'merged_reads') |
make_path(outpath) |
# Merge path - keep all the merged FASTQ files in one directory |
merge_path = os.path.join(self.path, 'merged_reads') |
make_path(merge_path) |
# Set the name of the merged, and unmerged files |
sample.general.mergedreads = \ |
os.path.join(merge_path, '{}_paired.fastq.gz'.format(sample.name)) |
log = os.path.join(outpath, 'log') |
error = os.path.join(outpath, 'err') |
try: |
if not os.path.isfile(sample.general.mergedreads): |
# Run the merging command |
out, err, cmd = bbtools.bbmerge(forward_in=sorted(sample.general.trimmedcorrectedfastqfiles)[0], |
merged_reads=sample.general.mergedreads, |
mix=True, |
returncmd=True, |
threads=self.cpus) |
write_to_logfile(out, err, self.logfile, sample.general.logout, sample.general.logerr, None, None) |
with open(log, 'w') as log_file: |
log_file.write(out) |
with open(error, 'w') as error_file: |
error_file.write(err) |
except (CalledProcessError, IndexError): |
delattr(sample.general, 'mergedreads') |
# Set the name of the report to store the metagenome file merging results |
report = os.path.join(self.reportpath, 'merged_metagenomes.csv') |
# Extract the total number of reads, and the number of reads that could be paired from the bbmerge |
# err stream |
num_reads, num_pairs = self.reads(error) |
# If the report doesn't exist, create it with the header and the results from the first sample |
if not os.path.isfile(report): |
with open(report, 'w') as report_file: |
report_file.write('Sample,TotalReads,PairedReads\n{sample},{total},{paired}\n' |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.