Skip to content

Commit

Permalink
Substituted SPAdes for IVA
Browse files Browse the repository at this point in the history
  • Loading branch information
CBeelen committed Apr 26, 2021
1 parent 5074cbb commit 18d01e0
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions micall/core/denovo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from micall.core.project_config import ProjectConfig

IVA = "iva"
SPAdes = "Spades/bin/spades.py"
DEFAULT_DATABASE = os.path.join(os.path.dirname(__file__),
'..',
'blast_db',
Expand Down Expand Up @@ -201,34 +201,33 @@ def denovo(fastq1_path: str,
'--interleave',
'-o', joined_path],
check=True)
iva_out_path = os.path.join(tmp_dir, 'iva_out')
contigs_fasta_path = os.path.join(iva_out_path, 'contigs.fasta')
# iva_args = [IVA, '--fr', joined_path, '-t', '2']
with open(os.path.join(tmp_dir, 'iva.log'), 'w') as log_file:
iva_args = [IVA, '-vv', '--fr', joined_path, '-t', '2']
if merged_contigs_csv is not None:
seeds_fasta_path = os.path.join(tmp_dir, 'seeds.fasta')
with open(seeds_fasta_path, 'w') as seeds_fasta:
SeqIO.write((SeqRecord(Seq(row['contig']), f'seed-{i}', '', '')
for i, row in enumerate(DictReader(merged_contigs_csv))),
seeds_fasta,
'fasta')
seeds_size = seeds_fasta.tell()
if seeds_size > 0:
iva_args.extend(['--contigs', seeds_fasta_path, '--make_new_seeds'])
iva_args.append(iva_out_path)
try:
run(iva_args,
check=True,
stdout=log_file,
stderr=STDOUT)
except CalledProcessError as ex:
output = ex.output and ex.output.decode('UTF8')
if output != 'Failed to make first seed. Cannot continue\n':
logger.warning('iva failed to assemble.', exc_info=True)
logger.warning(output)
with open(contigs_fasta_path, 'a'):
pass
spades_out_path = os.path.join(tmp_dir, 'spades_out')
contigs_fasta_path = os.path.join(spades_out_path, 'contigs.fasta')
spades_args = [SPAdes, '--12', joined_path, '--phred-offset', '33']
# Setting Phred offset manually is only required for microtests
if merged_contigs_csv is not None:
seeds_fasta_path = os.path.join(tmp_dir, 'seeds.fasta')
with open(seeds_fasta_path, 'w') as seeds_fasta:
SeqIO.write((SeqRecord(Seq(row['contig']), f'seed-{i}', '', '')
for i, row in enumerate(DictReader(merged_contigs_csv))),
seeds_fasta,
'fasta')
seeds_size = seeds_fasta.tell()
if seeds_size > 0:
spades_args.extend(['--trusted-contigs', seeds_fasta_path])
spades_args.extend(['-o', spades_out_path])
try:
run(spades_args,
check=True,
stdout=PIPE,
stderr=STDOUT)
except CalledProcessError as ex:
output = ex.output and ex.output.decode('UTF8')
if output != 'Failed to make first seed. Cannot continue\n':
logger.warning('SPAdes failed to assemble.', exc_info=True)
logger.warning(output)
with open(contigs_fasta_path, 'a'):
pass

os.chdir(start_dir)
duration = datetime.now() - start_time
Expand Down

1 comment on commit 18d01e0

@CBeelen
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For #665
SPAdes performs well in benchmark tests and is widely used, which is why we are giving it a try in the MiCall pipeline.

Please sign in to comment.