-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakefile
executable file
·4538 lines (4015 loc) · 212 KB
/
Snakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import re
import subprocess
import snakemake.io
from glob import glob
import pandas as pd
import time
configfile: "config.yaml"
report: "code/report/workflow.rst"
shell.prefix('printf "Job executed on: ${{HOSTNAME}}\n" && printf "SLURM job id: ${{SLURM_JOB_ID}}\n\n"; ')
# Substitute bash $USER environment variable with actual user id, otherwise some steps fail
param_work_dir = config["work_dir"] #get working directory from config file
userid = env_var = os.environ['USER'] #get bash $USER variable
work_dir = param_work_dir.replace("$USER", userid) #sub $USER for actual username
current_dir = os.getcwd()
#humann_ref_dir = "/home/kiledal/scratch_gdick1/GVHD/data/reference/humann" # for running on Great Lakes
humann_ref_dir = "/geomicro/data2/kiledal/projects/GVHD/data/reference/humann"
# Set which rules can be run on cluster head node
localrules: make_rulegraph, link_reads_w_sample_names
# Get import sample names
#metaG_samples = glob_wildcards("import/metagenomes/{sample}/").sample
#metaT_samples = glob_wildcards("import/metatranscriptomes/{sample}/").sample
#metabolome_samples = glob_wildcards("import/metabolomes/{sample}/").sample
#amplicon_samples = glob_wildcards("import/amplicons/{sample}/").sample
# Get sample names
start_time = time.time() # for testing how long it takes to parse out names
metaG_samples = open("data/sample_metadata/sample_lists/metaG_samples").read().splitlines()
all_metaG_samples = open("data/sample_metadata/sample_lists/all_metaG_samples").read().splitlines()
assembled_samples = open("data/sample_metadata/sample_lists/assembled_samples").read().splitlines()
qcd_samples = open("data/sample_metadata/sample_lists/qcd_samples").read().splitlines()
qcd_transcript_samples = open("data/sample_metadata/sample_lists/qcd_transcript_samples").read().splitlines()
jgi_samples = open("data/sample_metadata/sample_lists/jgi_samples").read().splitlines()
glerl_samples = open("data/sample_metadata/sample_lists/glerl_samples").read().splitlines()
transect_samples = open("data/sample_metadata/sample_lists/transect_samples").read().splitlines()
quast_samples = open("data/sample_metadata/sample_lists/quast_samples").read().splitlines()
read_download_samples = open("data/sample_metadata/sample_lists/read_download_samples").read().splitlines()
read_download_transcript_samples = open("data/sample_metadata/sample_lists/read_download_transcript_samples").read().splitlines()
read_download_amplicon_samples = open("data/sample_metadata/sample_lists/read_download_amplicon_samples").read().splitlines()
metaT_samples = open("data/sample_metadata/sample_lists/metaT_samples").read().splitlines()
metabolome_samples = open("data/sample_metadata/sample_lists/metabolome_samples").read().splitlines()
amplicon_samples = open("data/sample_metadata/sample_lists/amplicon_samples").read().splitlines()
seagull_samples = open("data/sample_metadata/size_sorted_HABs_samples_Seagull.tsv").read().splitlines()
victoria2022_samples = open("data/sample_metadata/sample_lists/victoria2022_samples").read().splitlines()
kenya2023_samples = open("data/sample_metadata/sample_lists/kenya2023_samples").read().splitlines()
# Old items
#metaG_samples = glob_wildcards("data/projects/2022_geomicro_JGI_CSP/metagenomes/{sample}/reads/decon_fwd_reads_fastp.fastq.gz", followlinks=True).sample
#metaG_samples = os.popen("ls data/projects/PRJNA702522/metagenomes/").read().splitlines() #+ os.popen("ls data/projects/PRJNA679730/metagenomes/").read().splitlines() #ESP 2018 & 19
#metaG_samples = os.popen("ls data/projects/PRJNA702522/metagenomes/").read().splitlines() #ESP1
#metaG_samples = os.popen("ls data/projects/2021_ESP/metagenomes/").read().splitlines() #ESP 2021
#metaG_samples = os.popen("ls data/projects/GLERL_USGS_2016_2020/metagenomes/").read().splitlines() + os.popen("ls data/projects/WLE_transects_2022/metagenomes/").read().splitlines()
#metaG_samples = glob_wildcards("data/projects/2022_geomicro_JGI_CSP/metagenomes/{sample}/").sample
#metaG_samples = glob_wildcards("data/projects/PRJNA464361/metagenomes/{sample}/").sample
#metaG_samples = ["E20212019","E20212012","E20212013","E20212010"]
end_time = time.time() # Record end of name parsing
execution_time = end_time - start_time
#print(f"Name processing time: {execution_time} seconds")
# Target rules
rule assemble:
input:
#expand("data/omics/metagenomes/{sample}/assembly/metaspades/contigs.fasta",sample = metaG_samples),
#expand("data/omics/metagenomes/{sample}/assembly/megahit/final.contigs.fa",sample = metaG_samples),
expand("data/omics/metagenomes/{sample}/assembly/metaspades_noNORM/contigs.fasta",sample = metaG_samples),
expand("data/omics/metagenomes/{sample}/assembly/megahit_noNORM/final.contigs.fa",sample = metaG_samples)
rule run_megahit:
input:
expand("data/omics/metagenomes/{sample}/assembly/megahit_noNORM/final.contigs.fa", sample = all_metaG_samples),
expand("data/omics/metagenomes/{sample}/assembly/megahit_noNORM/quast/report.tsv", sample = all_metaG_samples)
rule run_quast:
input:
expand("data/omics/metagenomes/{sample}/assembly/megahit_noNORM/quast/report.tsv", sample = quast_samples)
rule run_metaspades:
input:
expand("data/omics/metagenomes/{sample}/assembly/metaspades_noNORM/contigs.fasta",sample = metaG_samples)
rule run_biosyntheticSPAdes:
input:
expand("data/omics/metagenomes/{sample}/assembly/biosyntheticSPAdes/scaffolds.fasta", sample = jgi_samples)
rule run_prodigal:
input: expand("data/omics/metagenomes/{sample}/proteins/{sample}_PROTEINS.faa", sample = metaG_samples)
rule test:
input: expand("data/omics/metagenomes/{sample}/reads/raw_fwd_reads.fastq.gz",sample = metaG_samples)
output: "test.out"
rule lauren_assembly_and_BGC_test:
input:
# Assemblies
expand("data/omics/metagenomes/{sample}/assembly/metaspades/contigs.fasta",sample = glerl_samples + jgi_samples + transect_samples),
expand("data/omics/metagenomes/{sample}/assembly/megahit/final.contigs.fa",sample = glerl_samples + jgi_samples + transect_samples),
expand("data/omics/metagenomes/{sample}/assembly/metaspades_noNORM/contigs.fasta",sample = glerl_samples + jgi_samples + transect_samples),
#expand("data/omics/metagenomes/{sample}/assembly/megahit_noNORM/final.contigs.fa",sample = glerl_samples + jgi_samples + transect_samples),
expand("data/omics/metagenomes/{sample}/assembly/biosyntheticSPAdes/scaffolds.fasta", sample = glerl_samples + jgi_samples + transect_samples),
expand("data/omics/metagenomes/{sample}/assembly/biosyntheticSPAdes_100x/scaffolds.fasta", sample = glerl_samples + jgi_samples + transect_samples)
rule assemble_victoria:
input:
expand("data/omics/metagenomes/{sample}/assembly/megahit_noNORM/final.contigs.fa", sample = victoria2022_samples),
expand("data/omics/metagenomes/{sample}/assembly/megahit_noNORM/quast/report.tsv", sample = victoria2022_samples)
rule assemble_kenya23:
input:
expand("data/omics/metagenomes/{sample}/assembly/megahit_noNORM/final.contigs.fa", sample = kenya2023_samples),
expand("data/omics/metagenomes/{sample}/assembly/megahit_noNORM/quast/report.tsv", sample = kenya2023_samples),
expand("data/omics/metagenomes/{sample}/reads/{sample}_read_count_fastp.tsv", sample=kenya2023_samples)
rule assemble_glerl2:
input:
expand("data/omics/metagenomes/{sample}/assembly/megahit_noNORM/final.contigs.fa", sample = glerl_samples),
expand("data/omics/metagenomes/{sample}/assembly/megahit_noNORM/quast/report.tsv", sample = glerl_samples),
expand("data/omics/metagenomes/{sample}/reads/{sample}_read_count_fastp.tsv", sample=glerl_samples)
rule assemble_victoria_spades:
input:
expand("data/omics/metagenomes/{sample}/assembly/metaspades_noNORM/contigs.fasta",sample = victoria2022_samples)
hegarty_samples = ["samp_4457","samp_4458"]
rule hegarty_check:
input:
expand("data/omics/metagenomes/{sample}/assembly/megahit_noNORM/final.contigs.fa", sample = hegarty_samples),
expand("data/omics/metagenomes/{sample}/assembly/megahit_noNORM/quast/report.tsv", sample = hegarty_samples),
expand("data/omics/metagenomes/{sample}/reads/{sample}_read_count_fastp.tsv", sample= hegarty_samples)
rule make_rulegraph:
output:
"rulegraph.pdf",
"rulegraph.png"
shell:
"""
snakemake metaG_annotation --rulegraph --dry-run | dot -Tpdf > rulegraph.pdf
snakemake metaG_annotation --rulegraph --dry-run | dot -Tpng > rulegraph.png
"""
rule make_rulegraph_bins:
output:
pdf = "rulegraph_bins.pdf",
png = "rulegraph_bins.png"
shell:
"""
snakemake run_drep_sep metaG_annotation run_humann_fastp run_sourmash annotate_bins data/sample_data/bracken_counts.tsv --rulegraph --dry-run | dot -Tpdf > {output.pdf}
snakemake run_drep_sep metaG_annotation run_humann_fastp run_sourmash annotate_bins data/sample_data/bracken_counts.tsv --rulegraph --dry-run | dot -Tpng > {output.png}
"""
# rule import:
# input:
# output:
# resources: cpus=1, mem_mb=8000, time_min=2880, mem_gb = 8
# shell:
# """
# """
# rule gzip_fastx:
# rule unzip_fastx:
# rule zip_fastqs:
# input: SCRATCH + "/01RAW_fqs/{sample}"
# output: temp(SCRATCH + "/02ZIPPED_fqs/{sample}")
# params: outdir = SCRATCH + "/02ZIPPED_fqs/"
# run:
# if wildcards.sample.endswith('.fastq'):
# shell("echo gzip {input}")
# shell("echo mv {input}.gz {params.outdir}")
# else:
# shell("mv {input} {params.outdir}")
rule get_reads:
input:
acccession = "data/omics/{sample_type}/{sample}/reads/accession"
output:
fwd_reads = "data/omics/{sample_type}/{sample}/reads/raw_fwd_reads.fastq.gz",
rev_reads = "data/omics/{sample_type}/{sample}/reads/raw_rev_reads.fastq.gz",
touch = touch("data/omics/{sample_type}/{sample}/reads/.reads_downloaded")
params:
read_dir = "data/omics/{sample_type}/{sample}/reads/"
conda: "config/conda_yaml/kingfisher.yaml"
#benchmark:
#log:
resources: time_min = 5000, heavy_network = 1, cpus = 8
shell:
"""
export PATH=$PWD/code/kingfisher/bin:$PATH
cd {params.read_dir}
echo $(cat ./accession)
kingfisher get \
--download-threads {resources.cpus} \
--extraction-threads {resources.cpus} \
-r $(cat ./accession) \
-m ena-ascp aws-http prefetch \
--output-format-possibilities fastq.gz
# --check_md5sums \
# -m ena-ftp \
if (($(ls *_1.fastq.gz | wc -l)>1)); then
echo "Error: Multiple files were downloaded."
exit 1
fi
mv -f *_1.fastq.gz raw_fwd_reads.fastq.gz ||true
mv -f *_2.fastq.gz raw_rev_reads.fastq.gz ||true
# Download methods other than ascp can create .fastq files instead
if (($(ls *_1.fastq | wc -l)>1)); then
echo "Error: Multiple files were downloaded."
exit 1
fi
mv -f *_1.fastq raw_fwd_reads.fastq ||true
mv -f *_2.fastq raw_rev_reads.fastq ||true
# If ASCP download fails, other methods can output .fastq, compress before finishing if that's the case
if [ -e raw_fwd_reads.fastq ]; then gzip -1 raw_fwd_reads.fastq; fi
if [ -e raw_rev_reads.fastq ]; then gzip -1 raw_rev_reads.fastq; fi
"""
rule run_get_reads:
input:
expand("data/omics/metagenomes/{sample}/reads/raw_fwd_reads.fastq.gz", sample = read_download_samples),
expand("data/omics/metatranscriptomes/{sample}/reads/raw_fwd_reads.fastq.gz", sample = read_download_transcript_samples),
expand("data/omics/amplicons/{sample}/reads/raw_fwd_reads.fastq.gz", sample = read_download_amplicon_samples)
rule clumpify:
input:
fwd_reads = "data/omics/{sample_type}/{sample}/reads/raw_fwd_reads.fastq.gz",
rev_reads = "data/omics/{sample_type}/{sample}/reads/raw_rev_reads.fastq.gz"
output:
done = touch("data/omics/{sample_type}/{sample}/reads/done.touch")
params:
clumped_fwd_reads = "data/omics/{sample_type}/{sample}/reads/clumped_raw_fwd_reads.fastq.gz",
clumped_rev_reads = "data/omics/{sample_type}/{sample}/reads/clumped_raw_rev_reads.fastq.gz",
conda: "config/conda_yaml/main.yaml"
benchmark:
"benchmarks/clumpify/{sample_type}-{sample}.txt"
log: "logs/clumpify/{sample_type}-{sample}_initial.log"
resources: cpus=16, time_min=2880, mem_mb = lambda wildcards, attempt: attempt * 175000 # standard
#resources: partition = "largemem", cpus=16, time_min=2880, mem_mb = 500000 # coassembly or large samples
shell:
"""
#BBtools use more memory than given, reduce amount given by 20% to stay within job specs.
bbmap_mem=$(echo "scale=-1; ({resources.mem_mb}*0.8)/1" | bc)
clumpify.sh \
-Xmx${{bbmap_mem}}m -eoom \
in1={input.fwd_reads} \
in2={input.rev_reads} \
out1={params.clumped_fwd_reads} \
out2={params.clumped_rev_reads} \
groups=24 \
zl=9 pigz \
t={resources.cpus} \
2>&1 | tee {log} &&
rm {input.fwd_reads} {input.rev_reads} &&
mv {params.clumped_fwd_reads} {input.fwd_reads} &&
mv {params.clumped_rev_reads} {input.rev_reads}
"""
rule deduplicate:
input:
fwd_reads = "data/omics/{sample_type}/{sample}/reads/raw_fwd_reads.fastq.gz",
rev_reads = "data/omics/{sample_type}/{sample}/reads/raw_rev_reads.fastq.gz",
clumpify = "data/omics/{sample_type}/{sample}/reads/done.touch"
output:
dedup_interleaved = temp("data/omics/{sample_type}/{sample}/reads/dedup_interleaved.fastq.gz"),
dedup_reads_fwd = "data/omics/{sample_type}/{sample}/reads/dedup_reads_fwd.fastq.gz",
dedup_reads_rev = "data/omics/{sample_type}/{sample}/reads/dedup_reads_rev.fastq.gz"
conda: "config/conda_yaml/main.yaml"
log: "logs/dedup/{sample_type}-{sample}_dedup.log"
# resources: cpus=36, time_min=2880,
# mem_mb = lambda wildcards, attempt: attempt * 170000,
# #partition = "largemem"
resources:
partition = "largemem",
cpus = 24,
time_min = 7200,
mem_mb = 1000000
shell:
"""
#BBtools use more memory than given, amount given by 20% to stay within job specs.
bbmap_mem=$(echo "scale=-1; ({resources.mem_mb}*0.6)/1" | bc)
dedupe.sh \
-Xmx${{bbmap_mem}}m -eoom \
in1={input.fwd_reads} \
in2={input.rev_reads} \
out={output.dedup_interleaved} \
t={resources.cpus} \
2>&1 | tee {log}
# Dedup only outputs interleaved files, this just converts back to paired
reformat.sh in={output.dedup_interleaved} \
out1={output.dedup_reads_fwd} \
out2={output.dedup_reads_rev} 2>&1 | tee -a {log}
"""
rule de_interleave:
input:
reads = "import/staging/jgi_2022/all_sample_filtered_reads/{sample}_interleaved.fastq.gz"
output:
reads_fwd = "data/omics/{sample_type}/{sample}/reads/raw_fwd_reads.fastq.gz",
reads_rev = "data/omics/{sample_type}/{sample}/reads/raw_rev_reads.fastq.gz"
conda: "config/conda_yaml/main.yaml"
log: "logs/de_interleave/{sample_type}-{sample}.log"
# resources: cpus=36, time_min=2880,
# mem_mb = lambda wildcards, attempt: attempt * 170000,
# #partition = "largemem"
resources:
#partition = "largemem",
cpus = 24,
time_min = 7200,
mem_mb = 120000
shell:
"""
#BBtools use more memory than given, amount given by 20% to stay within job specs.
bbmap_mem=$(echo "scale=-1; ({resources.mem_mb}*0.6)/1" | bc)
# Dedup only outputs interleaved files, this just converts back to paired
reformat.sh in={input.reads} \
out1={output.reads_fwd} \
out2={output.reads_rev} 2>&1 | tee -a {log}
"""
rule JGI_SAMPLES_kraken_summarize_fastp:
input:
script = "code/merge_bracken.R",
kraken_results = expand("data/omics/metagenomes/{sample}/kraken_fastp/{database}_{sample}_bracken.txt", database = ["refseq","gtdb"], sample = glob_wildcards("import/staging/jgi_2022/all_sample_filtered_reads/{sample}_interleaved.fastq.gz").sample),
combined_tax_info = "data/reference/kraken_tax_info_merged.tsv"
output:
counts = "data/sample_data/JGI_bracken_counts.tsv",
rel_abund = "data/sample_data/JGI_bracken_rel_abund.tsv"
resources: cpus=1, mem_mb=5000, time_min=60
container: "docker://eandersk/r_microbiome"
shell:
"""
./{input.script} --taxonomy={input.combined_tax_info} --counts-out={output.counts} --rel-out={output.rel_abund}
"""
ruleorder: remove_contaminants_fastp > de_interleave
rule deinterleave_jgi:
input:
expand("data/omics/metagenomes/{sample}/reads/decon_fwd_reads_fastp.fastq.gz", sample = glob_wildcards("import/staging/jgi_2022/all_sample_filtered_reads/{sample}_interleaved.fastq.gz").sample)
rule fastp:
input:
fwd_reads = "data/omics/{sample_type}/{sample}/reads/raw_fwd_reads.fastq.gz",
rev_reads = "data/omics/{sample_type}/{sample}/reads/raw_rev_reads.fastq.gz",
clumped = "data/omics/{sample_type}/{sample}/reads/done.touch"
output:
tmp_fwd = temp("data/omics/{sample_type}/{sample}/reads/temp_fastp_fwd_reads.fastq.gz"),
tmp_rev = temp("data/omics/{sample_type}/{sample}/reads/temp_fastp_rev_reads.fastq.gz"),
fwd_reads = temp("data/omics/{sample_type}/{sample}/reads/fastp_fwd_reads.fastq.gz"),
rev_reads = temp("data/omics/{sample_type}/{sample}/reads/fastp_rev_reads.fastq.gz"),
html_dedup = "data/omics/{sample_type}/{sample}/reads/qc/fastp_dedup.html",
json_dedup = "data/omics/{sample_type}/{sample}/reads/qc/fastp_dedup.json",
html = "data/omics/{sample_type}/{sample}/reads/qc/fastp.html",
json = "data/omics/{sample_type}/{sample}/reads/qc/fastp.json"
conda: "config/conda_yaml/fastp.yaml"
benchmark:
"benchmarks/fastp/{sample_type}-{sample}.txt"
log: "logs/fastp/{sample_type}-{sample}_fastp.log"
resources: cpus=16, mem_mb = lambda wildcards, attempt: attempt * 60000,
time_min=2880
shell:
"""
# First deduplicate
fastp \
-i {input.fwd_reads} -I {input.rev_reads} \
-o {output.tmp_fwd} -O {output.tmp_rev} \
-h {output.html_dedup} -j {output.json_dedup} \
--thread {resources.cpus} \
-z 3 \
--dedup \
--dup_calc_accuracy 6 2>&1 | tee {log}
# Then trim and remove adapters
fastp \
-i {output.tmp_fwd} -I {output.tmp_rev} \
-o {output.fwd_reads} -O {output.rev_reads} \
-h {output.html} -j {output.json} \
--thread {resources.cpus} \
-z 9 \
--length_required 50 \
--n_base_limit 5 \
--low_complexity_filter --complexity_threshold 7 \
--detect_adapter_for_pe \
--correction \
--cut_front \
--cut_tail \
--cut_window_size=4 \
--cut_mean_quality 20 \
--overrepresentation_analysis 2>&1 | tee -a {log}
"""
rule fastp_no_dedup:
input:
fwd_reads = "data/omics/{sample_type}/{sample}/reads/raw_fwd_reads.fastq.gz",
rev_reads = "data/omics/{sample_type}/{sample}/reads/raw_rev_reads.fastq.gz",
clumped = "data/omics/{sample_type}/{sample}/reads/done.touch"
output:
fwd_reads = temp("data/omics/{sample_type}/{sample}/reads/fastp_no_dedup_fwd_reads.fastq.gz"),
rev_reads = temp("data/omics/{sample_type}/{sample}/reads/fastp_no_dedup_rev_reads.fastq.gz"),
html = "data/omics/{sample_type}/{sample}/reads/qc/fastp_no_dedup.html",
json = "data/omics/{sample_type}/{sample}/reads/qc/fastp_no_dedup.json"
conda: "config/conda_yaml/fastp.yaml"
benchmark:
"benchmarks/fastp_no_dedup/{sample_type}-{sample}.txt"
log: "logs/fastp_no_dedup/{sample_type}-{sample}_fastp.log"
resources: cpus=16, mem_mb = lambda wildcards, attempt: attempt * 60000,
time_min=2880
shell:
"""
# Filter, trim, and remove adapters
fastp \
-i {input.fwd_reads} -I {input.rev_reads} \
-o {output.fwd_reads} -O {output.rev_reads} \
-h {output.html} -j {output.json} \
--thread {resources.cpus} \
-z 9 \
--length_required 50 \
--n_base_limit 5 \
--low_complexity_filter --complexity_threshold 7 \
--detect_adapter_for_pe \
--correction \
--cut_front \
--cut_tail \
--cut_window_size=4 \
--cut_mean_quality 20 \
--overrepresentation_analysis 2>&1 | tee -a {log}
"""
rule fastqc_fastp:
input:
fwd_reads = "data/omics/{sample_type}/{sample}/reads/fastp_fwd_reads.fastq.gz",
rev_reads = "data/omics/{sample_type}/{sample}/reads/fastp_rev_reads.fastq.gz",
output:
#fwd_report = "data/omics/{sample_type}/{sample}/reads/fastqc_raw/fwd_fastqc.html",
#rev_report = "data/omics/{sample_type}/{sample}/reads/fastqc_raw/rev_fastqc.html"
touch("data/omics/{sample_type}/{sample}/reads/fastqc_fastp/.done")
conda:
"config/conda_yaml/fastqc.yaml"
resources: time_min = 7200, cpus = 24, mem_mb = 60000
shell:
"""
mkdir -p data/omics/{wildcards.sample_type}/{wildcards.sample}/reads/fastqc_fastp
fastqc -o data/omics/{wildcards.sample_type}/{wildcards.sample}/reads/fastqc_fastp -t {resources.cpus} {input.fwd_reads}
fastqc -o data/omics/{wildcards.sample_type}/{wildcards.sample}/reads/fastqc_fastp -t {resources.cpus} {input.rev_reads}
"""
rule fastqc_raw:
input:
clumpify_done = "data/omics/{sample_type}/{sample}/reads/done.touch",
fwd_reads = "data/omics/{sample_type}/{sample}/reads/raw_fwd_reads.fastq.gz",
rev_reads = "data/omics/{sample_type}/{sample}/reads/raw_rev_reads.fastq.gz",
output:
#fwd_report = "data/omics/{sample_type}/{sample}/reads/fastqc_raw/fwd_fastqc.html",
#rev_report = "data/omics/{sample_type}/{sample}/reads/fastqc_raw/rev_fastqc.html"
touch("data/omics/{sample_type}/{sample}/reads/fastqc_raw/.done")
conda:
"config/conda_yaml/fastqc.yaml"
resources: time_min = 7200, cpus = 24, mem_mb = 60000
shell:
"""
mkdir -p data/omics/{wildcards.sample_type}/{wildcards.sample}/reads/fastqc_raw
fastqc -o data/omics/{wildcards.sample_type}/{wildcards.sample}/reads/fastqc_raw -t {resources.cpus} {input.fwd_reads}
fastqc -o data/omics/{wildcards.sample_type}/{wildcards.sample}/reads/fastqc_raw -t {resources.cpus} {input.rev_reads}
"""
rule multiqc:
input:
"data/omics/{sample_type}/{sample}/reads/fastqc_fastp/.done",
"data/omics/{sample_type}/{sample}/reads/fastqc_decontam/.done",
"data/omics/{sample_type}/{sample}/reads/fastqc_raw/.done",
#"data/omics/{sample_type}/{sample}/reads/fastqc_teal_decon/.done"
output:
multiqc_dir = directory("data/omics/{sample_type}/{sample}/reads/qc/multiqc")
conda: "config/conda_yaml/multiqc.yaml"
benchmark:
"benchmarks/multiqc/{sample_type}-{sample}.txt"
log: "logs/multiqc/{sample_type}-{sample}.log"
resources: cpus=1, mem_mb = 20000, time_min=2880
shell:
"""
multiqc --interactive -d data/omics/{wildcards.sample_type}/{wildcards.sample}/reads/fastqc_* -o {output.multiqc_dir}
"""
rule run_fastqc_fastp:
input: expand("data/omics/metagenomes/{sample}/reads/fastqc_fastp/.done", sample = metaG_samples),
expand("data/omics/metagenomes/{sample}/reads/qc/multiqc",sample = metaG_samples)
rule get_contaminants:
output:
human_genome = "data/reference/contaminants/human.fa.gz",
spike_ins = "data/reference/contaminants/spike-ins.fa"
resources: cpus = 1
shell:
"""
wget -O {output.human_genome} http://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_38/GRCh38.p13.genome.fa.gz
wget -O {output.spike_ins} https://github.com/TealFurnholm/Strain-Level_Metagenome_Analysis/raw/master/spike-ins.fa
"""
rule bb_index:
input:
human_genome = ancient(rules.get_contaminants.output.human_genome)
output:
"data/reference/contaminants/ref/genome/1/summary.txt",
index = directory("data/reference/contaminants/ref/")
params:
bbmap_index_path = "data/reference/contaminants"
conda: "config/conda_yaml/main.yaml"
log: "logs/bbmap_index.log"
benchmark:
"benchmarks/bb_index.txt"
resources: cpus = 8, mem_mb = 50000
shell:
"""
bbmap.sh \
ref={input.human_genome} \
path={params.bbmap_index_path} \
t={resources.cpus} \
2>&1 | tee {log}
"""
rule remove_contaminants:
input:
dedup_reads_fwd = rules.deduplicate.output.dedup_reads_fwd,
dedup_reads_rev = rules.deduplicate.output.dedup_reads_rev,
human_genome = rules.get_contaminants.output.human_genome,
spike_ins = rules.get_contaminants.output.spike_ins,
adapters = "data/reference/contaminants/adapters.fa",
bbmap_index = "data/reference/contaminants/ref"
output:
trimmed_fwd = "data/omics/{sample_type}/{sample}/reads/trimmed_fwd_reads.fastq.gz",
trimmed_rev = "data/omics/{sample_type}/{sample}/reads/trimmed_rev_reads.fastq.gz",
phix_rm_fwd = "data/omics/{sample_type}/{sample}/reads/phix_fwd_reads.fastq.gz",
phix_rm_rev = "data/omics/{sample_type}/{sample}/reads/phix_rev_reads.fastq.gz",
decon_fwd = "data/omics/{sample_type}/{sample}/reads/decon_fwd_reads.fastq.gz",
decon_rev = "data/omics/{sample_type}/{sample}/reads/decon_rev_reads.fastq.gz",
cleaned_fwd = "data/omics/{sample_type}/{sample}/reads/cleaned_fwd_reads.fastq.gz",
cleaned_rev = "data/omics/{sample_type}/{sample}/reads/cleaned_rev_reads.fastq.gz"
params:
bbmap_index_path = "data/reference/contaminants"
conda: "config/conda_yaml/main.yaml"
log: "logs/read_qc/{sample_type}-{sample}.log"
benchmark:
"benchmarks/remove_contaminants/{sample_type}-{sample}.txt"
resources: cpus = 24, mem_mb = lambda wildcards, attempt: attempt * 120000, time_min = 2880
shell:
"""
bbmap_mem=$(echo "scale=-1; ({resources.mem_mb}*0.8)/1" | bc)
echo "Job memory= {resources.mem_mb}, bbmap allocated memory=$bbmap_mem because it is greedy"
bbduk.sh \
-Xmx${{bbmap_mem}}m -eoom \
in1={input.dedup_reads_fwd} \
in2={input.dedup_reads_rev} \
out1={output.trimmed_fwd} \
out2={output.trimmed_rev} \
t={resources.cpus} \
minlen=50 \
qtrim=rl \
trimq=15 \
ref={input.adapters} \
path={params.bbmap_index_path} \
ktrim=r k=23 mink=11 hdist=1 \
2>&1 | tee {log}
echo "\n\n***doing spike-in removal***\n\n" >> {log}
bbduk.sh \
-Xmx${{bbmap_mem}}m -eoom \
in1={output.trimmed_fwd} \
in2={output.trimmed_rev} \
outu1={output.phix_rm_fwd} \
outu2={output.phix_rm_rev} \
t={resources.cpus} k=31 hdist=1 \
ref={input.spike_ins} \
path={params.bbmap_index_path} \
2>&1 | tee -a {log}
echo "\n\n***doing remove contaminants***\n\n" >> {log}
bbmap.sh \
-Xmx${{bbmap_mem}}m -eoom \
in1={output.phix_rm_fwd} \
in2={output.phix_rm_rev} \
outu1={output.decon_fwd} \
outu2={output.decon_rev} \
t={resources.cpus} fast=t \
ref={input.human_genome} \
path={params.bbmap_index_path} \
-Xmx{resources.mem_mb}m \
2>&1 | tee -a {log}
echo "\n\n***Running RemovePolyPairs.pl***\n\n" | tee -a {log}
perl code/RemovePolyPairs.pl {output.decon_fwd} {output.decon_rev} 50 {output.cleaned_fwd} {output.cleaned_rev} 2>&1 | tee -a {log}
"""
rule count_reads:
input:
raw_reads_fwd = "data/omics/{sample_type}/{sample}/reads/raw_fwd_reads.fastq.gz",
raw_reads_rev = "data/omics/{sample_type}/{sample}/reads/raw_rev_reads.fastq.gz",
deduped_reads_fwd = "data/omics/{sample_type}/{sample}/reads/dedup_reads_fwd.fastq.gz",
deduped_reads_rev = "data/omics/{sample_type}/{sample}/reads/dedup_reads_rev.fastq.gz",
qual_filt_and_trimmed_fwd = "data/omics/{sample_type}/{sample}/reads/trimmed_fwd_reads.fastq.gz",
qual_filt_and_trimmed_rev = "data/omics/{sample_type}/{sample}/reads/trimmed_rev_reads.fastq.gz",
decon_reads_fwd = "data/omics/{sample_type}/{sample}/reads/cleaned_fwd_reads.fastq.gz",
decon_reads_rev = "data/omics/{sample_type}/{sample}/reads/cleaned_rev_reads.fastq.gz"
output:
"data/omics/{sample_type}/{sample}/reads/{sample}_read_count.tsv"
shell:
"""
printf "read_state\tfwd_read_count\trev_read_count\n" > {output}
printf "raw_reads\t$(($(zcat {input.raw_reads_fwd} | wc -l) / 4 ))\t$(($(zcat {input.raw_reads_rev} | wc -l) / 4 ))\n" >> {output}
printf "deduped_reads\t$(($(zcat {input.deduped_reads_fwd} | wc -l) / 4 ))\t$(($(zcat {input.deduped_reads_rev} | wc -l) / 4 ))\n" >> {output}
printf "filt_and_trimmed_reads\t$(($(zcat {input.qual_filt_and_trimmed_fwd} | wc -l) / 4 ))\t$(($(zcat {input.qual_filt_and_trimmed_rev} | wc -l) / 4 ))\n" >> {output}
printf "decon_reads\t$(($(zcat {input.decon_reads_fwd} | wc -l) / 4 ))\t$(($(zcat {input.decon_reads_rev} | wc -l) / 4 ))\n" >> {output}
"""
# rule remove_spike_ins_fastp:
# input:
# spike_ins = rules.get_contaminants.output.spike_ins,
# trimmed_fwd = rules.fastp.output.fwd_reads,
# trimmed_rev = rules.fastp.output.rev_reads
# output:
# phix_rm_fwd = temp("data/omics/metagenomes/{sample}/reads/phix_fwd_reads_fastp.fastq.gz"),
# phix_rm_rev = temp("data/omics/metagenomes/{sample}/reads/phix_rev_reads_fastp.fastq.gz")
# conda: "config/conda_yaml/main.yaml"
# log: "logs/remove_spike_ins/{sample}_fastp.log"
# params:
# bbmap_index_path = "data/reference/contaminants"
# benchmark:
# "benchmarks/remove_spike_ins_fastp/{sample}.txt"
# resources: cpus = 24, mem_mb = lambda wildcards, attempt: attempt * 150000, time_min = 2880
# shell:
# """
# bbmap_mem=$(echo "scale=-1; ({resources.mem_mb}*0.8)/1" | bc)
# echo "Job memory= {resources.mem_mb}, bbmap allocated memory=$bbmap_mem because it is greedy"
# echo "\n\n***Removing spike-in***\n\n" >> {log}
# bbduk.sh -Xmx${{bbmap_mem}}m -eoom \
# in1={input.trimmed_fwd} \
# in2={input.trimmed_rev} \
# outu1={output.phix_rm_fwd} \
# outu2={output.phix_rm_rev} \
# t={resources.cpus} k=31 hdist=1 \
# ref={input.spike_ins} \
# path={params.bbmap_index_path} \
# 1>>{log} 2>&1
# echo "\n\n*** DONE ***\n\n" >> {log}
# """
rule remove_contaminants_fastp:
input:
dedup_reads_fwd = rules.fastp.output.fwd_reads,
dedup_reads_rev = rules.fastp.output.rev_reads,
human_genome = ancient(rules.get_contaminants.output.human_genome),
spike_ins = ancient(rules.get_contaminants.output.spike_ins),
bbmap_index = ancient("data/reference/contaminants/ref")
output:
phix_rm_fwd = temp("data/omics/{sample_type}/{sample}/reads/phix_fwd_reads_fastp.fastq.gz"),
phix_rm_rev = temp("data/omics/{sample_type}/{sample}/reads/phix_rev_reads_fastp.fastq.gz"),
decon_fwd = "data/omics/{sample_type}/{sample}/reads/decon_fwd_reads_fastp.fastq.gz",
decon_rev = "data/omics/{sample_type}/{sample}/reads/decon_rev_reads_fastp.fastq.gz"
params:
bbmap_index_path = "data/reference/contaminants"
conda: "config/conda_yaml/main.yaml"
log: "logs/remove_contaminants_fastp/{sample_type}-{sample}.log"
benchmark:
"benchmarks/remove_contaminants_fastp/{sample_type}-{sample}.txt"
resources: cpus = 24, mem_mb = lambda wildcards, attempt: attempt * 120000, time_min = 2880
shell:
"""
bbmap_mem=$(echo "scale=-1; ({resources.mem_mb}*0.8)/1" | bc)
echo "Job memory= {resources.mem_mb}, bbmap allocated memory=$bbmap_mem because it is greedy"
bbduk.sh \
-Xmx${{bbmap_mem}}m -eoom \
in1={input.dedup_reads_fwd} \
in2={input.dedup_reads_rev} \
outu1={output.phix_rm_fwd} \
outu2={output.phix_rm_rev} \
t={resources.cpus} k=31 hdist=1 \
ref={input.spike_ins} \
path={params.bbmap_index_path} \
2>&1 | tee -a {log}
echo "\n\n***doing remove contaminants***\n\n" >> {log}
bbmap.sh \
-Xmx${{bbmap_mem}}m -eoom \
in1={output.phix_rm_fwd} \
in2={output.phix_rm_rev} \
outu1={output.decon_fwd} \
outu2={output.decon_rev} \
t={resources.cpus} fast=t \
ref={input.human_genome} \
path={params.bbmap_index_path} \
2>&1 | tee -a {log}
"""
rule remove_contaminants_fastp_no_dedup:
input:
dedup_reads_fwd = rules.fastp_no_dedup.output.fwd_reads,
dedup_reads_rev = rules.fastp_no_dedup.output.rev_reads,
human_genome = ancient(rules.get_contaminants.output.human_genome),
spike_ins = ancient(rules.get_contaminants.output.spike_ins),
bbmap_index = ancient("data/reference/contaminants/ref")
output:
phix_rm_fwd = temp("data/omics/{sample_type}/{sample}/reads/phix_fwd_reads_fastp_no_dedup.fastq.gz"),
phix_rm_rev = temp("data/omics/{sample_type}/{sample}/reads/phix_rev_reads_fastp_no_dedup.fastq.gz"),
decon_fwd = "data/omics/{sample_type}/{sample}/reads/noDedup_decon_fwd_reads_fastp.fastq.gz",
decon_rev = "data/omics/{sample_type}/{sample}/reads/noDedup_decon_rev_reads_fastp.fastq.gz"
params:
bbmap_index_path = "data/reference/contaminants"
conda: "config/conda_yaml/main.yaml"
log: "logs/remove_contaminants_fastp_no_dedup/{sample_type}-{sample}.log"
benchmark:
"benchmarks/remove_contaminants_fastp_no_dedup/{sample_type}-{sample}.txt"
resources: cpus = 24, mem_mb = lambda wildcards, attempt: attempt * 120000, time_min = 2880
shell:
"""
bbmap_mem=$(echo "scale=-1; ({resources.mem_mb}*0.8)/1" | bc)
echo "Job memory= {resources.mem_mb}, bbmap allocated memory=$bbmap_mem because it is greedy"
bbduk.sh \
-Xmx${{bbmap_mem}}m -eoom \
in1={input.dedup_reads_fwd} \
in2={input.dedup_reads_rev} \
outu1={output.phix_rm_fwd} \
outu2={output.phix_rm_rev} \
t={resources.cpus} k=31 hdist=1 \
ref={input.spike_ins} \
path={params.bbmap_index_path} \
2>&1 | tee -a {log}
echo "\n\n***doing remove contaminants***\n\n" >> {log}
bbmap.sh \
-Xmx${{bbmap_mem}}m -eoom \
in1={output.phix_rm_fwd} \
in2={output.phix_rm_rev} \
outu1={output.decon_fwd} \
outu2={output.decon_rev} \
t={resources.cpus} fast=t \
ref={input.human_genome} \
path={params.bbmap_index_path} \
2>&1 | tee -a {log}
"""
rule make_read_blastdb:
input:
decon_fwd = "data/omics/metagenomes/{sample}/reads/decon_fwd_reads_fastp.fastq.gz",
decon_rev = "data/omics/metagenomes/{sample}/reads/decon_rev_reads_fastp.fastq.gz"
output:
concat_reads = temp("data/omics/metagenomes/{sample}/reads/concat_decon_reads_fastp.fasta"),
db_index_made = touch("data/omics/metagenomes/{sample}/reads/.read_blast_index_created")
conda: "config/conda_yaml/seqtk.yaml"
log:
"logs/makeblastdb_reads/{sample}.log"
resources: cpus=1, mem_mb=5000, time_min=120
shell:
"""
seqtk seq -a {input.decon_fwd} > {output.concat_reads}
seqtk seq -a {input.decon_rev} >> {output.concat_reads}
makeblastdb -in {output.concat_reads} -dbtype nucl -logfile {log}
"""
rule blast_nuc:
input:
blast_db = rules.make_read_blastdb.output.concat_reads,
blast_db_index = rules.make_read_blastdb.output.db_index_made,
gene = "data/reference/blast_queries/{query}.fasta"
output:
blast_res = "data/omics/metagenomes/{sample}/BLAST/{query}__{sample}.blastn"
log:
"logs/BLAST/{query}__{sample}.log"
resources: cpus=32, mem_mb=5000, time_min=120
shell:
"""
blastn -query {input.gene} \
-db {input.blast_db} \
-out {output.blast_res} \
-outfmt '6 std qcovs stitle qseq sseq' \
-num_threads {resources.cpus}
# removed additional output columns: -outfmt '6 std qcovs stitle' \
# also removed database size standardization: -dbsize 1000000 \
"""
rule blast_Didymosphenia_geminata_chloroplast_16S:
input:
expand("data/omics/metagenomes/{sample}/BLAST/Didymosphenia_geminata_chloroplast_16S__{sample}.blastn", sample=metaG_samples)
rule fastqc_decontam:
input:
fwd_reads = "data/omics/{sample_type}/{sample}/reads/decon_fwd_reads_fastp.fastq.gz",
rev_reads = "data/omics/{sample_type}/{sample}/reads/decon_rev_reads_fastp.fastq.gz"
output:
touch("data/omics/{sample_type}/{sample}/reads/fastqc_decontam/.done")
conda:
"config/conda_yaml/fastqc.yaml"
shell:
"""
mkdir -p data/omics/{wildcards.sample_type}/{wildcards.sample}/reads/fastqc_decontam
fastqc -o data/omics/{wildcards.sample_type}/{wildcards.sample}/reads/fastqc_decontam -t {resources.cpus} {input.fwd_reads}
fastqc -o data/omics/{wildcards.sample_type}/{wildcards.sample}/reads/fastqc_decontam -t {resources.cpus} {input.rev_reads}
"""
rule run_fastqc_decontam:
input: expand("data/omics/metagenomes/{sample}/reads/fastqc_decontam/.done", sample = metaG_samples)
rule bbnorm:
input:
fwd_reads = rules.remove_contaminants_fastp.output.decon_fwd,
rev_reads = rules.remove_contaminants_fastp.output.decon_rev
output:
fwd_norm = temp("data/omics/{sample_type}/{sample}/reads/bbnorm_fwd_reads.fastq.gz"),
rev_norm = temp("data/omics/{sample_type}/{sample}/reads/bbnorm_rev_reads.fastq.gz")
params: "target=100 mindepth=2 bits=16 prefilter ecc=t"
conda: "config/conda_yaml/main.yaml"
log: "logs/bbnorm/{sample_type}/{sample}.log"
benchmark:
"benchmarks/bbnorm/{sample_type}/{sample}.txt"
resources: cpus = 36, mem_mb = lambda wildcards, attempt: attempt * 80000, time_min = 2880
shell:
"""
bbmap_mem=$(echo "scale=-1; ({resources.mem_mb}*0.8)/1" | bc)
echo "Job memory= {resources.mem_mb}, bbmap allocated memory=$bbmap_mem because it is greedy"
bbnorm.sh \
-Xmx${{bbmap_mem}}m -eoom \
in1={input.fwd_reads} \
in2={input.rev_reads} \
out1={output.fwd_norm} \
out2={output.rev_norm} \
t={resources.cpus} \
{params} \
1>>{log} 2>&1
"""
rule count_reads_fastp:
input:
raw_reads_fwd = "data/omics/{sample_type}/{sample}/reads/raw_fwd_reads.fastq.gz",
raw_reads_rev = "data/omics/{sample_type}/{sample}/reads/raw_rev_reads.fastq.gz",
deduped_reads_fwd = "data/omics/{sample_type}/{sample}/reads/fastp_fwd_reads.fastq.gz",
deduped_reads_rev = "data/omics/{sample_type}/{sample}/reads/fastp_rev_reads.fastq.gz",
qual_filt_and_trimmed_fwd = rules.fastp.output.fwd_reads,
qual_filt_and_trimmed_rev = rules.fastp.output.rev_reads,
decon_reads_fwd = "data/omics/{sample_type}/{sample}/reads/decon_fwd_reads_fastp.fastq.gz",
decon_reads_rev = "data/omics/{sample_type}/{sample}/reads/decon_rev_reads_fastp.fastq.gz",
#bbnorm_reads_fwd = rules.bbnorm.output.fwd_norm,
#bbnorm_reads_rev = rules.bbnorm.output.rev_norm,
output:
"data/omics/{sample_type}/{sample}/reads/{sample}_read_count_fastp.tsv"
resources: cpus=4
shell:
"""
printf "read_state\tfwd_read_count\trev_read_count\n" > {output} &&
printf "raw_reads\t$(($(pigz -dc -p {resources.cpus} {input.raw_reads_fwd} | wc -l) / 4 ))\t$(($(pigz -dc -p {resources.cpus} {input.raw_reads_rev} | wc -l) / 4 ))\n" >> {output} &&
printf "deduped_reads\t$(($(pigz -dc -p {resources.cpus} {input.deduped_reads_fwd} | wc -l) / 4 ))\t$(($(pigz -dc -p {resources.cpus} {input.deduped_reads_rev} | wc -l) / 4 ))\n" >> {output} &&
printf "filt_and_trimmed_reads\t$(($(pigz -dc -p {resources.cpus} {input.qual_filt_and_trimmed_fwd} | wc -l) / 4 ))\t$(($(pigz -dc -p {resources.cpus} {input.qual_filt_and_trimmed_rev} | wc -l) / 4 ))\n" >> {output} &&
printf "decon_reads\t$(($(pigz -dc -p {resources.cpus} {input.decon_reads_fwd} | wc -l) / 4 ))\t$(($(pigz -dc -p {resources.cpus} {input.decon_reads_rev} | wc -l) / 4 ))\n" >> {output}
"""
#printf "bbnorm_reads\t$(($(pigz -dc -p {resources.cpus} {input.bbnorm_reads_fwd} | wc -l) / 4 ))\t$(($(pigz -dc -p {resources.cpus} {input.bbnorm_reads_rev} | wc -l) / 4 ))\n" >> {output}
rule run_count_reads:
input:
expand("data/omics/metagenomes/{sample}/reads/{sample}_read_count.tsv", sample=metaG_samples),
expand("data/omics/metagenomes/{sample}/reads/{sample}_read_count_fastp.tsv", sample=metaG_samples)
rule run_count_reads_fastp:
input:
expand("data/omics/metagenomes/{sample}/reads/{sample}_read_count_fastp.tsv", sample=qcd_samples)
rule assemble_metaspades:
input:
fwd_reads = rules.bbnorm.output.fwd_norm,
rev_reads = rules.bbnorm.output.rev_norm
output:
assembly_dir = directory("data/omics/{sample_type}/{sample}/assembly/metaspades"),
contigs = "data/omics/{sample_type}/{sample}/assembly/metaspades/contigs.fasta"
conda: "config/conda_yaml/main.yaml"
log: "logs/assembly/metaspades/{sample_type}_{sample}.log"
benchmark: "benchmarks/metaspades/{sample_type}_{sample}.txt"
#resources: cpus = 24, time_min=7200, mem_mb = lambda wildcards, attempt: attempt * 120000
#resources: cpus = 24, time_min=20000, mem_mb = 500000, partition = "largemem"
resources: cpus = 36, time_min=20000, mem_mb = 170000
#resources: cpus = 64, time_min=20000, mem_mb = 500000
shell:
"""
export OMP_NUM_THREADS={resources.cpus}
metaspades.py \
-t {resources.cpus} \
--memory $(({resources.mem_mb}/1024)) \
-1 {input.fwd_reads} \
-2 {input.rev_reads} \
-o {output.assembly_dir} 2>&1 | tee {log}
"""
rule assemble_metaspades_noNORM:
input:
fwd_reads = rules.remove_contaminants_fastp.output.decon_fwd,
rev_reads = rules.remove_contaminants_fastp.output.decon_rev
output:
assembly_dir = directory("data/omics/{sample_type}/{sample}/assembly/metaspades_noNORM"),
contigs = "data/omics/{sample_type}/{sample}/assembly/metaspades_noNORM/contigs.fasta"
conda: "config/conda_yaml/main.yaml"
log: "logs/assembly/metaspades_noNORM/{sample_type}_{sample}.log"
benchmark: "benchmarks/metaspades_noNORM/{sample_type}_{sample}.txt"
#resources: cpus = 24, time_min=7200, mem_mb = lambda wildcards, attempt: attempt * 120000
#resources: cpus = 24, time_min=20000, mem_mb = 500000, partition = "largemem"
#resources: cpus = 36, time_min=20000, mem_mb = 170000
resources: cpus = 64, time_min=20000, mem_mb = 500000
shell:
"""
export OMP_NUM_THREADS={resources.cpus}
metaspades.py \
-t {resources.cpus} \
--memory $(({resources.mem_mb}/1024)) \
-1 {input.fwd_reads} \
-2 {input.rev_reads} \
-o {output.assembly_dir} 2>&1 | tee {log}
"""
rule assemble_biosyntheticSPAdes:
input:
fwd_reads = rules.remove_contaminants_fastp.output.decon_fwd,
rev_reads = rules.remove_contaminants_fastp.output.decon_rev
output:
assembly_dir = directory("data/omics/{sample_type}/{sample}/assembly/biosyntheticSPAdes"),
contigs = "data/omics/{sample_type}/{sample}/assembly/biosyntheticSPAdes/scaffolds.fasta"
conda: "config/conda_yaml/main.yaml"
log: "logs/assembly/biosyntheticSPAdes/{sample_type}_{sample}.log"
benchmark: "benchmarks/biosyntheticSPAdes/{sample_type}_{sample}.txt"
#resources: cpus = 24, time_min=7200, mem_mb = lambda wildcards, attempt: attempt * 120000
resources: cpus = 24, time_min=20000, mem_mb = 500000, partition = "largemem"
#resources: cpus = 36, time_min=20000, mem_mb = 170000
#resources: cpus = 64, time_min=20000, mem_mb = 500000
shell:
"""
export OMP_NUM_THREADS={resources.cpus}
metaspades.py \
-t {resources.cpus} \
--bio \
--memory $(({resources.mem_mb}/1024)) \
-1 {input.fwd_reads} \
-2 {input.rev_reads} \
-o {output.assembly_dir} 2>&1 | tee {log}
"""
rule assemble_RNAspades:
input:
fwd_reads = rules.remove_contaminants_fastp.output.decon_fwd,
rev_reads = rules.remove_contaminants_fastp.output.decon_rev
output:
contigs = "data/omics/{sample_type}/{sample}/assembly/RNAspades/transcripts.fasta"
params:
assembly_dir = "data/omics/{sample_type}/{sample}/assembly/RNAspades"
conda: "config/conda_yaml/spades4.yaml"
log: "logs/assembly/RNAspades/{sample_type}_{sample}.log"
benchmark: "benchmarks/RNAspades/{sample_type}_{sample}.txt"