-
Notifications
You must be signed in to change notification settings - Fork 4
/
MetaPro_commands.py
3661 lines (2988 loc) · 192 KB
/
MetaPro_commands.py
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
# The functions here generate the pipeline commands.
# The functions here generate the pipeline commands.
# Each command module is made up of sub stages that are used to get the final result.
import os
import os.path
from numpy.core.arrayprint import _make_options_dict
import MetaPro_paths as mpp
import subprocess as sp
import time
import sys
from datetime import datetime as dt
class mt_pipe_commands:
# --------------------------------------------------------------------
# constructor:
# there should only be one of these objects used for an entire pipeline.
def __init__(self, no_host, Config_path, Quality_score=33, tutorial_keyword = None, sequence_path_1=None, sequence_path_2=None, sequence_single=None, sequence_contigs = None):
self.tool_path_obj = mpp.tool_path_obj(Config_path)
self.no_host_flag = no_host
# path to the genome sequence file
if(tutorial_keyword is None):
print("MetaPro operating in auto-mode")
self.tutorial_keyword = None
if sequence_single is not None:
self.sequence_single = sequence_single
self.sequence_path_1 = ""
self.sequence_path_2 = ""
print("Reads:", self.sequence_single)
self.read_mode = "single"
self.sequence_contigs = ""
else:
self.sequence_single = ""
self.sequence_path_1 = sequence_path_1
self.sequence_path_2 = sequence_path_2
print("Forward Reads:", self.sequence_path_1)
print("Reverse Reads:", self.sequence_path_2)
self.read_mode = "paired"
self.sequence_contigs = ""
else:
print("MetaPro is in TUTORIAL MODE:", tutorial_keyword)
self.tutorial_keyword = tutorial_keyword
if sequence_path_1 is None:
self.sequence_single = sequence_single
self.sequence_path_1 = ""
self.sequence_path_2 = ""
self.sequence_contigs = ""
if(sequence_contigs is not None):
self.sequence_contigs = sequence_contigs
print("Reads:", self.sequence_single)
print("potential contigs:", self.sequence_contigs)
self.read_mode = "single"
else:
self.sequence_single = ""
if(sequence_single is not None):
self.sequence_single = sequence_single
self.sequence_contigs = ""
if(sequence_contigs is not None):
self.sequence_contigs = sequence_contigs
self.sequence_path_1 = sequence_path_1
self.sequence_path_2 = sequence_path_2
print("Forward Reads:", self.sequence_path_1)
print("Reverse Reads:", self.sequence_path_2)
print("potential singletons:", self.sequence_single)
print("potential contigs:", self.sequence_contigs)
self.read_mode = "paired"
self.Qual_str = str(Quality_score)
self.Output_Path = os.getcwd()
self.threads_str = str(self.tool_path_obj.num_threads)
self.thread_count = self.tool_path_obj.num_threads
self.DNA_DB = self.tool_path_obj.DNA_DB
print("Output filepath:", self.Output_Path)
# -----------------------------------------------------------
# support functions
def make_folder(self, folder_path):
if not (os.path.exists(folder_path)):
os.makedirs(folder_path)
def conditional_insert_job_into_queue(self, job_location, queue, command):
if(not os.path.exists(job_location)):
print(dt.today(), job_location, "doesn't exist. adding")
if(not queue):
queue = [command]
else:
queue.append(command)
print(queue)
return queue
def create_and_launch(self, job_folder, inner_name, command_list):
# create the pbs job, and launch items
# job name: string tag for export file name
# command list: list of command statements for writing
# mode: selection of which pbs template to use: default -> low memory
# dependency_list: if not empty, will append wait args to sbatch subprocess call. it's polymorphic
# returns back the job ID given from sbatch
# docker mode: single cpu
# no ID, no sbatch. just run the command
shell_script_full_path = os.path.join(self.Output_Path, job_folder, inner_name + ".sh")
with open(shell_script_full_path, "w") as PBS_script_out:
for item in command_list:
PBS_script_out.write(item + "\n")
PBS_script_out.close()
#if not work_in_background:
output = ""
try:
sp.check_output(["sh", shell_script_full_path])#, stderr = sp.STDOUT)
except sp.CalledProcessError as e:
return_code = e.returncode
if return_code != 1:
raise
def launch_only(self, command_list, command_list_length):
#just launch the job. Don't make a script file.
#print(dt.today(), "inside launch_only:", len(command_list))
if(command_list_length == 1):
#print("0th item:", command_list[0])
try:
os.system(command_list[0])
except sp.CalledProcessError as e:
return_code = e.returncode
if return_code != 1:
raise
#else:
# sys.exit("something bad happened")
else:
for command_item in command_list:
try:
os.system(command_item)
except sp.CalledProcessError as e:
return_code = e.returncode
if return_code != 1:
raise
def create_quality_control_command(self, stage_name):
subfolder = os.path.join(self.Output_Path, stage_name)
data_folder = os.path.join(subfolder, "data")
sorted_read_folder = os.path.join(data_folder, "0_sorted_raw_input")
adapter_folder = os.path.join(data_folder, "1_adapter_removal")
tag_remove_folder = os.path.join(data_folder, "2_tag_remove")
vsearch_merge_folder = os.path.join(data_folder, "3_vsearch_pair_merge")
vsearch_filter_folder = os.path.join(data_folder, "4_quality_filter")
orphan_read_filter_folder = os.path.join(data_folder, "5_orphan_read_filter")
cdhit_folder = os.path.join(data_folder, "6_remove_duplicates")
final_folder = os.path.join(subfolder, "final_results")
self.make_folder(subfolder)
self.make_folder(data_folder)
self.make_folder(sorted_read_folder)
self.make_folder(adapter_folder)
self.make_folder(tag_remove_folder)
self.make_folder(vsearch_merge_folder)
self.make_folder(vsearch_filter_folder)
self.make_folder(orphan_read_filter_folder)
self.make_folder(cdhit_folder)
self.make_folder(final_folder)
sort_pair_1 = ">&2 echo Sorting pair 1 | "
sort_pair_1 += self.tool_path_obj.Python + " "
sort_pair_1 += self.tool_path_obj.sort_reads + " "
sort_pair_1 += self.sequence_path_1 + " "
sort_pair_1 += os.path.join(sorted_read_folder, "pair_1_sorted.fastq") + " "
sort_pair_1 += "forward"
sort_pair_2 = ">&2 echo Sorting pair 2 | "
sort_pair_2 += self.tool_path_obj.Python + " "
sort_pair_2 += self.tool_path_obj.sort_reads + " "
sort_pair_2 += self.sequence_path_2 + " "
sort_pair_2 += os.path.join(sorted_read_folder, "pair_2_sorted.fastq") + " "
sort_pair_2 += "reverse"
adapter_removal_line = ">&2 echo Removing adapters | "
adapter_removal_line += self.tool_path_obj.AdapterRemoval
if self.read_mode == "single":
adapter_removal_line += " --file1 " + self.sequence_single
elif self.read_mode == "paired":
adapter_removal_line += " --file1 " + os.path.join(sorted_read_folder, "pair_1_sorted.fastq")
adapter_removal_line += " --file2 " + os.path.join(sorted_read_folder, "pair_2_sorted.fastq")
adapter_removal_line += " --qualitybase " + str(self.Qual_str)
if(self.Qual_str == "33"):
adapter_removal_line += " --qualitymax 75"
adapter_removal_line += " --threads " + self.threads_str
adapter_removal_line += " --minlength " + str(self.tool_path_obj.adapterremoval_minlength)
adapter_removal_line += " --basename " + adapter_folder
adapter_removal_line += "_AdapterRemoval"
adapter_removal_line += " --trimqualities "
if self.read_mode == "single":
adapter_removal_line += " --output1 " + os.path.join(adapter_folder, "singletons_adptr_rem.fastq")
elif self.read_mode == "paired":
adapter_removal_line += " --output1 " + os.path.join(adapter_folder, "pair_1_adptr_rem.fastq")
adapter_removal_line += " --output2 " + os.path.join(adapter_folder, "pair_2_adptr_rem.fastq")
adapter_removal_line += " --singleton " + os.path.join(adapter_folder, "singletons_adptr_rem.fastq")
#Sort-reads introduces tags at the read-level of the
tag_remove_pair_1 = ">&2 echo Remove tags pair 1 | "
tag_remove_pair_1 += self.tool_path_obj.Python + " "
tag_remove_pair_1 += self.tool_path_obj.remove_tag + " "
tag_remove_pair_1 += os.path.join(adapter_folder, "pair_1_adptr_rem.fastq") + " "
tag_remove_pair_1 += os.path.join(tag_remove_folder, "pair_1_no_tags.fastq")
tag_remove_pair_2 = ">&2 echo Remove tags pair 2 | "
tag_remove_pair_2 += self.tool_path_obj.Python + " "
tag_remove_pair_2 += self.tool_path_obj.remove_tag + " "
tag_remove_pair_2 += os.path.join(adapter_folder, "pair_2_adptr_rem.fastq") + " "
tag_remove_pair_2 += os.path.join(tag_remove_folder, "pair_2_no_tags.fastq")
tag_remove_singletons = ">&2 echo Remove tags singletons | "
tag_remove_singletons += self.tool_path_obj.Python + " "
tag_remove_singletons += self.tool_path_obj.remove_tag + " "
tag_remove_singletons += os.path.join(adapter_folder, "singletons_adptr_rem.fastq") + " "
tag_remove_singletons += os.path.join(tag_remove_folder, "singletons_no_tags.fastq")
# tries to merge the cleaned pairs
# rejects get sent out
vsearch_merge = ">&2 echo " + "Vsearch Merge pairs | "
vsearch_merge += self.tool_path_obj.vsearch
vsearch_merge += " --fastq_mergepairs " + os.path.join(tag_remove_folder, "pair_1_no_tags.fastq")
vsearch_merge += " --reverse " + os.path.join(tag_remove_folder, "pair_2_no_tags.fastq")
vsearch_merge += " --fastq_ascii " + str(self.Qual_str)
vsearch_merge += " --fastqout " + os.path.join(vsearch_merge_folder, "merge_success.fastq")
vsearch_merge += " --fastqout_notmerged_fwd " + os.path.join(vsearch_merge_folder, "pair_1_merge_reject.fastq")
vsearch_merge += " --fastqout_notmerged_rev " + os.path.join(vsearch_merge_folder, "pair_2_merge_reject.fastq")
# concatenate the merge overlaps with the singletons
cat_glue = ">&2 echo concatenating singletons | "
cat_glue += "cat "
cat_glue += os.path.join(vsearch_merge_folder, "merge_success.fastq") + " "
cat_glue += os.path.join(tag_remove_folder, "singletons_no_tags.fastq")
cat_glue += " > " + os.path.join(vsearch_merge_folder, "singletons.fastq")
# Filter out low-quality reads
# start with the singles / merged sections
vsearch_filter_0 = ">&2 echo low-quality filter on singletons | "
vsearch_filter_0 += self.tool_path_obj.vsearch
if self.read_mode == "single":
vsearch_filter_0 += " --fastq_filter " + os.path.join(adapter_folder, "singletons_adptr_rem.fastq")
elif self.read_mode == "paired":
vsearch_filter_0 += " --fastq_filter " + os.path.join(vsearch_merge_folder, "singletons.fastq")
vsearch_filter_0 += " --fastq_ascii " + self.Qual_str
vsearch_filter_0 += " --fastq_maxee " + "2.0"
vsearch_filter_0 += " --fastqout " + os.path.join(vsearch_filter_folder, "singletons_hq.fastq")
# then move onto the standalones in pair 1
vsearch_filter_1 = ">&2 echo low-quality filter on pair 1 | "
vsearch_filter_1 += self.tool_path_obj.vsearch
vsearch_filter_1 += " --fastq_filter " + os.path.join(vsearch_merge_folder, "pair_1_merge_reject.fastq")
vsearch_filter_1 += " --fastq_ascii " + self.Qual_str
vsearch_filter_1 += " --fastq_maxee " + "2.0"
vsearch_filter_1 += " --fastqout " + os.path.join(vsearch_filter_folder, "pair_1_hq.fastq")
vsearch_filter_2 = ">&2 echo low-quality filter on pair 2 | "
vsearch_filter_2 += self.tool_path_obj.vsearch
vsearch_filter_2 += " --fastq_filter " + os.path.join(vsearch_merge_folder, "pair_2_merge_reject.fastq")
vsearch_filter_2 += " --fastq_ascii " + self.Qual_str
vsearch_filter_2 += " --fastq_maxee " + "2.0"
vsearch_filter_2 += " --fastqout " + os.path.join(vsearch_filter_folder, "pair_2_hq.fastq")
# redistribute data into singletons, or paired-reads
orphan_read_filter = ">&2 echo moving newly orphaned reads | "
orphan_read_filter += self.tool_path_obj.Python + " "
orphan_read_filter += self.tool_path_obj.orphaned_read_filter + " "
orphan_read_filter += os.path.join(vsearch_filter_folder, "pair_1_hq.fastq") + " "
orphan_read_filter += os.path.join(vsearch_filter_folder, "pair_2_hq.fastq") + " "
orphan_read_filter += os.path.join(vsearch_filter_folder, "singletons_hq.fastq") + " "
orphan_read_filter += os.path.join(orphan_read_filter_folder, "pair_1_match.fastq") + " "
orphan_read_filter += os.path.join(orphan_read_filter_folder, "pair_2_match.fastq") + " "
orphan_read_filter += os.path.join(orphan_read_filter_folder, "singletons_with_duplicates.fastq")
# remove duplicates (to shrink the data size)
cdhit_singletons = ">&2 echo removing singleton duplicates | "
cdhit_singletons += self.tool_path_obj.cdhit_dup + " -i "
if self.read_mode == "single":
cdhit_singletons += os.path.join(vsearch_filter_folder, "singletons_hq.fastq")
elif self.read_mode == "paired":
cdhit_singletons += os.path.join(orphan_read_filter_folder, "singletons_with_duplicates.fastq")
cdhit_singletons += " -o " + os.path.join(cdhit_folder, "singletons_unique.fastq")
# remove duplicates in the pairs
cdhit_paired = ">&2 echo remove duplicates from paired | "
cdhit_paired += self.tool_path_obj.cdhit_dup + " "
cdhit_paired += "-i" + " " + os.path.join(orphan_read_filter_folder, "pair_1_match.fastq") + " "
cdhit_paired += "-i2" + " " + os.path.join(orphan_read_filter_folder, "pair_2_match.fastq") + " "
cdhit_paired += "-o" + " " + os.path.join(cdhit_folder, "pair_1_unique.fastq") + " "
cdhit_paired += "-o2" + " " + os.path.join(cdhit_folder, "pair_2_unique.fastq")
#move data to appropriate places
copy_singletons = "cp " + os.path.join(cdhit_folder, "singletons_unique.fastq") + " "
copy_singletons += os.path.join(final_folder, "singletons.fastq")
copy_pair_1 = "cp " + os.path.join(cdhit_folder, "pair_1_unique.fastq") + " "
copy_pair_1 += os.path.join(final_folder, "pair_1.fastq")
copy_pair_2 = "cp " + os.path.join(cdhit_folder, "pair_2_unique.fastq") + " "
copy_pair_2 += os.path.join(final_folder, "pair_2.fastq")
# move these particular files to final_folder because they'll be needed by another stage.
copy_duplicate_singletons = "cp "
if(self.read_mode == "single"):
copy_duplicate_singletons += os.path.join(vsearch_filter_folder, "singletons_hq.fastq") + " "
copy_duplicate_singletons += os.path.join(final_folder, "singletons_hq.fastq")
else:
copy_duplicate_singletons += os.path.join(orphan_read_filter_folder, "singletons_with_duplicates.fastq") + " "
copy_duplicate_singletons += os.path.join(final_folder, "singletons_with_duplicates.fastq")
copy_pair_1_match = "cp " + os.path.join(orphan_read_filter_folder, "pair_1_match.fastq") + " "
copy_pair_1_match += os.path.join(final_folder, "pair_1_match.fastq")
copy_pair_2_match = "cp " + os.path.join(orphan_read_filter_folder, "pair_2_match.fastq") + " "
copy_pair_2_match += os.path.join(final_folder, "pair_2_match.fastq")
copy_singletons_cluster = "cp " + os.path.join(cdhit_folder, "singletons_unique.fastq.clstr") + " "
copy_singletons_cluster += os.path.join(final_folder, "singletons_unique.fastq.clstr")
copy_paired_cluster = "cp " + os.path.join(cdhit_folder, "pair_1_unique.fastq.clstr") + " "
copy_paired_cluster += os.path.join(final_folder, "pair_1_unique.fastq.clstr")
if self.read_mode == "single":
COMMANDS_qual = [
adapter_removal_line,
vsearch_filter_0,
cdhit_singletons,
copy_singletons,
copy_duplicate_singletons,
copy_singletons_cluster
]
elif self.read_mode == "paired":
COMMANDS_qual = [
sort_pair_1,
sort_pair_2,
adapter_removal_line,
tag_remove_pair_1,
tag_remove_pair_2,
tag_remove_singletons,
vsearch_merge,
cat_glue,
vsearch_filter_0,
vsearch_filter_1,
vsearch_filter_2,
orphan_read_filter,
cdhit_singletons,
cdhit_paired,
copy_singletons,
copy_pair_1,
copy_pair_2,
copy_duplicate_singletons,
copy_singletons_cluster,
copy_pair_1_match,
copy_paired_cluster,
copy_pair_2_match
]
return COMMANDS_qual
def create_host_filter_command(self, stage_name, dependency_name):
subfolder = os.path.join(self.Output_Path, stage_name)
data_folder = os.path.join(subfolder, "data")
quality_folder = os.path.join(self.Output_Path, dependency_name, "final_results")
host_removal_folder = os.path.join(data_folder, "0_remove_host")
blat_hr_folder = os.path.join(data_folder, "1_blat_host")
final_folder = os.path.join(subfolder, "final_results")
self.make_folder(subfolder)
self.make_folder(data_folder)
self.make_folder(host_removal_folder)
self.make_folder(blat_hr_folder)
self.make_folder(final_folder)
Host_Contaminants = os.path.join(host_removal_folder, "host_contaminents_seq.fasta")
copy_host = ">&2 echo Copy the host file over | "
copy_host += "cp " + self.tool_path_obj.Host + " " + Host_Contaminants
# craft a BWA index for the host sequences
bwa_hr_prep = ">&2 echo make host contaminants index for BWA | "
bwa_hr_prep += self.tool_path_obj.BWA + " index -a bwtsw " + Host_Contaminants
samtools_hr_prep = ">&2 echo SAMTOOLS host contaminant prep | "
samtools_hr_prep += self.tool_path_obj.SAMTOOLS + " faidx " + Host_Contaminants
# host removal on unique singletons
bwa_hr_singletons = ">&2 echo BWA host remove on singletons | "
bwa_hr_singletons += self.tool_path_obj.BWA + " mem -t "
bwa_hr_singletons += self.threads_str + " "
bwa_hr_singletons += Host_Contaminants + " "
bwa_hr_singletons += os.path.join(quality_folder, "singletons.fastq") + " "
bwa_hr_singletons += ">" + " "
bwa_hr_singletons += os.path.join(host_removal_folder, "singletons_no_host.sam")
#Tutorial-use only.
bwa_hr_tut_singletons = ">&2 echo BWA host remove on singletons | "
bwa_hr_tut_singletons += self.tool_path_obj.BWA + " mem -t "
bwa_hr_tut_singletons += self.threads_str + " "
bwa_hr_tut_singletons += Host_Contaminants + " "
bwa_hr_tut_singletons += self.sequence_single
bwa_hr_tut_singletons += " > " + os.path.join(host_removal_folder, "singletons_no_host.sam")
# annoying type conversion pt 1
samtools_hr_singletons_sam_to_bam = ">&2 echo convert singletons host reads | "
samtools_hr_singletons_sam_to_bam += self.tool_path_obj.SAMTOOLS
samtools_hr_singletons_sam_to_bam += " view -bS " + os.path.join(host_removal_folder, "singletons_no_host.sam")
samtools_hr_singletons_sam_to_bam += " > " + os.path.join(host_removal_folder, "singletons_no_host.bam")
# annoying type conversion pt 2
samtools_no_host_singletons_bam_to_fastq = self.tool_path_obj.SAMTOOLS + " fastq -n -f 4" + " -0 "
samtools_no_host_singletons_bam_to_fastq += os.path.join(host_removal_folder, "singletons_no_host.fastq") + " "
samtools_no_host_singletons_bam_to_fastq += os.path.join(host_removal_folder, "singletons_no_host.bam")
# apparently, we're to keep the host separation
samtools_host_singletons_bam_to_fastq = self.tool_path_obj.SAMTOOLS + " fastq -n -F 4" + " -0 "
samtools_host_singletons_bam_to_fastq += os.path.join(host_removal_folder, "singletons_host_only.fastq") + " "
samtools_host_singletons_bam_to_fastq += os.path.join(host_removal_folder, "singletons_no_host.bam")
bwa_hr_paired = ">&2 echo bwa host-removal on paired | "
bwa_hr_paired += self.tool_path_obj.BWA + " "
bwa_hr_paired += "mem" + " " + "-t" + " " + self.threads_str + " "
bwa_hr_paired += Host_Contaminants + " "
bwa_hr_paired += os.path.join(quality_folder, "pair_1.fastq") + " "
bwa_hr_paired += os.path.join(quality_folder, "pair_2.fastq") + " "
bwa_hr_paired += ">" + " "
bwa_hr_paired += os.path.join(host_removal_folder, "paired_on_host.sam")
#Tutorial-use only
bwa_hr_tut_paired = ">&2 echo bwa host-removal on paired | "
bwa_hr_tut_paired += self.tool_path_obj.BWA + " "
bwa_hr_tut_paired += "mem" + " " + "-t" + " " + self.threads_str + " "
bwa_hr_tut_paired += Host_Contaminants + " "
bwa_hr_tut_paired += self.sequence_path_1 + " "
bwa_hr_tut_paired += self.sequence_path_2 + " "
bwa_hr_tut_paired += ">" + " "
bwa_hr_tut_paired += os.path.join(host_removal_folder, "paired_on_host.sam")
bwa_hr_filter_paired = ">&2 echo BWA host-removal PP on paired | "
bwa_hr_filter_paired += self.tool_path_obj.Python + " "
bwa_hr_filter_paired += self.tool_path_obj.bwa_read_sorter + " "
bwa_hr_filter_paired += "paired" + " "
bwa_hr_filter_paired += self.tool_path_obj.filter_stringency + " "
bwa_hr_filter_paired += os.path.join(host_removal_folder, "paired_on_host.sam") + " "
bwa_hr_filter_paired += os.path.join(quality_folder, "pair_1.fastq") + " "
bwa_hr_filter_paired += os.path.join(quality_folder, "pair_2.fastq") + " "
bwa_hr_filter_paired += os.path.join(host_removal_folder, "pair_1_no_host.fastq") + " "
bwa_hr_filter_paired += os.path.join(host_removal_folder, "pair_2_no_host.fastq") + " "
bwa_hr_filter_paired += os.path.join(host_removal_folder, "pair_1_host_only.fastq") + " "
bwa_hr_filter_paired += os.path.join(host_removal_folder, "pair_2_host_only.fastq")
# blat prep
make_blast_db_host = ">&2 echo Make BLAST db for host contaminants | "
make_blast_db_host += self.tool_path_obj.Makeblastdb + " -in " + Host_Contaminants + " -dbtype nucl"
vsearch_filter_3 = ">&2 echo Convert singletons for BLAT | "
vsearch_filter_3 += self.tool_path_obj.vsearch
vsearch_filter_3 += " --fastq_filter " + os.path.join(host_removal_folder, "singletons_no_host.fastq")
vsearch_filter_3 += " --fastq_ascii " + self.Qual_str
vsearch_filter_3 += " --fastaout " + os.path.join(host_removal_folder, "singletons_no_host.fasta")
vsearch_filter_4 = ">&2 echo Convert pair 1 for BLAT | "
vsearch_filter_4 += self.tool_path_obj.vsearch
vsearch_filter_4 += " --fastq_filter " + os.path.join(host_removal_folder, "pair_1_no_host.fastq")
vsearch_filter_4 += " --fastq_ascii " + self.Qual_str
vsearch_filter_4 += " --fastaout " + os.path.join(host_removal_folder, "pair_1_no_host.fasta")
vsearch_filter_5 = ">&2 echo Convert pair 2 for BLAT | "
vsearch_filter_5 += self.tool_path_obj.vsearch
vsearch_filter_5 += " --fastq_filter " + os.path.join(host_removal_folder, "pair_2_no_host.fastq")
vsearch_filter_5 += " --fastq_ascii " + self.Qual_str
vsearch_filter_5 += " --fastaout " + os.path.join(host_removal_folder, "pair_2_no_host.fasta")
blat_hr_singletons = ">&2 echo BLAT host singletons | "
blat_hr_singletons += self.tool_path_obj.BLAT + " -noHead -minIdentity=90 -minScore=65 "
blat_hr_singletons += Host_Contaminants + " "
blat_hr_singletons += os.path.join(host_removal_folder, "singletons_no_host.fasta")
blat_hr_singletons += " -fine -q=rna -t=dna -out=blast8 -threads=" + self.threads_str
blat_hr_singletons += " " + os.path.join(host_removal_folder, "singletons_no_host.blatout")
blat_hr_pair_1 = ">&2 echo BLAT host pair 1 | "
blat_hr_pair_1 += self.tool_path_obj.BLAT
blat_hr_pair_1 += " -noHead -minIdentity=90 -minScore=65 " + Host_Contaminants + " "
blat_hr_pair_1 += os.path.join(host_removal_folder, "pair_1_no_host.fasta")
blat_hr_pair_1 += " -fine -q=rna -t=dna -out=blast8 -threads=" + self.threads_str
blat_hr_pair_1 += " " + os.path.join(host_removal_folder, "pair_1_no_host.blatout")
blat_hr_pair_2 = ">&2 echo BLAT host pair 2 | "
blat_hr_pair_2 += self.tool_path_obj.BLAT
blat_hr_pair_2 += " -noHead -minIdentity=90 -minScore=65 " + Host_Contaminants + " "
blat_hr_pair_2 += os.path.join(host_removal_folder, "pair_2_no_host.fasta")
blat_hr_pair_2 += " -fine -q=rna -t=dna -out=blast8 -threads=" + self.threads_str
blat_hr_pair_2 += " " + os.path.join(host_removal_folder, "pair_2_no_host.blatout")
# HR BLAT
hr_singletons = ">&2 echo BLAT contaminant singletons | "
hr_singletons += self.tool_path_obj.Python + " " + self.tool_path_obj.BLAT_Contaminant_Filter + " "
hr_singletons += "single" + " "
hr_singletons += self.tool_path_obj.filter_stringency + " "
hr_singletons += os.path.join(host_removal_folder, "singletons_no_host.fastq") + " " # in
hr_singletons += os.path.join(host_removal_folder, "singletons_no_host.blatout") + " " # in
hr_singletons += os.path.join(blat_hr_folder, "singletons_no_host.fastq") + " " # out
hr_singletons += os.path.join(blat_hr_folder, "singletons_host_only.fastq") # out
hr_paired = ">&2 echo BLAT contaminant paired | "
hr_paired += self.tool_path_obj.Python + " "
hr_paired += self.tool_path_obj.BLAT_Contaminant_Filter + " "
hr_paired += "paired" + " "
hr_paired += self.tool_path_obj.filter_stringency + " "
hr_paired += os.path.join(host_removal_folder, "pair_1_no_host.fastq") + " "
hr_paired += os.path.join(host_removal_folder, "pair_2_no_host.fastq") + " "
hr_paired += os.path.join(host_removal_folder, "pair_1_no_host.blatout") + " "
hr_paired += os.path.join(host_removal_folder, "pair_2_no_host.blatout") + " "
hr_paired += os.path.join(blat_hr_folder, "pair_1_no_host.fastq") + " "
hr_paired += os.path.join(blat_hr_folder, "pair_2_no_host.fastq") + " "
hr_paired += os.path.join(blat_hr_folder, "pair_1_host_only.fastq") + " "
hr_paired += os.path.join(blat_hr_folder, "pair_2_host_only.fastq")
#-----------------------------
#orphan correction
copy_singletons = "cp " + os.path.join(blat_hr_folder, "singletons_no_host.fastq") + " "
copy_singletons += os.path.join(final_folder, "singletons.fastq")
copy_pair_1 = "cp " + os.path.join(blat_hr_folder, "pair_1_no_host.fastq") + " "
copy_pair_1 += os.path.join(final_folder, "pair_1.fastq")
copy_pair_2 = "cp " + os.path.join(blat_hr_folder, "pair_2_no_host.fastq") + " "
copy_pair_2 += os.path.join(final_folder, "pair_2.fastq")
if(self.tutorial_keyword is None):
if self.read_mode == "single":
COMMANDS_host = [
copy_host,
bwa_hr_prep,
samtools_hr_prep,
bwa_hr_singletons,
samtools_hr_singletons_sam_to_bam,
samtools_no_host_singletons_bam_to_fastq,
samtools_host_singletons_bam_to_fastq,
make_blast_db_host,
vsearch_filter_3,
blat_hr_singletons,
hr_singletons,
copy_singletons
]
elif self.read_mode == "paired":
COMMANDS_host = [
copy_host,
bwa_hr_prep,
samtools_hr_prep,
bwa_hr_singletons,
samtools_hr_singletons_sam_to_bam,
samtools_no_host_singletons_bam_to_fastq,
samtools_host_singletons_bam_to_fastq,
bwa_hr_paired,
bwa_hr_filter_paired,
make_blast_db_host,
vsearch_filter_3,
vsearch_filter_4,
vsearch_filter_5,
blat_hr_singletons,
blat_hr_pair_1,
blat_hr_pair_2,
hr_singletons,
hr_paired,
copy_singletons,
copy_pair_1,
copy_pair_2
]
else:
print(dt.today(), "Host filter operating in tutorial-mode")
if self.read_mode == "single":
COMMANDS_host = [
copy_host,
bwa_hr_prep,
samtools_hr_prep,
bwa_hr_tut_singletons,
samtools_hr_singletons_sam_to_bam,
samtools_no_host_singletons_bam_to_fastq,
samtools_host_singletons_bam_to_fastq,
make_blast_db_host,
vsearch_filter_3,
blat_hr_singletons,
hr_singletons,
copy_singletons
]
elif self.read_mode == "paired":
COMMANDS_host = [
copy_host,
bwa_hr_prep,
samtools_hr_prep,
bwa_hr_tut_singletons,
samtools_hr_singletons_sam_to_bam,
samtools_no_host_singletons_bam_to_fastq,
samtools_host_singletons_bam_to_fastq,
bwa_hr_tut_paired,
bwa_hr_filter_paired,
make_blast_db_host,
vsearch_filter_3,
vsearch_filter_4,
vsearch_filter_5,
blat_hr_singletons,
blat_hr_pair_1,
blat_hr_pair_2,
hr_singletons,
hr_paired,
copy_singletons,
copy_pair_1,
copy_pair_2
]
return COMMANDS_host
def create_vector_filter_command(self, stage_name, dependency_name):
# why do we leave all the interim files intact?
# because science needs repeatable data, and the process needs to be able to start at any point
subfolder = os.path.join(self.Output_Path, stage_name)
data_folder = os.path.join(subfolder, "data")
dependency_folder = os.path.join(self.Output_Path, dependency_name, "final_results")
vector_removal_folder = os.path.join(data_folder, "0_vector_removal")
blat_containment_vector_folder = os.path.join(data_folder, "1_blat_containment_vr")
final_folder = os.path.join(subfolder, "final_results")
self.make_folder(subfolder)
self.make_folder(data_folder)
self.make_folder(vector_removal_folder)
self.make_folder(blat_containment_vector_folder)
self.make_folder(final_folder)
Vector_Contaminants = os.path.join(vector_removal_folder, "vector_contaminants_seq.fasta")
copy_vector = ">&2 echo copy vector prep | "
copy_vector += "cp " + self.tool_path_obj.UniVec_Core + " " + Vector_Contaminants
bwa_vr_prep = ">&2 echo BWA vector prep | "
bwa_vr_prep += self.tool_path_obj.BWA + " index -a bwtsw " + Vector_Contaminants
samtools_vr_prep = ">&2 echo samtools vector prep | "
samtools_vr_prep += self.tool_path_obj.SAMTOOLS + " faidx " + Vector_Contaminants
bwa_vr_singletons = ">&2 echo BWA vector oprhans | "
bwa_vr_singletons += self.tool_path_obj.BWA + " mem -t " + self.threads_str + " "
bwa_vr_singletons += Vector_Contaminants + " "
bwa_vr_singletons += os.path.join(dependency_folder, "singletons.fastq")
bwa_vr_singletons += " > " + os.path.join(vector_removal_folder, "singletons_no_vectors.sam")
bwa_vr_tut_singletons = ">&2 echo BWA vector oprhans TUTORIAL MODE | "
bwa_vr_tut_singletons += self.tool_path_obj.BWA + " mem -t " + self.threads_str + " "
bwa_vr_tut_singletons += Vector_Contaminants + " "
bwa_vr_tut_singletons += self.sequence_single
bwa_vr_tut_singletons += " > " + os.path.join(vector_removal_folder, "singletons_no_vectors.sam")
samtools_no_vector_singletons_convert = ">&2 echo samtools vector oprhans pt 1 | "
samtools_no_vector_singletons_convert += self.tool_path_obj.SAMTOOLS + " view -bS "
samtools_no_vector_singletons_convert += os.path.join(vector_removal_folder, "singletons_no_vectors.sam")
samtools_no_vector_singletons_convert += " > " + os.path.join(vector_removal_folder, "singletons_no_vectors.bam")
samtools_no_vector_singletons_export = ">&2 echo samtools vector singletons pt 2 | "
samtools_no_vector_singletons_export += self.tool_path_obj.SAMTOOLS + " fastq -n -f 4"
samtools_no_vector_singletons_export += " -0 " + os.path.join(vector_removal_folder, "singletons_no_vectors.fastq") + " "
samtools_no_vector_singletons_export += os.path.join(vector_removal_folder, "singletons_no_vectors.bam")
samtools_vector_singletons_export = ">&2 echo samtools vector singletons pt 3 | "
samtools_vector_singletons_export += self.tool_path_obj.SAMTOOLS + " fastq -n -F 4"
samtools_vector_singletons_export += " -0 " + os.path.join(vector_removal_folder, "singletons_vectors_only.fastq") + " "
samtools_vector_singletons_export += os.path.join(vector_removal_folder, "singletons_no_vectors.bam")
bwa_vr_paired = ">&2 echo bwa vector paired | "
bwa_vr_paired += self.tool_path_obj.BWA + " mem -t " + self.threads_str + " "
bwa_vr_paired += Vector_Contaminants + " "
bwa_vr_paired += os.path.join(dependency_folder, "pair_1.fastq") + " "
bwa_vr_paired += os.path.join(dependency_folder, "pair_2.fastq") + " "
bwa_vr_paired += " > " + os.path.join(vector_removal_folder, "paired_on_vectors.sam")
bwa_vr_tut_paired = ">&2 echo bwa vector paired TUTORIAL MODE | "
bwa_vr_tut_paired += self.tool_path_obj.BWA + " mem -t " + self.threads_str + " "
bwa_vr_tut_paired += Vector_Contaminants + " "
bwa_vr_tut_paired += self.sequence_path_1 + " "
bwa_vr_tut_paired += self.sequence_path_2 + " "
bwa_vr_tut_paired += " > " + os.path.join(vector_removal_folder, "paired_on_vectors.sam")
bwa_vr_filter_paired = ">&2 echo BWA vector filter on paired | "
bwa_vr_filter_paired += self.tool_path_obj.Python + " "
bwa_vr_filter_paired += self.tool_path_obj.bwa_read_sorter + " "
bwa_vr_filter_paired += "paired" + " "
bwa_vr_filter_paired += self.tool_path_obj.filter_stringency + " "
bwa_vr_filter_paired += os.path.join(vector_removal_folder, "paired_on_vectors.sam") + " "
bwa_vr_filter_paired += os.path.join(dependency_folder, "pair_1.fastq") + " "
bwa_vr_filter_paired += os.path.join(dependency_folder, "pair_2.fastq") + " "
bwa_vr_filter_paired += os.path.join(vector_removal_folder, "pair_1_no_vectors.fastq") + " "
bwa_vr_filter_paired += os.path.join(vector_removal_folder, "pair_2_no_vectors.fastq") + " "
bwa_vr_filter_paired += os.path.join(vector_removal_folder, "pair_1_vectors_only.fastq") + " "
bwa_vr_filter_paired += os.path.join(vector_removal_folder, "pair_2_vectors_only.fastq")
make_blast_db_vector = ">&2 echo BLAST make db vectors | "
make_blast_db_vector += self.tool_path_obj.Makeblastdb + " -in " + Vector_Contaminants + " -dbtype nucl"
vsearch_filter_6 = ">&2 echo convert vector singletons for BLAT | "
vsearch_filter_6 += self.tool_path_obj.vsearch
vsearch_filter_6 += " --fastq_filter " + os.path.join(vector_removal_folder, "singletons_no_vectors.fastq")
vsearch_filter_6 += " --fastq_ascii " + self.Qual_str
vsearch_filter_6 += " --fastaout " + os.path.join(vector_removal_folder, "singletons_no_vectors.fasta")
vsearch_filter_7 = ">&2 echo convert vector pair 1 for BLAT | "
vsearch_filter_7 += self.tool_path_obj.vsearch
vsearch_filter_7 += " --fastq_filter " + os.path.join(vector_removal_folder, "pair_1_no_vectors.fastq")
vsearch_filter_7 += " --fastq_ascii " + self.Qual_str
vsearch_filter_7 += " --fastaout " + os.path.join(vector_removal_folder, "pair_1_no_vectors.fasta")
vsearch_filter_8 = ">&2 echo convert vector pair 2 for BLAT | "
vsearch_filter_8 += self.tool_path_obj.vsearch
vsearch_filter_8 += " --fastq_filter " + os.path.join(vector_removal_folder, "pair_2_no_vectors.fastq")
vsearch_filter_8 += " --fastq_ascii " + self.Qual_str
vsearch_filter_8 += " --fastaout " + os.path.join(vector_removal_folder, "pair_2_no_vectors.fasta")
blat_vr_singletons = ">&2 echo BLAT vector singletons | "
blat_vr_singletons += self.tool_path_obj.BLAT
blat_vr_singletons += " -noHead -minIdentity=90 -minScore=65 "
blat_vr_singletons += Vector_Contaminants + " "
blat_vr_singletons += os.path.join(vector_removal_folder, "singletons_no_vectors.fasta")
blat_vr_singletons += " -fine -q=rna -t=dna -out=blast8 -threads=" + self.threads_str + " "
blat_vr_singletons += os.path.join(vector_removal_folder, "singletons_no_vectors.blatout")
blat_vr_pair_1 = ">&2 echo BLAT vector pair 1 | "
blat_vr_pair_1 += self.tool_path_obj.BLAT + " -noHead -minIdentity=90 -minScore=65 "
blat_vr_pair_1 += Vector_Contaminants + " "
blat_vr_pair_1 += os.path.join(vector_removal_folder, "pair_1_no_vectors.fasta")
blat_vr_pair_1 += " -fine -q=rna -t=dna -out=blast8 -threads=" + self.threads_str + " "
blat_vr_pair_1 += os.path.join(vector_removal_folder, "pair_1_no_vectors.blatout")
blat_vr_pair_2 = ">&2 echo BLAT vector pair 2 | "
blat_vr_pair_2 += self.tool_path_obj.BLAT + " -noHead -minIdentity=90 -minScore=65 "
blat_vr_pair_2 += Vector_Contaminants + " "
blat_vr_pair_2 += os.path.join(vector_removal_folder, "pair_2_no_vectors.fasta")
blat_vr_pair_2 += " -fine -q=rna -t=dna -out=blast8 -threads=" + self.threads_str + " "
blat_vr_pair_2 += os.path.join(vector_removal_folder, "pair_2_no_vectors.blatout")
blat_filter_vector_singletons = ">&2 echo BLAT contaminant singletons | "
blat_filter_vector_singletons += self.tool_path_obj.Python + " " + self.tool_path_obj.BLAT_Contaminant_Filter + " "
blat_filter_vector_singletons += "single" + " "
blat_filter_vector_singletons += self.tool_path_obj.filter_stringency + " "
blat_filter_vector_singletons += os.path.join(vector_removal_folder, "singletons_no_vectors.fastq") + " " # in
blat_filter_vector_singletons += os.path.join(vector_removal_folder, "singletons_no_vectors.blatout") + " " # in
blat_filter_vector_singletons += os.path.join(blat_containment_vector_folder, "singletons_no_vectors.fastq") + " " # out
blat_filter_vector_singletons += os.path.join(blat_containment_vector_folder, "singletons_vectors_only.fastq") # out
blat_filter_vector_paired = ">&2 echo BLAT contaminant pair 1 | "
blat_filter_vector_paired += self.tool_path_obj.Python + " " + self.tool_path_obj.BLAT_Contaminant_Filter + " "
blat_filter_vector_paired += "paired" + " "
blat_filter_vector_paired += self.tool_path_obj.filter_stringency + " "
blat_filter_vector_paired += os.path.join(vector_removal_folder, "pair_1_no_vectors.fastq") + " "
blat_filter_vector_paired += os.path.join(vector_removal_folder, "pair_2_no_vectors.fastq") + " "
blat_filter_vector_paired += os.path.join(vector_removal_folder, "pair_1_no_vectors.blatout") + " "
blat_filter_vector_paired += os.path.join(vector_removal_folder, "pair_2_no_vectors.blatout") + " "
blat_filter_vector_paired += os.path.join(blat_containment_vector_folder, "pair_1_no_vectors.fastq") + " "
blat_filter_vector_paired += os.path.join(blat_containment_vector_folder, "pair_2_no_vectors.fastq") + " "
blat_filter_vector_paired += os.path.join(blat_containment_vector_folder, "pair_1_vectors_only.fastq") + " "
blat_filter_vector_paired += os.path.join(blat_containment_vector_folder, "pair_2_vectors_only.fastq")
copy_singletons = "cp " + os.path.join(blat_containment_vector_folder, "singletons_no_vectors.fastq") + " "
copy_singletons += os.path.join(final_folder, "singletons.fastq")
copy_pair_1 = "cp " + os.path.join(blat_containment_vector_folder, "pair_1_no_vectors.fastq") + " "
copy_pair_1 += os.path.join(final_folder, "pair_1.fastq")
copy_pair_2 = "cp " + os.path.join(blat_containment_vector_folder, "pair_2_no_vectors.fastq") + " "
copy_pair_2 += os.path.join(final_folder, "pair_2.fastq")
if(self.tutorial_keyword == "vectors" or self.tutorial_keyword == "vector"):
if self.read_mode == "single":
COMMANDS_vector = [
copy_vector,
bwa_vr_prep,
samtools_vr_prep,
bwa_vr_tut_singletons,
samtools_no_vector_singletons_convert,
samtools_no_vector_singletons_export,
samtools_vector_singletons_export,
make_blast_db_vector,
vsearch_filter_6,
blat_vr_singletons,
blat_filter_vector_singletons,
copy_singletons
]
elif self.read_mode == "paired":
COMMANDS_vector = [
copy_vector,
bwa_vr_prep,
samtools_vr_prep,
bwa_vr_tut_singletons,
samtools_no_vector_singletons_convert,
samtools_no_vector_singletons_export,
samtools_vector_singletons_export,
bwa_vr_tut_paired,
bwa_vr_filter_paired,
make_blast_db_vector,
vsearch_filter_6,
vsearch_filter_7,
vsearch_filter_8,
blat_vr_singletons,
blat_vr_pair_1,
blat_vr_pair_2,
blat_filter_vector_singletons,
blat_filter_vector_paired,
copy_singletons,
copy_pair_1,
copy_pair_2
]
else:
if self.read_mode == "single":
COMMANDS_vector = [
copy_vector,
bwa_vr_prep,
samtools_vr_prep,
bwa_vr_singletons,
samtools_no_vector_singletons_convert,
samtools_no_vector_singletons_export,
samtools_vector_singletons_export,
make_blast_db_vector,
vsearch_filter_6,
blat_vr_singletons,
blat_filter_vector_singletons,
copy_singletons
]
elif self.read_mode == "paired":
COMMANDS_vector = [
copy_vector,
bwa_vr_prep,
samtools_vr_prep,
bwa_vr_singletons,
samtools_no_vector_singletons_convert,
samtools_no_vector_singletons_export,
samtools_vector_singletons_export,
bwa_vr_paired,
bwa_vr_filter_paired,
make_blast_db_vector,
vsearch_filter_6,
vsearch_filter_7,
vsearch_filter_8,
blat_vr_singletons,
blat_vr_pair_1,
blat_vr_pair_2,
blat_filter_vector_singletons,
blat_filter_vector_paired,
copy_singletons,
copy_pair_1,
copy_pair_2
]
return COMMANDS_vector
def create_rRNA_filter_prep_command_v3(self, stage_name, category, dependency_name, marker_file):
#split the data into tiny shards. called once
dep_loc = os.path.join(self.Output_Path, dependency_name, "final_results")
subfolder = os.path.join(self.Output_Path, stage_name)
data_folder = os.path.join(subfolder, "data")
jobs_folder = os.path.join(data_folder, "jobs")
self.make_folder(subfolder)
self.make_folder(data_folder)
self.make_folder(jobs_folder)
if(self.tutorial_keyword == "rRNA"):
category = "singletons"
split_folder = os.path.join(data_folder, category + "_fastq")
self.make_folder(split_folder)
split_tut_single_fastq = ">&2 echo splitting fastq for " + category + " | "
split_tut_single_fastq += self.tool_path_obj.Python + " "
split_tut_single_fastq += self.tool_path_obj.File_splitter + " "
split_tut_single_fastq += self.sequence_single + " " #os.path.join(dep_loc, category + ".fastq") + " "
split_tut_single_fastq += os.path.join(split_folder, category) + " "
split_tut_single_fastq += str(self.tool_path_obj.rRNA_chunksize)
if(self.read_mode == "paired"):
category = "pair_1"
split_folder = os.path.join(data_folder, category + "_fastq")
self.make_folder(split_folder)
split_tut_pair_1_fastq = ">&2 echo splitting fastq for " + category + " | "
split_tut_pair_1_fastq += self.tool_path_obj.Python + " "
split_tut_pair_1_fastq += self.tool_path_obj.File_splitter + " "
split_tut_pair_1_fastq += self.sequence_path_1 + " "#os.path.join(dep_loc, category + ".fastq") + " "
split_tut_pair_1_fastq += os.path.join(split_folder, category) + " "
split_tut_pair_1_fastq += str(self.tool_path_obj.rRNA_chunksize)
category = "pair_2"
split_folder = os.path.join(data_folder, category + "_fastq")
self.make_folder(split_folder)
split_tut_pair_2_fastq = ">&2 echo splitting fastq for " + category + " | "
split_tut_pair_2_fastq += self.tool_path_obj.Python + " "
split_tut_pair_2_fastq += self.tool_path_obj.File_splitter + " "
split_tut_pair_2_fastq += self.sequence_path_2 + " "#os.path.join(dep_loc, category + ".fastq") + " "
split_tut_pair_2_fastq += os.path.join(split_folder, category) + " "
split_tut_pair_2_fastq += str(self.tool_path_obj.rRNA_chunksize)
return [split_tut_single_fastq + " && " + split_tut_pair_1_fastq + " && " + split_tut_pair_2_fastq]
else:
return [split_tut_single_fastq]
else:
split_folder = os.path.join(data_folder, category + "_fastq")
self.make_folder(split_folder)
split_fastq = ">&2 echo splitting fastq for " + category + " | "
split_fastq += self.tool_path_obj.Python + " "
split_fastq += self.tool_path_obj.File_splitter + " "
split_fastq += os.path.join(dep_loc, category + ".fastq") + " "
split_fastq += os.path.join(split_folder, category) + " "
split_fastq += str(self.tool_path_obj.rRNA_chunksize)
make_marker = "touch" + " "
make_marker += os.path.join(jobs_folder, marker_file)
return [split_fastq + " && " + make_marker]
def create_rRNA_filter_convert_fastq_command(self, stage_name, category, fastq_name, marker_file):
subfolder = os.path.join(self.Output_Path, stage_name)
data_folder = os.path.join(subfolder, "data")
jobs_folder = os.path.join(data_folder, "jobs")
fasta_folder = os.path.join(data_folder, category + "_fasta")
fastq_folder = os.path.join(data_folder, category + "_fastq")
file_name = fastq_name.split(".")[0]
jobs_folder = os.path.join(data_folder, "jobs")
fastq_seqs = os.path.join(fastq_folder, fastq_name)
fasta_seqs = os.path.join(fasta_folder, file_name + ".fasta")
tut_fasta_folder = os.path.join(data_folder, "tutorial_fasta")
self.make_folder(jobs_folder)
#if(self.tutorial_keyword == "rRNA"):
# self.make_folder(tut_fasta_folder)
#else:
self.make_folder(fasta_folder)
convert_fastq_to_fasta = ">&2 echo " + " converting " + file_name + " file to fasta | "
convert_fastq_to_fasta += self.tool_path_obj.vsearch
convert_fastq_to_fasta += " --fastq_filter " + fastq_seqs
convert_fastq_to_fasta += " --fastq_ascii " + self.Qual_str
convert_fastq_to_fasta += " --fastaout " + fasta_seqs
make_marker = "touch" + " "
make_marker += os.path.join(jobs_folder, marker_file)
return [convert_fastq_to_fasta + " && " + make_marker]
def create_rRNA_filter_barrnap_arc_command(self, stage_name, category, fastq_name, marker_file):
# called by each split file
# category -> singletons, pair 1, pair 2
# file name -> the specific split section of the category (the fastq segments)
# stage_name -> "rRNA_Filter"
subfolder = os.path.join(self.Output_Path, stage_name)
data_folder = os.path.join(subfolder, "data")
jobs_folder = os.path.join(data_folder, "jobs")
fasta_folder = os.path.join(data_folder, category + "_fasta")
fastq_folder = os.path.join(data_folder, category + "_fastq")
Barrnap_out_folder = os.path.join(data_folder, category + "_barrnap")
file_name = fastq_name.split(".")[0]
Barrnap_arc_out = os.path.join(Barrnap_out_folder, file_name + "_arc.barrnap_out")
jobs_folder = os.path.join(data_folder, "jobs")
fasta_seqs = os.path.join(fasta_folder, file_name + ".fasta")
tut_fasta_folder = os.path.join(data_folder, "tutorial_fasta")
tut_Barrnap_out_folder = os.path.join(data_folder, "tutorial_barrnap")
#if(self.tutorial_keyword == "rRNA"):
# self.make_folder(tut_fasta_folder)
# self.make_folder(tut_Barrnap_out_folder)
#else:
self.make_folder(fasta_folder)