Skip to content

Commit 5074cbb

Browse files
committed
Mixture samples created in make_sample.py, and iva log output created in denovo.py
1 parent 6850f87 commit 5074cbb

File tree

3 files changed

+141
-22
lines changed

3 files changed

+141
-22
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@
3535
/test_samples.csv
3636
.vscode
3737
/docs/_site
38+
/scripts/*
39+
/micall/tests/microtest/.Rhistory
40+
/Results/*
41+
/SPAdes-3.15.2/*
42+
/Spades/*

micall/core/denovo.py

+26-21
Original file line numberDiff line numberDiff line change
@@ -203,27 +203,32 @@ def denovo(fastq1_path: str,
203203
check=True)
204204
iva_out_path = os.path.join(tmp_dir, 'iva_out')
205205
contigs_fasta_path = os.path.join(iva_out_path, 'contigs.fasta')
206-
iva_args = [IVA, '--fr', joined_path, '-t', '2']
207-
if merged_contigs_csv is not None:
208-
seeds_fasta_path = os.path.join(tmp_dir, 'seeds.fasta')
209-
with open(seeds_fasta_path, 'w') as seeds_fasta:
210-
SeqIO.write((SeqRecord(Seq(row['contig']), f'seed-{i}', '', '')
211-
for i, row in enumerate(DictReader(merged_contigs_csv))),
212-
seeds_fasta,
213-
'fasta')
214-
seeds_size = seeds_fasta.tell()
215-
if seeds_size > 0:
216-
iva_args.extend(['--contigs', seeds_fasta_path, '--make_new_seeds'])
217-
iva_args.append(iva_out_path)
218-
try:
219-
run(iva_args, check=True, stdout=PIPE, stderr=STDOUT)
220-
except CalledProcessError as ex:
221-
output = ex.output and ex.output.decode('UTF8')
222-
if output != 'Failed to make first seed. Cannot continue\n':
223-
logger.warning('iva failed to assemble.', exc_info=True)
224-
logger.warning(output)
225-
with open(contigs_fasta_path, 'a'):
226-
pass
206+
# iva_args = [IVA, '--fr', joined_path, '-t', '2']
207+
with open(os.path.join(tmp_dir, 'iva.log'), 'w') as log_file:
208+
iva_args = [IVA, '-vv', '--fr', joined_path, '-t', '2']
209+
if merged_contigs_csv is not None:
210+
seeds_fasta_path = os.path.join(tmp_dir, 'seeds.fasta')
211+
with open(seeds_fasta_path, 'w') as seeds_fasta:
212+
SeqIO.write((SeqRecord(Seq(row['contig']), f'seed-{i}', '', '')
213+
for i, row in enumerate(DictReader(merged_contigs_csv))),
214+
seeds_fasta,
215+
'fasta')
216+
seeds_size = seeds_fasta.tell()
217+
if seeds_size > 0:
218+
iva_args.extend(['--contigs', seeds_fasta_path, '--make_new_seeds'])
219+
iva_args.append(iva_out_path)
220+
try:
221+
run(iva_args,
222+
check=True,
223+
stdout=log_file,
224+
stderr=STDOUT)
225+
except CalledProcessError as ex:
226+
output = ex.output and ex.output.decode('UTF8')
227+
if output != 'Failed to make first seed. Cannot continue\n':
228+
logger.warning('iva failed to assemble.', exc_info=True)
229+
logger.warning(output)
230+
with open(contigs_fasta_path, 'a'):
231+
pass
227232

228233
os.chdir(start_dir)
229234
duration = datetime.now() - start_time

micall/tests/microtest/make_sample.py

+110-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,72 @@ def main():
5555
7757)
5656
hxb2_ref = projects.getReference('HIV1-B-FR-K03455-seed')
5757

58+
sections_2220_mix1a_1, sections_2220_mix1a_2 = make_random_sections('HIV1-B-FR-K03455-seed',
59+
6225,
60+
7757,
61+
projects,
62+
9000
63+
)
64+
sections_2220_mix1b_1, sections_2220_mix1b_2 = make_random_sections('HIV1-B-FR-K03455-seed',
65+
6225,
66+
7757,
67+
projects,
68+
1000,
69+
mutations = (CodonMutation(7000, 'AAA'),)
70+
)
71+
sections_2220_mix2a_1, sections_2220_mix2a_2 = make_random_sections('HIV1-B-FR-K03455-seed',
72+
6225,
73+
7757,
74+
projects,
75+
8000
76+
)
77+
sections_2220_mix2b_1, sections_2220_mix2b_2 = make_random_sections('HIV1-B-FR-K03455-seed',
78+
6225,
79+
7757,
80+
projects,
81+
2000,
82+
mutations = (CodonMutation(7000, 'AAA'),)
83+
)
84+
sections_2220_mix3a_1, sections_2220_mix3a_2 = make_random_sections('HIV1-B-FR-K03455-seed',
85+
6225,
86+
7757,
87+
projects,
88+
7000
89+
)
90+
sections_2220_mix3b_1, sections_2220_mix3b_2 = make_random_sections('HIV1-B-FR-K03455-seed',
91+
6225,
92+
7757,
93+
projects,
94+
3000,
95+
mutations = (CodonMutation(7000, 'AAA'),)
96+
)
97+
sections_2220_mix4a_1, sections_2220_mix4a_2 = make_random_sections('HIV1-B-FR-K03455-seed',
98+
6225,
99+
7757,
100+
projects,
101+
6000
102+
)
103+
sections_2220_mix4b_1, sections_2220_mix4b_2 = make_random_sections('HIV1-B-FR-K03455-seed',
104+
6225,
105+
7757,
106+
projects,
107+
4000,
108+
mutations = (CodonMutation(7000, 'AAA'),)
109+
)
110+
sections_2220_mix5a_1, sections_2220_mix5a_2 = make_random_sections('HIV1-B-FR-K03455-seed',
111+
6225,
112+
7757,
113+
projects,
114+
5000
115+
)
116+
sections_2220_mix5b_1, sections_2220_mix5b_2 = make_random_sections('HIV1-B-FR-K03455-seed',
117+
6225,
118+
7757,
119+
projects,
120+
5000,
121+
mutations = (CodonMutation(7000, 'AAA'),)
122+
)
123+
58124
projects.config['regions']['HXB2-with-deletion'] = dict(
59125
reference=hxb2_ref[617:928] + hxb2_ref[9358:9652],
60126
is_nucleotide=True,
@@ -266,8 +332,51 @@ def main():
266332
FastqFile('2210A-NFLHIVDNA_S25_L001_R2_001.fastq',
267333
'2210',
268334
True,
269-
sections_2210_2)]
335+
sections_2210_2),
336+
FastqFile('2220-HIV-mixture10_S26_L001_R1_001.fastq',
337+
'2220',
338+
False,
339+
sections_2220_mix1a_1 + sections_2220_mix1b_1),
340+
FastqFile('2220-HIV-mixture10_S26_L001_R2_001.fastq',
341+
'2220',
342+
True,
343+
sections_2220_mix1a_2 + sections_2220_mix1b_2),
344+
FastqFile('2220-HIV-mixture20_S27_L001_R1_001.fastq',
345+
'2220',
346+
False,
347+
sections_2220_mix2a_1 + sections_2220_mix2b_1),
348+
FastqFile('2220-HIV-mixture20_S27_L001_R2_001.fastq',
349+
'2220',
350+
True,
351+
sections_2220_mix2a_2 + sections_2220_mix2b_2),
352+
FastqFile('2220-HIV-mixture30_S28_L001_R1_001.fastq',
353+
'2220',
354+
False,
355+
sections_2220_mix3a_1 + sections_2220_mix3b_1),
356+
FastqFile('2220-HIV-mixture30_S28_L001_R2_001.fastq',
357+
'2220',
358+
True,
359+
sections_2220_mix3a_2 + sections_2220_mix3b_2),
360+
FastqFile('2220-HIV-mixture40_S29_L001_R1_001.fastq',
361+
'2220',
362+
False,
363+
sections_2220_mix4a_1 + sections_2220_mix4b_1),
364+
FastqFile('2220-HIV-mixture40_S29_L001_R2_001.fastq',
365+
'2220',
366+
True,
367+
sections_2220_mix4a_2 + sections_2220_mix4b_2),
368+
FastqFile('2220-HIV-mixture50_S30_L001_R1_001.fastq',
369+
'2220',
370+
False,
371+
sections_2220_mix5a_1 + sections_2220_mix5b_1),
372+
FastqFile('2220-HIV-mixture50_S30_L001_R2_001.fastq',
373+
'2220',
374+
True,
375+
sections_2220_mix5a_2 + sections_2220_mix5b_2)
376+
]
270377
for fastq_file in fastq_files:
378+
if not fastq_file.name.startswith('2220-HIV-mixture30'):
379+
continue
271380
with open(fastq_file.name, 'w') as f:
272381
next_cluster = 1
273382
for section in fastq_file.sections:

0 commit comments

Comments
 (0)