Skip to content

Commit

Permalink
Merge pull request #14 from B-UMMI/minor_fix
Browse files Browse the repository at this point in the history
Control if assembly is produced when SPAdes doesn't crash
  • Loading branch information
cimendes authored Feb 16, 2018
2 parents 74a0817 + 97c9b50 commit 0add1c0
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions modules/spades.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@


# Run Spades
def spades(spades_folder, threads, fastq_files, notUseCareful, maxMemory, minCoverageAssembly, kmers, assembled_se_reads):
def spades(spades_folder, threads, fastq_files, notUseCareful, maxMemory, minCoverageAssembly, kmers,
assembled_se_reads):
contigs = os.path.join(spades_folder, 'contigs.fasta')

command = ['spades.py', '', '--only-assembler', '--threads', str(threads), '--memory', str(maxMemory), '--cov-cutoff', str(minCoverageAssembly), '', '-1', fastq_files[0], '-2', fastq_files[1], '', '-o', spades_folder]
command = ['spades.py', '', '--only-assembler', '--threads', str(threads), '--memory', str(maxMemory),
'--cov-cutoff', str(minCoverageAssembly), '', '-1', fastq_files[0], '-2', fastq_files[1], '',
'-o', spades_folder]

if not notUseCareful:
command[1] = '--careful'
Expand Down Expand Up @@ -231,8 +234,7 @@ def decide_filter_parameters(sequence_dict, minContigsLength, minCoverageContigs
@spades_timer
def runSpades(sampleName, outdir, threads, fastq_files, notUseCareful, maxMemory, minCoverageAssembly, minContigsLength, estimatedGenomeSizeMb, kmers, maximumReadsLength, defaultKmers, minCoverageContigs, assembled_se_reads, saveExcludedContigs, maxNumberContigs):
pass_qc = True
failing = {}
failing['sample'] = False
failing = {'sample': False}
warnings = {}

# Create SPAdes output directory
Expand All @@ -250,40 +252,46 @@ def runSpades(sampleName, outdir, threads, fastq_files, notUseCareful, maxMemory
else:
print 'SPAdes will use the following k-mers: ' + str(kmers)

run_successfully, contigs = spades(spades_folder, threads, fastq_files, notUseCareful, maxMemory, minCoverageAssembly, kmers, assembled_se_reads)
run_successfully, contigs = spades(spades_folder, threads, fastq_files, notUseCareful, maxMemory,
minCoverageAssembly, kmers, assembled_se_reads)

if run_successfully:
shutil.copyfile(contigs, os.path.join(outdir, str('SPAdes_original_assembly.contigs.fasta')))
if os.path.isfile(contigs):
shutil.copyfile(contigs, os.path.join(outdir, str('SPAdes_original_assembly.contigs.fasta')))

contigs_link = os.path.join(outdir, str(sampleName + '.contigs.fasta'))
os.symlink(contigs, contigs_link)
contigs_link = os.path.join(outdir, str(sampleName + '.contigs.fasta'))
os.symlink(contigs, contigs_link)

contigs = contigs_link
contigs = contigs_link

minContigsLength = define_minContigsLength(maximumReadsLength, minContigsLength)
minContigsLength = define_minContigsLength(maximumReadsLength, minContigsLength)

sequence_dict = get_SPAdes_sequence_information(contigs)
sequence_dict = get_SPAdes_sequence_information(contigs)

warnings, sequence_dict, filtered_sequences_sufix, spades_report_general = decide_filter_parameters(sequence_dict, minContigsLength, minCoverageContigs, estimatedGenomeSizeMb, maxNumberContigs)
warnings, sequence_dict, filtered_sequences_sufix, spades_report_general = \
decide_filter_parameters(sequence_dict, minContigsLength, minCoverageContigs, estimatedGenomeSizeMb,
maxNumberContigs)

if filtered_sequences_sufix is not None:
filtered_sequence_file = os.path.splitext(contigs)[0] + '.' + filtered_sequences_sufix + '.fasta'
write_filtered_sequences_and_stats(sequence_dict, spades_report_general, contigs, filtered_sequence_file, sampleName, False, saveExcludedContigs)
contigs = filtered_sequence_file
else:
filtered_sequence_file = os.path.splitext(contigs)[0] + '.original.fasta'
write_filtered_sequences_and_stats(sequence_dict, spades_report_general, contigs, filtered_sequence_file, sampleName, True, False)
contigs = filtered_sequence_file

os.remove(contigs_link)
if filtered_sequences_sufix is not None:
filtered_sequence_file = os.path.splitext(contigs)[0] + '.' + filtered_sequences_sufix + '.fasta'
write_filtered_sequences_and_stats(sequence_dict, spades_report_general, contigs,
filtered_sequence_file, sampleName, False, saveExcludedContigs)
contigs = filtered_sequence_file
else:
filtered_sequence_file = os.path.splitext(contigs)[0] + '.original.fasta'
write_filtered_sequences_and_stats(sequence_dict, spades_report_general, contigs,
filtered_sequence_file, sampleName, True, False)
contigs = filtered_sequence_file

os.remove(contigs_link)
else:
run_successfully = False
failing['sample'] = 'Assembly was not produced'
else:
failing['sample'] = 'Did not run'
print failing['sample']
contigs = None
pass_qc = False

if not run_successfully:
print failing['sample']
pass_qc = False

utils.removeDirectory(spades_folder)
Expand Down

0 comments on commit 0add1c0

Please sign in to comment.