-
Notifications
You must be signed in to change notification settings - Fork 0
/
scratch.sh
1276 lines (1029 loc) · 37.6 KB
/
scratch.sh
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
cd /gpfs/commons/groups/imielinski_lab/data/FAHNSC/Flow/emerald/Emerald3/AS3T/align
outputdir=align
ok=$(ls ${outputdir}/ema-bin-* | grep -v ".bam$" | tr "\n" " ")
alignbin=""
for bin in $ok
do
{ samtools quickcheck ${bin}.bam && echo "${bin} aligned" ||
{ echo "${bin} not aligned yet" && alignbin="$alignbin $bin"; }; } 2> /dev/null
done
{ echo "bla"
echo "bloo" \
; }
get_fn_sans_ext() {
filename=$(basename -- "${1}")
extension="${filename##*.}"
filename="${filename%.*}"
# echo 'vcf_ext=${extension}'
echo ${filename}
}
fin_fn=$(get_fn_sans_ext ${OUTPUT})
test -s ${OUTPUT} && present1=true || present1=false
present2=true
if [ "$SOMATIC" = "TRUE" ]; then
{ test -s ${OUTPUT}.filtered.somatic.sv.vcf.bgz &&
test -s ${OUTPUT}.unfiltered.somatic.sv.vcf.bgz &&
test -s ${OUTPUT}.gripss.filtered.somatic.vcf &&
present2=true; } ||
present2=false;
fi
{ $present1 && $present2 && echo "All outputs present... FINISHED"; } ||
{ echo "Something went wrong... exiting" && exit 1; }
{ $present && echo "skipping IdentifyVariants"; } ||
{ echo "" && echo $cmd; } &&
{ echo "worked?" && broke=true || broke=false; } 1>> $logfile &&
echo "okok"
broke=false
present=false
if [[ $do_call == true ]] ; then
write_status "Start calling $output_vcf"
if [[ "$jobnodes" != "1" ]] ; then
write_status "Error: variant calling does not (yet) support multiple nodes for a given input file."
exit $EX_USAGE
fi
if [[ ! -f $output_vcf ]] ; then
dir=$workingdir/$(basename $output_vcf).gridss.working
prefix=$dir/$(basename $output_vcf)
mkdir -p $dir
if [[ ! -d $dir ]] ; then
write_status "Unable to create directory $dir"
exit $EX_CANTCREAT
fi
write_status "Running IdentifyVariants $output_vcf"
{ test -f $prefix.unallocated.vcf ||
test -f $prefix.allocated.vcf \
; } && present=true || present=false
cmd="$timecmd java -Xmx$jvmheap $jvm_args \
-Dgridss.output_to_temp_file=true \
-cp $gridss_jar gridss.IdentifyVariants \
TMP_DIR=$workingdir \
WORKING_DIR=$workingdir \
REFERENCE_SEQUENCE=$reference \
WORKER_THREADS=$threads \
$input_args \
$blacklist_arg \
$config_args \
ASSEMBLY=$assembly \
OUTPUT_VCF=$prefix.unallocated.vcf \
$readpairing_args"
trap 'rm $prefix.unallocated.vcf' 0 1 2 3 6 9 15
{ $present && echo "skipping IdentifyVariants"; } ||
{ echo "" && echo $cmd; } &&
{ eval $cmd && broke=true || broke=false; } 1>&2 2>> $logfile
$broke && rm $prefix.unallocated.vcf && exit 1
write_status "Running AnnotateVariants $output_vcf"
test -f $prefix.allocated.vcf &&
present=true || present=false
cmd="$timecmd java -Xmx$jvmheap $jvm_args \
-Dgridss.output_to_temp_file=true \
-Dgridss.async.buffersize=2048 \
-cp $gridss_jar gridss.AnnotateVariants \
TMP_DIR=$workingdir \
WORKING_DIR=$workingdir \
REFERENCE_SEQUENCE=$reference \
WORKER_THREADS=$threads \
$input_args \
$blacklist_arg \
$config_args \
ASSEMBLY=$assembly \
INPUT_VCF=$prefix.unallocated.vcf \
OUTPUT_VCF=$prefix.allocated.vcf \
$picardoptions \
$readpairing_args"
trap 'rm $prefix.allocated.vcf' 1 2 3 6 9 15
{ $present && echo "skipping AnnotateVariants"; } ||
{ echo "" && echo $cmd; } &&
{ eval $cmd && broke=true || broke=false; } 1>&2 2>> $logfile
$broke && rm $prefix.allocated.vcf && exit 1
# { $timecmd java -Xmx$jvmheap $jvm_args \
# -Dgridss.output_to_temp_file=true \
# -Dgridss.async.buffersize=2048 \
# -cp $gridss_jar gridss.AnnotateVariants \
# TMP_DIR=$workingdir \
# WORKING_DIR=$workingdir \
# REFERENCE_SEQUENCE=$reference \
# WORKER_THREADS=$threads \
# $input_args \
# $blacklist_arg \
# $config_args \
# ASSEMBLY=$assembly \
# INPUT_VCF=$prefix.unallocated.vcf \
# OUTPUT_VCF=$prefix.allocated.vcf \
# $picardoptions \
# $readpairing_args \
# ; } 1>&2 2>> $logfile
write_status "Running AnnotateInsertedSequence $output_vcf"
repeatmaskerbed_cmdline=""
if [[ "$repeatmaskerbed" != "" ]] ; then
repeatmaskerbed_cmdline="REPEAT_MASKER_BED=$repeatmaskerbed"
fi
trap 'rm $prefix.allocated.vcf' 1 2 3 6 9 15
cmd="$timecmd java -Xmx4g $jvm_args \
-Dgridss.output_to_temp_file=true \
-cp $gridss_jar gridss.AnnotateInsertedSequence \
TMP_DIR=$workingdir \
WORKING_DIR=$workingdir \
REFERENCE_SEQUENCE=$reference \
WORKER_THREADS=$threads \
INPUT=$prefix.allocated.vcf \
OUTPUT=$output_vcf \
$repeatmaskerbed_cmdline \
$picardoptions"
test "$externalaligner" == "true" &&
cmd="$cmd ${aligner_args_bwa}"
test -f $output_vcf && present=true || present=false
trap 'rm $output_vcf' 1 2 3 6 9 15
{ $present && echo "skipping AnnotateInsertedSequence"; } ||
{ echo "" && echo $cmd; } &&
{ eval $cmd && broke=true || broke=false; } 1>&2 2>> $logfile
$broke && rm $output_vcf && exit 1
# { $timecmd java -Xmx4g $jvm_args \
# -Dgridss.output_to_temp_file=true \
# -cp $gridss_jar gridss.AnnotateInsertedSequence \
# TMP_DIR=$workingdir \
# WORKING_DIR=$workingdir \
# REFERENCE_SEQUENCE=$reference \
# WORKER_THREADS=$threads \
# INPUT=$prefix.allocated.vcf \
# OUTPUT=$output_vcf \
# $repeatmaskerbed_cmdline \
# $picardoptions \
# && $rmcmd $prefix.allocated.vcf \
# ; } 1>&2 2>> $logfile
test -f ${output_vcf} && $rmcmd $prefix.unallocated.vcf &&
$rmcmd $prefix.allocated.vcf
else
write_status "Skipping variant calling $output_vcf"
fi
write_status "Complete calling $output_vcf"
fi
broke=false
present=false
if [[ $do_call == true ]] ; then
write_status "Start calling $output_vcf"
if [[ "$jobnodes" != "1" ]] ; then
write_status "Error: variant calling does not (yet) support multiple nodes for a given input file."
exit $EX_USAGE
fi
if [[ ! -f $output_vcf ]] ; then
dir=$workingdir/$(basename $output_vcf).gridss.working
prefix=$dir/$(basename $output_vcf)
mkdir -p $dir
if [[ ! -d $dir ]] ; then
write_status "Unable to create directory $dir"
exit $EX_CANTCREAT
fi
write_status "Running IdentifyVariants $output_vcf"
{ test -f $prefix.unallocated.vcf ||
test -f $prefix.allocated.vcf \
; } && present=true || present=false
cmd="$timecmd java -Xmx$jvmheap $jvm_args \
-Dgridss.output_to_temp_file=true \
-cp $gridss_jar gridss.IdentifyVariants \
TMP_DIR=$workingdir \
WORKING_DIR=$workingdir \
REFERENCE_SEQUENCE=$reference \
WORKER_THREADS=$threads \
$input_args \
$blacklist_arg \
$config_args \
ASSEMBLY=$assembly \
OUTPUT_VCF=$prefix.unallocated.vcf \
$readpairing_args"
trap 'rm $prefix.unallocated.vcf' 1 2 3 6 9 15
{ $present && echo "skipping IdentifyVariants"; } ||
{ echo "" && echo $cmd; } &&
{ eval $cmd && broke=false || broke=true; } 1>&2 2>> $logfile
$broke && rm $prefix.unallocated.vcf && exit 1
write_status "Running AnnotateVariants $output_vcf"
test -f $prefix.allocated.vcf &&
present=true || present=false
cmd="$timecmd java -Xmx$jvmheap $jvm_args \
-Dgridss.output_to_temp_file=true \
-Dgridss.async.buffersize=2048 \
-cp $gridss_jar gridss.AnnotateVariants \
TMP_DIR=$workingdir \
WORKING_DIR=$workingdir \
REFERENCE_SEQUENCE=$reference \
WORKER_THREADS=$threads \
$input_args \
$blacklist_arg \
$config_args \
ASSEMBLY=$assembly \
INPUT_VCF=$prefix.unallocated.vcf \
OUTPUT_VCF=$prefix.allocated.vcf \
$picardoptions \
$readpairing_args"
trap 'rm $prefix.allocated.vcf' 1 2 3 6 9 15
{ $present && echo "skipping AnnotateVariants"; } ||
{ echo "" && echo $cmd; } &&
{ eval $cmd && broke=false || broke=true; } 1>&2 2>> $logfile
$broke && rm $prefix.allocated.vcf && exit 1
write_status "Running AnnotateInsertedSequence $output_vcf"
repeatmaskerbed_cmdline=""
if [[ "$repeatmaskerbed" != "" ]] ; then
repeatmaskerbed_cmdline="REPEAT_MASKER_BED=$repeatmaskerbed"
fi
trap 'rm $prefix.allocated.vcf' 1 2 3 6 9 15
cmd="$timecmd java -Xmx4g $jvm_args \
-Dgridss.output_to_temp_file=true \
-cp $gridss_jar gridss.AnnotateInsertedSequence \
TMP_DIR=$workingdir \
WORKING_DIR=$workingdir \
REFERENCE_SEQUENCE=$reference \
WORKER_THREADS=$threads \
INPUT=$prefix.allocated.vcf \
OUTPUT=$output_vcf \
$repeatmaskerbed_cmdline \
$picardoptions"
test "$externalaligner" == "true" &&
cmd="$cmd ${aligner_args_bwa}"
test -f $output_vcf && present=true || present=false
trap 'rm $output_vcf' 1 2 3 6 9 15
{ $present && echo "skipping AnnotateInsertedSequence"; } ||
{ echo "" && echo $cmd; } &&
{ eval $cmd && broke=false || broke=true; } 1>&2 2>> $logfile
$broke && rm $output_vcf && exit 1
test -f ${output_vcf} && $rmcmd $prefix.unallocated.vcf &&
$rmcmd $prefix.allocated.vcf
else
write_status "Skipping variant calling $output_vcf"
fi
write_status "Complete calling $output_vcf"
fi
refdir
mkdir -p tmpref
str="Copyng reference to temporary directory"
test ! -f tmpref/$(basename ${REFERENCE}) && echo "copying ${REFERENCE} to ./tmpref/" && cp tmpref/$(basename ${REFERENCE}) tmpref/
test ! -f tmpref/$(basename ${REFERENCE}).fai && echo "copying ${REFERENCE.fai} to ./tmpref/" && cp tmpref/$(basename ${REFERENCE}).fai tmpref/
test ! -f tmpref/$(basename ${REFERENCE}).bwt && "copying ${REFERENCE.bwt} to ./tmpref/" && cp tmpref/$(basename ${REFERENCE}).bwt tmpref/
{ test ! -f tmpref/$(basename ${REFERENCE}).img && "copying ${REFERENCE.img} to ./tmpref/" && cp tmpref/$(basename ${REFERENCE}).bwt tmpref/ ; } || { echo "img not found" && echo "please run "; }
jvm_args="-Dgridss.keepTempFiles=true"
jvm_args="$jvm_args \
-Dreference_fasta=$REFERENCE \
-Dsamjdk.use_async_io_read_samtools=true \
-Dsamjdk.use_async_io_write_samtools=true \
-Dsamjdk.use_async_io_write_tribble=true \
-Dsamjdk.buffer_size=4194304"
"java -Xmx4g $jvm_args \
-cp $GRIDSS_JAR gridss.PrepareReference \
REFERENCE_SEQUENCE=$REFERENCE"
REFERENCE="./tmpref/$(basename ${REFERENCE})"
{ $present1 && $present2 &&
echo "Successfully called, removing temporary files" &&
rm *.bam &&
rm -rf *.working &&
rm -rf tmpref/*
echo "All outputs present... FINISHED" \
; } ||
{ echo "Something went wrong... exiting" && exit 1; }
export cmd="{ echo \"bla\" && echo \"blap\"; }";
/usr/bin/time -p sh -c 'echo "$(date): $cmd" && eval $cmd'
write_status "Running CollectGridssMetricsAndExtractSVReads|samtools $f"
cmd="$timecmd java -Xmx4g $jvm_args \
-cp $gridss_jar gridss.CollectGridssMetricsAndExtractSVReads \
TMP_DIR=$dir \
ASSUME_SORTED=true \
I=$f \
O=$prefix \
THRESHOLD_COVERAGE=$maxcoverage \
FILE_EXTENSION=null \
GRIDSS_PROGRAM=null \
GRIDSS_PROGRAM=CollectCigarMetrics \
GRIDSS_PROGRAM=CollectMapqMetrics \
GRIDSS_PROGRAM=CollectTagMetrics \
GRIDSS_PROGRAM=CollectIdsvMetrics \
GRIDSS_PROGRAM=ReportThresholdCoverage \
PROGRAM=null \
PROGRAM=CollectInsertSizeMetrics \
SV_OUTPUT=/dev/stdout \
COMPRESSION_LEVEL=0 \
METRICS_OUTPUT=$prefix.sv_metrics \
INSERT_SIZE_METRICS=$tmp_prefix.insert_size_metrics \
$readpairing_args \
UNMAPPED_READS=false \
MIN_CLIP_LENGTH=5 \
INCLUDE_DUPLICATES=true \
$picardoptions \
| $timecmd samtools sort \
-n \
-T $tmp_prefix.namedsorted-tmp \
-Obam \
-o $tmp_prefix.namedsorted.bam \
-@ $threads \
/dev/stdin"
{ $timecmd java -Xmx4g $jvm_args \
-cp $gridss_jar gridss.CollectGridssMetricsAndExtractSVReads \
TMP_DIR=$dir \
ASSUME_SORTED=true \
I=$f \
O=$prefix \
THRESHOLD_COVERAGE=$maxcoverage \
FILE_EXTENSION=null \
GRIDSS_PROGRAM=null \
GRIDSS_PROGRAM=CollectCigarMetrics \
GRIDSS_PROGRAM=CollectMapqMetrics \
GRIDSS_PROGRAM=CollectTagMetrics \
GRIDSS_PROGRAM=CollectIdsvMetrics \
GRIDSS_PROGRAM=ReportThresholdCoverage \
PROGRAM=null \
PROGRAM=CollectInsertSizeMetrics \
SV_OUTPUT=/dev/stdout \
COMPRESSION_LEVEL=0 \
METRICS_OUTPUT=$prefix.sv_metrics \
INSERT_SIZE_METRICS=$tmp_prefix.insert_size_metrics \
$readpairing_args \
UNMAPPED_READS=false \
MIN_CLIP_LENGTH=5 \
INCLUDE_DUPLICATES=true \
$picardoptions \
| $timecmd samtools sort \
-n \
-T $tmp_prefix.namedsorted-tmp \
-Obam \
-o $tmp_prefix.namedsorted.bam \
-@ $threads \
/dev/stdin \
; } 1>&2 2>> $logfile
REFERENCE=/gpfs/commons/groups/imielinski_lab/DB/GATK/human_g1k_v37_with_chr.fasta
REFERENCE="bla"
blacklist="$( cat ~/DB/modules/GRIDSS/gridss_ref_blacklist.txt | \
awk -v var=$(readlink -f $REFERENCE) '$1 == var {print $2}' | xargs -I {} readlink -f {})"
ent="$( cat ~/DB/modules/GRIDSS/gridss_ref_blacklist.txt | \
awk -v var=$(readlink -f $REFERENCE) '$1 == var')"
echo "$ent" | awk '{print $1}'
cat ${REFERENCE}.fai | awk '{print $1}' | uniq > rname
cat ${BLACKLIST} | awk '{print $1}' | uniq > bname
allbninrn=$(Rscript -e "cat(tolower(all(readLines('bname') %in% readLines('rname'))))")
# test "$(cat ${REFERENCE}.fai | awk '{print $1}' | uniq)" == "$(cat ${BLACKLIST} | awk '{print $1}' | uniq)" && echo "ok"
# test "$(cat ${REFERENCE}.fai | awk '{print $1}' | uniq | xargs | sort)" == "$(cat ${BLACKLIST} | awk '{print $1}' | uniq | xargs | sort)" && echo "ok"
# $(readlink -f ~/DB/GATK/human_g1k_v37_with_chr.fasta)
# REFERENCE="
# "~/DB/modules/GRIDSS/gridss_ref_blacklist.txt"
for bam in *.bam; do
echo $(readlink -f $bam)
samtools view -H $bam | grep "SN" | awk '{gsub(/^SN:|^ID:/, "", $2); print $2}' > bamrn
bammatch=$(Rscript -e "cat(tolower(all(readLines('bamrn') == readLines('rname'))))")
$bammatch && echo "Passed: $bam: matches ${REFERENCE}" || {
echo "Failed comparison" &&
echo "Comparison of the reference name and bamname:" &&
echo -e "${REFERENCE}\t$(readlink -f ${bam})" &&
echo -e "${REFERENCE}\t$(readlink -f ${bam})" > ./$(basename ${bam})_ref_mismatch
paste bamrn rname >> ./$(basename ${bam})_ref_mismatch \
; }
done
samtools view -H ctK*.bam | grep "SN" | awk '{gsub(/^SN:|^ID:/, "", $2); print $2}'
samtools view -H $bam | awk '$2 ~ /^SN/ {print $0}' | awk '{gsub(/^SN:|^ID:/, "", $2); print $2}' > bamrn
lftp ftp.ncbi.nih.gov:/genomes/genbank/vertebrate_mammalian/Homo_sapiens
echo -e "bla foobar\nbla" | sed "s/ \t\r\n,:|/ /g" | xargs
if ! { echo $cmd && fuck; }; then echo "samtools flagstat broke"; exit 1; fi
Rscript $@
## if ^^ breaks, then $? will be non-zero
[ ! "$?" == "0" ] && { echo "HRDetect failed"; exit 1; }
if ! { bcftools view $output_vcf 1> /dev/null; }; then
if ! { echo "$(date): ${cmd}" && eval $cmd; }; then
rm -rf $output_vcf; exit 1;
fi
else
write_status "skipping AnnotateInsertedSequence"
fi
bcftools view $prefix.unallocated.vcf 1> /dev/null && idvdone=true || idvdone=false
bcftools view $prefix.allocated.vcf 1> /dev/null && anvdone=true || anvdone=false
if ! ${idvdone}; then
if ! { echo "$(date): ${cmd}" && eval $cmd; }; then
rm -rf $prefix.unallocated.vcf; echo "IdentifyVariants broke!"; exit 1;
fi
else
echo "skipping IdentifyVariants"
fi
if ! ${anvdone}; then
if ! { echo "$(date): ${cmd}" && eval $cmd; }; then
rm -rf $prefix.allocated.vcf; echo "AnnotateVariants broke!"; exit 1;
fi
else
echo "skipping AnnotateVariants"
fi
if ! { $present || $present2; }; then
cmd="${lib_dir}/bwa mem -M -R \"@RG\tID:${laneid}\tSM:${sampleName}\tPL:ILLUMINA\" -t $NSLOTS ${ref_fasta} ${fq1} ${fq2} | ${lib_dir}/samblaster -M -i /dev/stdin | samtools sort -T ${tmpdir} -@ $sortthread -O bam -l 0 -m ${sortmem}G -o ${tmpName}.aligned_bwa_markdups.bam -"
if { echo -e "Running alignment, mark dup, sorting:\n$cmd" && eval $cmd; }; then
echo "Finished alignment!"
else
echo "ERROR!! Broke at bwa mem alignment!"; exit 1
fi
else
echo "Alignment output already present for ID: ${laneid}, SM: ${sampleName}"
fi
cp -r ~/lab/git/mskilab/gTrack/. ./
git clone ~/lab/git/mskilab/gTrack/. ./
for remote in `git branch -r | grep -v \> | xargs`; do git branch --track ${remote#origin/} $remote; done
git branch -r | grep -v '\->' | while read remote; do git branch --track ${remote#origin/} $remote; done
git remote set-url origin [email protected]:mskilab/gTrack.git
git remote set-url origin https://github.com/mskilab/gTrack.git
cmd='$timecmd java -Xmx4g $jvm_args \
-cp $gridss_jar gridss.CollectGridssMetricsAndExtractSVReads \
TMP_DIR=$dir \
ASSUME_SORTED=true \
I=$f \
O=$prefix \
THRESHOLD_COVERAGE=$maxcoverage \
FILE_EXTENSION=null \
GRIDSS_PROGRAM=null \
GRIDSS_PROGRAM=CollectCigarMetrics \
GRIDSS_PROGRAM=CollectMapqMetrics \
GRIDSS_PROGRAM=CollectTagMetrics \
GRIDSS_PROGRAM=CollectIdsvMetrics \
GRIDSS_PROGRAM=ReportThresholdCoverage \
PROGRAM=null \
PROGRAM=CollectInsertSizeMetrics \
SV_OUTPUT=/dev/stdout \
COMPRESSION_LEVEL=0 \
METRICS_OUTPUT=$prefix.sv_metrics \
INSERT_SIZE_METRICS=$tmp_prefix.insert_size_metrics \
$readpairing_args \
UNMAPPED_READS=false \
MIN_CLIP_LENGTH=5 \
INCLUDE_DUPLICATES=true \
$picardoptions \
\| $timecmd samtools sort \
-n \
-T $tmp_prefix.namedsorted-tmp \
-Obam \
-o $tmp_prefix.namedsorted.bam \
-@ $threads \
/dev/stdin'
tmpdir=""
tmpdir="/nfs/"
maketmpdir='if [ "$tmpdir" ]; then TMP_DIR=$tmpdir; echo "making TMP_DIR=$tmpdir"; else TMP_DIR=$dir; echo "making TMP_DIR=$dir"; fi'
maketmpdir='if [ "$tmpdir" ]; then TMP_DIR=$tmpdir; write_status "making TMP_DIR=$tmpdir"; else TMP_DIR=$dir; write_status "making TMP_DIR=$dir"; fi'
eval $maketmpdir
# eval echo $maketmpdir
cmd='$timecmd java -Xmx4g $jvm_args
-cp $gridss_jar gridss.CollectGridssMetricsAndExtractSVReads
TMP_DIR=$dir
ASSUME_SORTED=true
I=$f
O=$prefix
THRESHOLD_COVERAGE=$maxcoverage
FILE_EXTENSION=null
GRIDSS_PROGRAM=null
GRIDSS_PROGRAM=CollectCigarMetrics
GRIDSS_PROGRAM=CollectMapqMetrics
GRIDSS_PROGRAM=CollectTagMetrics
GRIDSS_PROGRAM=CollectIdsvMetrics
GRIDSS_PROGRAM=ReportThresholdCoverage
PROGRAM=null
PROGRAM=CollectInsertSizeMetrics
SV_OUTPUT=/dev/stdout
COMPRESSION_LEVEL=0
METRICS_OUTPUT=$prefix.sv_metrics
INSERT_SIZE_METRICS=$tmp_prefix.insert_size_metrics
$readpairing_args
UNMAPPED_READS=false
MIN_CLIP_LENGTH=5
INCLUDE_DUPLICATES=true
$picardoptions \| samtools view'
eval echo $cmd | xargs
bla=$(echo $cmd | xargs | xargs)
cmd='echo "$bla"'
export cmd='for accession in 1 2 3 4 5; do
sh ~/dummy.sh $accession foo;
done'
ok="$(echo "$bla") $(echo 'TMP_DIR=$dir')"
blip="fii"
ok='\{ echo \ "$blip foob" \| sed "s/i/o/g"\; echo "finish"\; \}'
echo $cmd
echo "$cmd"
eval echo $cmd
eval echo "$cmd"
eval "echo '$cmd'"
eval "echo $cmd | xargs | xargs"
eval "$(echo $cmd | xargs | xargs)"
tmpdir=""
tmpdir="/nfs/scratch"
maketmpdir='if [ "$tmpdir" ]\; then TMP_DIR=$tmpdir\; echo "making TMP_DIR=$tmpdir"\; else TMP_DIR=$dir\; echo "making TMP_DIR=$dir"\; fi'
wdir=""
wdir="/nfs/scratch"
makewdir='if [ "$tmpdir" ]\; then TMP_DIR=$tmpdir\; echo "making TMP_DIR=$tmpdir"\; else TMP_DIR=$dir\; echo "making TMP_DIR=$dir"\; fi'
eval "parse $maketmpdir"
eval "$(parse $maketmpdir)"
eval "echo $maketmpdir"
eval eval "$(echo $maketmpdir)"
maketmpdir='if [ "$tmpdir" ]; then TMP_DIR=$tmpdir; else TMP_DIR=$dir; fi'
blip="fii"
ok='{ echo \ "$blip foob" \| sed "s/i/o/g"\; echo "finish"\; \}'
ok='echo \ "$blip foob" \| sed "s/i/o/g"\; echo "finish"'
parse() {
echo "$@" | xargs | xargs
}
# eval parse "$ok"
# eval "$(parse \"$ok\")"
# eval $(parse "$ok")
eval "parse $ok"
eval "$(parse $ok)"
eval "echo $ok | xargs | xargs"
## executes
eval "$(echo $ok | xargs | xargs)"
collectgridssmetrics='{ $timecmd java -Xmx4g $jvm_args \
-cp $gridss_jar gridss.analysis.CollectGridssMetrics \
TMP_DIR=$dir \
ASSUME_SORTED=true \
I=$f \
O=$tmp_prefix \
THRESHOLD_COVERAGE=$maxcoverage \
FILE_EXTENSION=null \
GRIDSS_PROGRAM=null \
PROGRAM=null \
PROGRAM=CollectInsertSizeMetrics \
STOP_AFTER=$metricsrecords \
$picardoptions \
\; \} 1\>\&2 2\>\> $logfile'
eval "parse $collectgridssmetrics"
eval "$(parse $collectgridssmetrics)"
computesamtags='{ $timecmd java -Xmx4g $jvm_args \
-cp $gridss_jar gridss.ComputeSamTags \
TMP_DIR=$dir \
WORKING_DIR=$workingdir \
REFERENCE_SEQUENCE=$reference \
COMPRESSION_LEVEL=0 \
I=$tmp_prefix.namedsorted.bam \
O=/dev/stdout \
RECALCULATE_SA_SUPPLEMENTARY=true \
SOFTEN_HARD_CLIPS=true \
FIX_MATE_INFORMATION=true \
FIX_DUPLICATE_FLAG=true \
FIX_SA=true \
FIX_MISSING_HARD_CLIP=true \
TAGS=null \
TAGS=NM \
TAGS=SA \
TAGS=R2 \
TAGS=Q2 \
TAGS=MC \
TAGS=MQ \
ASSUME_SORTED=true \
$picardoptions \
\| $timecmd samtools sort \
-T $tmp_prefix.coordinate-tmp \
-Obam \
-o $tmp_prefix.coordinate.bam \
-@ $threads \
/dev/stdin \
\; \} 1\>\&2 2\>\> $logfile\'
eval "parse $computesamtags"
eval "$(parse $computesamtags)"
softcliptstosplitreads='{ $timecmd java -Xmx4g $jvm_args \
-Dsamjdk.create_index=false \
-cp $gridss_jar gridss.SoftClipsToSplitReads \
TMP_DIR=$workingdir \
WORKING_DIR=$workingdir \
REFERENCE_SEQUENCE=$reference \
I=$tmp_prefix.coordinate.bam \
O=$tmp_prefix.sc2sr.primary.sv.bam \
OUTPUT_UNORDERED_RECORDS=$tmp_prefix.sc2sr.supp.sv.bam \
WORKER_THREADS=$threads \
$picardoptions \
\&\& $rmcmd $tmp_prefix.coordinate.bam \
\&\& $timecmd samtools sort \
-@ $threads \
-T $tmp_prefix.sc2sr.suppsorted.sv-tmp \
-Obam \
-o $tmp_prefix.sc2sr.suppsorted.sv.bam \
$tmp_prefix.sc2sr.supp.sv.bam \
\&\& $rmcmd $tmp_prefix.sc2sr.supp.sv.bam \
\&\& $timecmd samtools merge \
-@ $threads \
$prefix.sv.tmp.bam \
$tmp_prefix.sc2sr.primary.sv.bam \
$tmp_prefix.sc2sr.suppsorted.sv.bam \
\&\& $timecmd samtools index $prefix.sv.tmp.bam \
\&\& $rmcmd $tmp_prefix.sc2sr.primary.sv.bam \
\&\& $rmcmd $tmp_prefix.sc2sr.suppsorted.sv.bam \
\&\& mv $prefix.sv.tmp.bam $prefix.sv.bam \
\&\& mv $prefix.sv.tmp.bam.bai $prefix.sv.bam.bai \
\; \} 1\>\&2 2\>\> $logfile\'
eval "parse $softcliptstosplitreads"
eval "$(parse $softcliptstosplitreads)"
preprocessforbreakendassembly='{ $timecmd java -Xmx4g $jvm_args \
-cp $gridss_jar gridss.PreprocessForBreakendAssembly \
TMP_DIR=$dir \
WORKING_DIR=$workingdir \
REFERENCE_SEQUENCE=$reference \
COMPRESSION_LEVEL=0 \
I=$tmp_prefix.namedsorted.bam \
O=/dev/stdout \
WORKER_THREADS=$threads \
ALIGNER=BWAMEM \
ALIGNER_BATCH_SIZE=10000 \
$picardoptions \
\| $timecmd samtools sort \
-@ $threads \
-T $tmp_prefix.sc2sr.suppsorted.sv-tmp \
-Obam \
-o $prefix.sv.tmp.bam \
/dev/stdin \
\&\& $rmcmd $tmp_prefix.namedsorted.bam \
\&\& $timecmd samtools index $prefix.sv.tmp.bam \
\&\& mv $prefix.sv.tmp.bam $prefix.sv.bam \
\&\& mv $prefix.sv.tmp.bam.bai $prefix.sv.bam.bai \
\; \} 1\>\&2 2\>\> $logfile\'
eval "parse $preprocessforbreakendassembly"
eval "$(parse $preprocessforbreakendassembly)"
sanitycheckevidence='java -Xmx$jvmheap $jvm_args \
-cp $gridss_jar gridss.SanityCheckEvidence \
TMP_DIR=$workingdir \
WORKING_DIR=$workingdir \
REFERENCE_SEQUENCE=$reference \
WORKER_THREADS=$threads \
$input_args \
$blacklist_arg \
$config_args \
ASSEMBLY=ignored \
OUTPUT_ERROR_READ_NAMES=reads_failing_sanity_check.txt \
1\>\&2 2\>\> $logfile\'
eval "parse $sanitycheckevidence"
eval "$(parse $preprocessforbreakendassembly)"
assemblebreakends='{ $timecmd java -Xmx$jvmheap $jvm_args \
-Dgridss.output_to_temp_file=true \
-cp $gridss_jar gridss.AssembleBreakends \
JOB_INDEX=$jobindex \
JOB_NODES=$jobnodes \
TMP_DIR=$workingdir \
WORKING_DIR=$workingdir \
REFERENCE_SEQUENCE=$reference \
WORKER_THREADS=$threads \
O=$assembly \
$input_args \
$blacklist_arg \
$config_args \
$picardoptions \
$readpairing_args \
\; \} 1\>\&2 2\>\> $logfile\'
eval "parse $assemblebreakends"
eval "$(parse $assemblebreakends)"
collectgridssmetrics2='{ $timecmd java -Xmx4g $jvm_args \
-cp $gridss_jar gridss.analysis.CollectGridssMetrics \
I=$assembly \
O=$prefix \
REFERENCE_SEQUENCE=$reference \
THRESHOLD_COVERAGE=$maxcoverage \
TMP_DIR=$workingdir \
FILE_EXTENSION=null \
GRIDSS_PROGRAM=null \
GRIDSS_PROGRAM=CollectCigarMetrics \
GRIDSS_PROGRAM=CollectMapqMetrics \
GRIDSS_PROGRAM=CollectTagMetrics \
GRIDSS_PROGRAM=CollectIdsvMetrics \
GRIDSS_PROGRAM=ReportThresholdCoverage \
PROGRAM=null \
PROGRAM=QualityScoreDistribution \
$picardoptions \
\; \} 1\>\&2 2\>\> $logfile\'
eval "parse $collectgridssmetrics2"
eval "$(parse $collectgridssmetrics2)"
softcliptstosplitreads2='{ $timecmd java -Xmx4g $jvm_args \
-Dgridss.async.buffersize=16 \
-Dsamjdk.create_index=false \
-Dgridss.output_to_temp_file=true \
-cp $gridss_jar gridss.SoftClipsToSplitReads \
TMP_DIR=$dir \
WORKING_DIR=$workingdir \
REFERENCE_SEQUENCE=$reference \
WORKER_THREADS=$threads \
I=$assembly \
O=$tmp_prefix.sc2sr.primary.sv.bam \
OUTPUT_UNORDERED_RECORDS=$tmp_prefix.sc2sr.supp.sv.bam \
REALIGN_ENTIRE_READ=true \
READJUST_PRIMARY_ALIGNMENT_POSITION=true \
$aligner_args_bwa \
$picardoptions \
\&\& $timecmd samtools sort \
-@ $threads \
-T $tmp_prefix.sc2sr.suppsorted.sv-tmp \
-Obam \
-o $tmp_prefix.sc2sr.suppsorted.sv.bam \
$tmp_prefix.sc2sr.supp.sv.bam \
\&\& $rmcmd $tmp_prefix.sc2sr.supp.sv.bam \
\&\& $timecmd samtools merge \
-@ $threads \
$prefix.sv.tmp.bam \
$tmp_prefix.sc2sr.primary.sv.bam \
$tmp_prefix.sc2sr.suppsorted.sv.bam \
\&\& $timecmd samtools index $prefix.sv.tmp.bam \
\&\& $rmcmd $tmp_prefix.sc2sr.primary.sv.bam \
\&\& $rmcmd $tmp_prefix.sc2sr.suppsorted.sv.bam \
\&\& mv $prefix.sv.tmp.bam $prefix.sv.bam \
\&\& mv $prefix.sv.tmp.bam.bai $prefix.sv.bam.bai \
\; \} 1\>\&2 2\>\> $logfile\'
eval "parse $softcliptstosplitreads2"
eval "$(parse $softcliptstosplitreads2)"
softcliptstosplitreads2_int='{ $timecmd java -Xmx4g $jvm_args \
-Dgridss.async.buffersize=16 \
-Dsamjdk.create_index=false \
-cp $gridss_jar gridss.SoftClipsToSplitReads \
TMP_DIR=$dir \
WORKING_DIR=$workingdir \
REFERENCE_SEQUENCE=$reference \
WORKER_THREADS=$threads \
I=$assembly \
O=/dev/stdout \
ALIGNER=BWAMEM \
ALIGNER_BATCH_SIZE=100000 \
REALIGN_ENTIRE_READ=true \
READJUST_PRIMARY_ALIGNMENT_POSITION=true \
COMPRESSION_LEVEL=0 \
$picardoptions \
\| $timecmd samtools sort \
-@ $threads \
-T $tmp_prefix.sc2sr.suppsorted.sv-tmp \
-Obam \
-o $prefix.sv.tmp.bam \
/dev/stdin \
\&\& $timecmd samtools index $prefix.sv.tmp.bam \
\&\& mv $prefix.sv.tmp.bam $prefix.sv.bam \
\&\& mv $prefix.sv.tmp.bam.bai $prefix.sv.bam.bai \
\; \} 1\>\&2 2\>\> $logfile\'
eval "parse $softcliptstosplitreads2_int"
eval "$(parse $softcliptstosplitreads2_int)"
sanitycheckbyevidence2='java -Xmx$jvmheap $jvm_args \
-cp $gridss_jar gridss.SanityCheckEvidence \
TMP_DIR=$workingdir \
WORKING_DIR=$workingdir \
REFERENCE_SEQUENCE=$reference \
WORKER_THREADS=$threads \
$input_args \
$blacklist_arg \
$config_args \
ASSEMBLY=$assembly \
$readpairing_args \
OUTPUT_ERROR_READ_NAMES=reads_failing_sanity_check.txt\'
eval "parse $sanitycheckbyevidence2"
eval "$(parse $sanitycheckbyevidence2)"
eval "echo $sanitycheckbyevidence2"
eval eval "$(echo $sanitycheckbyevidence2)"
identifyvariants='$timecmd java -Xmx$jvmheap $jvm_args \
-Dgridss.output_to_temp_file=true \
-cp $gridss_jar gridss.IdentifyVariants \
TMP_DIR=$workingdir \
WORKING_DIR=$workingdir \
REFERENCE_SEQUENCE=$reference \
WORKER_THREADS=$threads \
$input_args \
$blacklist_arg \
$config_args \
ASSEMBLY=$assembly \
OUTPUT_VCF=$prefix.unallocated.vcf \
$readpairing_args'
eval "echo $identifyvariants"
eval eval "$(echo $ok)"
##########
##########
########## Look here!
##########
##########
blip="fii"
ok='{ echo \ "$blip foob" \| sed "s/i/o/g"\; echo "finish"\; \}'
parse() {
echo "$@" | xargs | xargs
}
# eval parse "$ok"
# eval "$(parse \"$ok\")"
# eval $(parse "$ok")
eval "parse $ok"
eval "$(parse $ok)"
eval "echo $ok"
eval eval "$(echo $ok)"
eval echo "$ok" # this is it
eval eval "$ok" # this is it
##########
##########
########## Look here!
##########
##########
# echo "Matching provided reference against known library of blacklists"
# ## using reference blacklist lookup to match up reference
# ent=$( cat ${RB_LOOKUP} | \
# awk -v var=$(readlink -f $REFERENCE) '$1 == var' | xargs)
# matchbl=$(echo "$ent" | awk '{print $2}' | xargs -I {} readlink -f {})
# matchpon=$(echo "$ent" | awk '{print $3}' | xargs -I {} readlink -f {})
# ## default blacklist
# # "/gpfs/commons/groups/imielinski_lab/DB/GRIDSS/core.svaba.blacklist.bed"
# if [ "$ent" ]; then
# echo "Reference match found"
# test "$matchbl" == "$BLACKLIST" && echo "provided blacklist good to go"
# if [ ! "$BLACKLIST" == "$matchbl" ]; then
# echo "Blacklist provided (path: $BLACKLIST) does not match known working file"
# echo "replacing with good match: ${matchbl}"
# BLACKLIST=${matchbl}
# fi
# test "$matchpon" == "$PONDIR" && echo "provided PON directory good to go"
# if [ ! "$PONDIR" == "$matchpon" ]; then
# echo "PON provided (path: $PONDIR) does not match known working file"
# echo "replacing with good match: ${matchpon}"
# PONDIR=${matchpon}
# fi
# else
# { test ! -e "$BLACKLIST" || test "$BLACKLIST" == "/dev/null"; } &&
# echo "Blacklist file ($BLACKLIST) not valid" &&
# BLACKLIST="${LIBDIR}/core.svaba.blacklist.bed" &&
# echo "Replacing with default, $BLACKLIST"
# echo "Reference not found in reference fasta/blacklist dictionary..."
# echo -e \
# "\nWARNING: GRIDSS requires the blacklist must not contain non-matching seqnames to ref"
# { test ! -e "$PONDIR" || test "$PONDIR" == "/dev/null"; } &&
# echo "PONDIR file ($PONDIR) not valid" &&
# PONDIR="" &&
# echo "Not using PON!"
# echo "PON directory (${PONDIR}) not found in reference fasta/PON dictionary..."
# echo -e \
# "\nWARNING: GRIDSS requires the pon must not contain non-matching seqnames to ref, i.e. chr vs no chr"
# fi
# cat ${REFERENCE}.fai | awk '{print $1}' | uniq > rname
# cat ${BLACKLIST} | awk '{print $1}' | uniq > bname
# allbninrn=$(Rscript -e "cat(tolower(all(readLines('bname') %in% readLines('rname'))))")
# bnnotinrn=$(Rscript -e "cat({bn = readLines('bname'); bn[!bn %in% readLines('rname')]})")
# $allbninrn && echo "Passed: all seqnames in ${BLACKLIST} are in ${REFERENCE}.fai" ||
# { echo "ERROR!! Found $blacklist contains seqnames not within ${REFERENCE}.fai" &&
# echo "GRIDSS will break... rewriting blacklist without offending seqnames to file:" &&
# echo "fixed_blacklist.bed"
# awk -v var="$bnnotinrn" 'BEGIN{split(var,t); for (i in t) vals[t[i]]} !($1 in vals)' \
# $BLACKLIST > fixed_blacklist.bed &&
# BLACKLIST="fixed_blacklist.bed" &&
# echo "now using ./fixed_blacklist.bed" \
# ; }
WDIR2=""
if [ -s "wdir" ]; then
WDIR2=$(cat wdir)
fi
if [ ! "$WDIR" = "." ]; then
if [ ! -s "$WDIR2" ]; then
test ! -s "$WDIR" && test -s "/scratch" && WDIR="/scratch" ||
WDIR="."
WDIR="$WDIR/$(basename $(readlink -f .))_$$"
echo $WDIR > wdir
else