Skip to content

Commit a2074ca

Browse files
authored
Fix downsample (#222)
* edited file names for downsample fastqs * stringified depth for file name
1 parent 658e6db commit a2074ca

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

flowcraft/generator/templates/downsample_fastq.nf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ process downsample_fastq_{{ pid }} {
1717
{% include "post.txt" ignore missing %}
1818

1919
tag { "${sample_id}" }
20-
publishDir "results/downsample_fastq_{{ pid }}/", pattern: "*_ss.*"
20+
21+
publishDir "results/downsample_fastq_{{ pid }}/", pattern: "*_ss_*.*"
2122

2223
input:
2324
set sample_id, file(fastq_pair) from {{ input_channel }}
@@ -27,7 +28,7 @@ process downsample_fastq_{{ pid }} {
2728
val clear from checkpointClear_{{ pid }}
2829

2930
output:
30-
set sample_id, file('*_ss.*') into {{ output_channel }}
31+
set sample_id, file('*_ss_*.*') into {{ output_channel }}
3132
{% with task_name="downsample_fastq" %}
3233
{%- include "compiler_channels.txt" ignore missing -%}
3334
{% endwith %}

flowcraft/templates/downsample_fastq.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,17 @@ def main(sample_id, fastq_pair, genome_size, depth, clear, seed):
134134
# print ("Writing R1.fq.gz")
135135
ps = subprocess.Popen(('seqtk', 'sample', parsed_seed, p1, str(ratio)),
136136
stdout=subprocess.PIPE)
137-
with open('{}_ss.fq.gz'.format(bn1), 'w') as outfile:
137+
with open('{}_ss_{}.fq.gz'.format(bn1, str(target_depth)), 'w') as \
138+
outfile:
138139
subprocess.Popen(('gzip', '--fast', '-c'),
139140
stdin=ps.stdout, stdout=outfile )
140141
ps.wait()
141142

142143
# print ("Writing R2.fq.gz")
143144
ps = subprocess.Popen(('seqtk', 'sample', parsed_seed, p2, str(ratio)),
144145
stdout=subprocess.PIPE)
145-
with open('{}_ss.fq.gz'.format(bn2), 'w') as outfile:
146+
with open('{}_ss_{}.fq.gz'.format(bn2, str(target_depth)), 'w') as \
147+
outfile:
146148
subprocess.Popen(('gzip', '--fast', '-c'),
147149
stdin=ps.stdout, stdout=outfile)
148150
ps.wait()
@@ -157,8 +159,8 @@ def main(sample_id, fastq_pair, genome_size, depth, clear, seed):
157159
os.remove(rp)
158160

159161
else:
160-
shutil.copy(p1, "{}._ss.fq.gz".format(bn1))
161-
shutil.copy(p2, "{}._ss.fq.gz".format(bn2))
162+
os.symlink(p1, "{}_ss_{}.fq.gz".format(bn1, str(target_depth)))
163+
os.symlink(p2, "{}_ss_{}.fq.gz".format(bn2, str(target_depth)))
162164

163165
# Record the original estimated coverage
164166
with open(".report.json", "w") as fh:

0 commit comments

Comments
 (0)