Skip to content

Commit

Permalink
Fix downsample (#222)
Browse files Browse the repository at this point in the history
* edited file names for downsample fastqs
* stringified depth for file name
  • Loading branch information
cimendes committed Sep 16, 2019
1 parent 658e6db commit a2074ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions flowcraft/generator/templates/downsample_fastq.nf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ process downsample_fastq_{{ pid }} {
{% include "post.txt" ignore missing %}

tag { "${sample_id}" }
publishDir "results/downsample_fastq_{{ pid }}/", pattern: "*_ss.*"

publishDir "results/downsample_fastq_{{ pid }}/", pattern: "*_ss_*.*"

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

output:
set sample_id, file('*_ss.*') into {{ output_channel }}
set sample_id, file('*_ss_*.*') into {{ output_channel }}
{% with task_name="downsample_fastq" %}
{%- include "compiler_channels.txt" ignore missing -%}
{% endwith %}
Expand Down
10 changes: 6 additions & 4 deletions flowcraft/templates/downsample_fastq.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,17 @@ def main(sample_id, fastq_pair, genome_size, depth, clear, seed):
# print ("Writing R1.fq.gz")
ps = subprocess.Popen(('seqtk', 'sample', parsed_seed, p1, str(ratio)),
stdout=subprocess.PIPE)
with open('{}_ss.fq.gz'.format(bn1), 'w') as outfile:
with open('{}_ss_{}.fq.gz'.format(bn1, str(target_depth)), 'w') as \
outfile:
subprocess.Popen(('gzip', '--fast', '-c'),
stdin=ps.stdout, stdout=outfile )
ps.wait()

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

else:
shutil.copy(p1, "{}._ss.fq.gz".format(bn1))
shutil.copy(p2, "{}._ss.fq.gz".format(bn2))
os.symlink(p1, "{}_ss_{}.fq.gz".format(bn1, str(target_depth)))
os.symlink(p2, "{}_ss_{}.fq.gz".format(bn2, str(target_depth)))

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

0 comments on commit a2074ca

Please sign in to comment.