Skip to content

Commit

Permalink
added metaSPAdes
Browse files Browse the repository at this point in the history
  • Loading branch information
notestaff committed May 16, 2019
1 parent c9842f2 commit 1eb128c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
5 changes: 4 additions & 1 deletion assembly.py
Expand Up @@ -354,6 +354,7 @@ def assemble_spades(
filter_contigs=False,
min_contig_len=0,
kmer_sizes=(55,65),
spades_mode='rna',
n_reads=10000000,
outReads=None,
always_succeed=False,
Expand All @@ -378,7 +379,7 @@ def assemble_spades(
tools.spades.SpadesTool().assemble(reads_fwd=reads_fwd, reads_bwd=reads_bwd, reads_unpaired=reads_unpaired,
contigs_untrusted=contigs_untrusted, contigs_trusted=contigs_trusted,
contigs_out=out_fasta, filter_contigs=filter_contigs,
min_contig_len=min_contig_len,
min_contig_len=min_contig_len, spades_mode=spades_mode,
kmer_sizes=kmer_sizes, always_succeed=always_succeed, max_kmer_sizes=max_kmer_sizes,
spades_opts=spades_opts, mem_limit_gb=mem_limit_gb,
threads=threads)
Expand All @@ -403,6 +404,8 @@ def parser_assemble_spades(parser=argparse.ArgumentParser()):
parser.add_argument('--outReads', default=None, help='Save the trimmomatic/prinseq/subsamp reads to a BAM file')
parser.add_argument('--filterContigs', dest='filter_contigs', default=False, action='store_true',
help='only output contigs SPAdes is sure of (drop lesser-quality contigs from output)')
parser.add_argument('--spadesMode', dest='spades_mode', choices=('rna', 'meta'), default='meta',
help='which SPAdes mode to use (rnaSPAdes or metaSPAdes)')
parser.add_argument('--alwaysSucceed', dest='always_succeed', default=False, action='store_true',
help='if assembly fails for any reason, output an empty contigs file, rather than failing with '
'an error code')
Expand Down
3 changes: 3 additions & 0 deletions pipes/WDL/workflows/tasks/tasks_assembly.wdl
Expand Up @@ -5,6 +5,7 @@ task assemble {
Int? trinity_n_reads=250000
Int? spades_n_reads=10000000
Int? spades_min_contig_len=0
String? spades_mode="rna"

String? assembler="trinity" # trinity, spades, or trinity-spades
Boolean? always_succeed=false
Expand Down Expand Up @@ -39,6 +40,7 @@ task assemble {
${'--nReads=' + spades_n_reads} \
${true="--alwaysSucceed" false="" always_succeed} \
${'--minContigLen=' + spades_min_contig_len} \
${'--spadesMode=' + spades_mode} \
--memLimitGb $mem_in_gb \
--outReads=${sample_name}.subsamp.bam \
--loglevel=DEBUG
Expand All @@ -61,6 +63,7 @@ task assemble {
${'--nReads=' + spades_n_reads} \
${true='--alwaysSucceed' false='' always_succeed} \
${'--minContigLen=' + spades_min_contig_len} \
${'--spadesMode=' + spades_mode} \
--memLimitGb $mem_in_gb \
--loglevel=DEBUG

Expand Down
16 changes: 12 additions & 4 deletions tools/spades.py
Expand Up @@ -43,7 +43,8 @@ def execute(self, args): # pylint: disable=W0221

def assemble(self, reads_fwd, reads_bwd, contigs_out, reads_unpaired=None, contigs_trusted=None,
contigs_untrusted=None, kmer_sizes=(55,65), always_succeed=False, max_kmer_sizes=1,
filter_contigs=False, min_contig_len=0, mem_limit_gb=8, threads=None, spades_opts=''):
filter_contigs=False, min_contig_len=0, mem_limit_gb=8, threads=None, spades_opts='',
spades_mode='rna'):
'''Assemble contigs from RNA-seq reads and (optionally) pre-existing contigs.
Inputs:
Expand All @@ -63,6 +64,7 @@ def assemble(self, reads_fwd, reads_bwd, contigs_out, reads_unpaired=None, conti
mem_limit_gb: max memory to use, in gigabytes
threads: number of threads to use
spades_opts: additional options to pass to spades
spades_mode: whether to use rnaSPAdes (spades_mode=="rna") or metaSPAdes (spades_mode=="meta")
Outputs:
contigs_out: assembled contigs in fasta format. Note that, since we use the
RNA-seq assembly mode, for some genome regions we may get several contigs
Expand All @@ -89,14 +91,20 @@ def assemble(self, reads_fwd, reads_bwd, contigs_out, reads_unpaired=None, conti
if reads_fwd and reads_bwd and os.path.getsize(reads_fwd) > 0 and os.path.getsize(reads_bwd) > 0:
args += ['-1', reads_fwd, '-2', reads_bwd ]
if reads_unpaired and os.path.getsize(reads_unpaired) > 0:
args += [ '--s1', reads_unpaired ]
if spades_mode == 'meta':
log.warning('SPAdes: ignoring unpaired reads in metaSPAdes mode')
else:
args += [ '--s1', reads_unpaired ]

if contigs_trusted: args += [ '--trusted-contigs', contigs_trusted ]
if contigs_untrusted: args += [ '--untrusted-contigs', contigs_untrusted ]
if kmer_size: args += [ '-k', kmer_size ]
if spades_opts: args += shlex.split(spades_opts)
args += [ '--rna', '-m' + str(mem_limit_gb), '-t', str(threads), '-o', spades_dir ]
args += [ '--' + spades_mode, '-m' + str(mem_limit_gb), '-t', str(threads), '-o', spades_dir ]

transcripts_fname = os.path.join(spades_dir, ('hard_filtered_' if filter_contigs else '') + 'transcripts.fasta')
transcripts_fname = os.path.join(spades_dir,
('hard_filtered_' if filter_contigs else '') + 'transcripts.fasta') \
if spades_mode == 'rna' else 'contigs.fasta'

try:
self.execute(args=args)
Expand Down

0 comments on commit 1eb128c

Please sign in to comment.