-
Notifications
You must be signed in to change notification settings - Fork 1
/
Leucippus.java
15918 lines (14403 loc) · 540 KB
/
Leucippus.java
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
/** Description of Leucippus
* @author 1: Alexej Abyzov
* @author 2: Nikolaos Vasmatzis
* @authors 3: Others
* @version 1.0 Build 08/06/2015.
* Description : Software for Noise Estimation
*/
// 11/23/2016
//
// 07/16/2017 : add checking if output file exists then either display error message
// or change output name to name with new latest version identifier.
// frags, noisetab, graphs, decision, extract,
// 07/16/2017
//
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Hashtable;
import java.util.Set;
import java.util.List;
import java.util.Random;
import java.util.Vector;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import java.io.RandomAccessFile;
import java.util.UUID;
import java.net.URL;
import java.util.Enumeration;
import java.lang.management.ManagementFactory;
import java.util.HashSet;
import java.util.Set;
public class Leucippus
{
private static boolean firstdontmatch;
private static String[][] noisetable = new String[0][0];
private static int[][] totalbasecounts = new int[0][0];
// Two dimensional String array used to hold table results
private static List<Double[]> dbtb = new ArrayList<Double[]>();
// Data structure that is used to host arrays with various size.
// that contain coefficients from Pascal's Triangle.
// It is used in calculating the statistics for choosing the window
// with the best overlap.
private static String q = "!\"#$%&\'()*+,-./0123456789:;<=>?@ABCDE"
+"FGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
private static char[] qar = q.toCharArray();
// the qar is a base quality grading 'char' array;
// the index of qar array provides with the actual base quality.
private static int[] percmis = new int[11];
// integer array that holds the number of reads that present within groups of
// percentage of mismatches.
private static Vector<String> readswithindels = new Vector<String>();
// Vector that holds all reads that present indels. The first element of a
// particular group contains information about the interval that was used to
// (coordinates, sequence, and locus) to retrieve the reads from 'bam' files.
// Each read line of the vector contains the origin (bam file name) the read name
// the modified read(according to cigar and position, the cigar, and the position.
private static Vector<String> missed_sites = new Vector<String>();
private static Vector<String> initprstrsends = new Vector<String> ();
// Vector that was generated to hold initial site intervals
// It is used in make-tables process and assists when distance filter is applied
// By storing the original intervals in this parallel Vector(with this of merged)
// all reads that have too high distance from all initial start points and end points are discarted
// (the start and end points of the read are checked in all corresponding initial intervals)
// if all checks discard the read then the read is discarded.
// 08/08/2016
// We exclude all reads by Mapping quality And by delta D
// Then we exclude padded bases even if they include indel
// Now we can calculated coverage (used for indels)
// By applying base quality we calculate total expected for SNVs
// 08/08/2016
/**
* @param args : String array that holds user arguments
* @throws InterruptedException
* @throws IOException
*/
public static void main(String[] args) throws InterruptedException, IOException
{
// Main method (START)
// System.out.println("main method start!");
// Information printed on screen(START)
// General Information (START)
String leu_gen_nfo = "\n\nProgram: Leucippus (Mosaics: Site Noise-Estimation, Validation, Identification)\n"
+ "Version: 0.1.0\n\n"
+ "Usage: Leucippus <command> [options]\n\n"
+ "Command: frag create long reads\n"
+ " noisetab create noise table\n"
+ " graph create graph\n"
+ " decide decide [somatic | germline | unknown | omitted]\n"
+ " extract extract reads that present alternative allele\n"
+ " posgraph create graph for particular postion(site)\n\n"
+ "Config options: " + " -cf+suffix <value> [none]\n\n";
// General Information (END)
// Specific Information (START)
String fragsinfo = "\nUsage: Leucippus frag -o ofile [options] [ file1.fq.gz file2.fq.gz ]\n\n"
+ "Options: -o FILE output file in gzip (e.g., longreads.fq.gz)\n"
+ " -o1 FILE output file in gzip (e.g., remainedreads1.fq.gz)\n"
+ " -o2 FILE output file in gzip (e.g., remainedreads2.fq.gz)\n"
+ " -l maximum long reads length [500]\n"
+ " -minov minimum overlapping region [50]\n"
+ "Input: file1.fq.gz input gzipped file with reads in fastq format\n"
+ " (if not provided, input is taken from standard input)\n"
+ " file2.fq.gz input gzipped file with reads in fastq format\n";
// String tableinfo = "\nUsage: Leucippus noisetab [options] file1.bam [file2.bam, ...]\n\n"
// + "Options: -interval FILE file with intervals\n"
// + " -ref FILE FASTA file with reference sequence (could be .gz file)\n"
// + " -o FILE output file\n"
// + " -q base quality cut off 0-100 [20]\n"
// + " -pad padding range at read ends [1]\n"
// + " -d distance cut off [-1]\n\n";
// //+ " -j java version 1.7 or 1.8 [1.7]\n\n"; java version is retrieved internally
String tableinfo = "\nUsage: Leucippus noisetab [options] file1.bam [file2.bam, ...]\n\n"
+ "Options: -interval FILE file with intervals\n"
+ " -ref FILE FASTA file with reference sequence (could be .gz file)\n"
+ " -o FILE output file\n"
+ " -q base quality cut off 0-100 [20]\n"
+ " -pad padding range at read ends [1]\n"
+ " -d distance cut off [-1]\n"
+ " -msmct exclude all reads above mismatch cutoff [-1]\n\n";
//+ " -j java version 1.7 or 1.8 [1.7]\n\n"; java version is retrieved internally
String graphinfo = "\nUsage: Leucippus graph [options] -o <prefix> table1.file [table2.file]\n\n"
+ "Options: -type graph type: pvalue|mutrate [pvalue]\n"
+ " -coverage INT minimum site/position coverage [100]\n"
+ " -range DOUBLE maximum range for error [0.005]\n"
+ " -overlap INT use positions in overlapping 3'-ends of reads\n"
+ " (the number specifies read length and it is\n"
+ " only useful for analysis of amplicon-seq data)\n"
+ " -cfR PATH /pathtoRscript/Rscript (required)\n"
// + " -fpval generate frequency p-value table\n"
+ " -o prefix for output files: prefix.pdf\n\n";
// + " prefix.fpvtb[1,2].tsv\n\n";
// May 19 2016
// Java Leucipus posgraph -pos chr4:153253817 [table1 table2 table3 ...]
// Keep the same options as in graph
String posgraphinfo = "\nUsage: Leucippus posgraph [options] -o <prefix> [table1 table2 .... table(n)]\n\n"
+ "Options: -type graph type: pvalue|mutrate [pvalue]\n"
+ " -pos chr(x):position (x: 1-22, X, Y)[chr1:1000000]\n"
+ " -coverage INT minimum site/position coverage [100]\n"
+ " -range DOUBLE maximum range for error [0.05]\n"
+ " -overlap INT use positions in overlapping 3'-ends of reads\n"
+ " (the number specifies read length and it is\n"
+ " only useful for analysis of amplicon-seq data)\n"
+ " -cfR PATH /pathtoRscript/Rscript (required)\n"
// + " -fpval generate frequency p-value table\n"
+ " -o prefix for output files: prefix.pdf\n\n";
// + " prefix.fpvtb[ 1,2].tsv\n\n";
// May 19 2016
//
String decideinfo = "\nUsage: Leucippus decide [options] table.file\n\n"
+ "Options: -o FILE results\n"
+ " -coverage minimum site/position coverage [100]\n"
+ " -germlineAF DOUBLE minimum AF to call variant as germline [0.35]\n"
+ " -pvalue DOUBLE p-value for somatic call[0.05]\n\n";
String extractinfo = "\nUsage: Leucippus extract [options] bam.file\n\n"
+ "Options: -o FILE results\n"
+ " -a allele_X [X could be A,C,T,G]\n"
+ " -p chr:position\n\n";
String confinfo = "\nUsage: Not specified. Instead Options are used.\n\n"
+ "Options: -cfsam <path to samtools executable [samtools]>\n"
+ " -cfR <path to R executable [R]>\n"
// + " -cfbwa <path to bwa (none)>\n"
+ " -cftmp <path to temporary folder [./Temp]>\n"
+ " -cfbash <path to bash shell [/bin/bash]>\n"
+ " -cfseparator character\n\n";
// + " -cfref <path to ref (none)>\n\n";
// Specific Information(END)
// Information printed on screen (END)
// final argument arrays (START)
String[][] OverlapArgs = new String[8][2]; // frag
//String[][] TablesArgs = new String[7][2]; // noisetab
String[][] TablesArgs = new String[8][2]; // noisetab
String[][] GraphsArgs = new String[6][2]; // graph
String[][] DecideArgs = new String[5][2]; // decide
String[][] ExtractArgs = new String[4][2]; // extract
String[][] PosGraphsArgs = new String[7][2]; // posgraph
// TablesArgs[7][0] = "javaversion";
// TablesArgs[7][1] = jv;
// final argument arrays (END)
// Leucippus States(States 0 = no state, 1-4 = task state
int state = 0;
boolean doubleoccur = false;
// Identify state (START)
// For each command (frag, noisetab, graph, decide, and extract) there is a
// corresponding state : 1, 2, 3, 4, 5
for (int i = 0; i < args.length; i++)
{
if ((args[i].equals("frag")) && ((state == 0) || (state == 1)))
state = 1;
if ((args[i].equals("noisetab")) && ((state == 0) || (state == 2)))
state = 2;
if ((args[i].equals("graph")) && ((state == 0) || (state == 3)))
state = 3;
if ((args[i].equals("decide")) && ((state == 0) || (state == 4)))
state = 4;
if ((args[i].equals("extract")) && ((state == 0) || (state == 5)))
state = 5;
if ((args[i].equals("posgraph")) && ((state == 0) || (state == 6)))
state = 6;
if ((args[i].equals("frag"))
&& ((state == 2) || (state == 3) || (state == 4) || (state == 5) || (state == 6)))
doubleoccur = true;
if ((args[i].equals("noisetab"))
&& ((state == 1) || (state == 3) || (state == 4) || (state == 5) || (state == 6)))
doubleoccur = true;
if ((args[i].equals("graph"))
&& ((state == 1) || (state == 2) || (state == 4) || (state == 5) || (state == 6)))
doubleoccur = true;
if ((args[i].equals("decide"))
&& ((state == 1) || (state == 2) || (state == 3) || (state == 5) || (state == 6)))
doubleoccur = true;
if ((args[i].equals("extract"))
&& ((state == 1) || (state == 2) || (state == 3) || (state == 4) || (state == 6)))
doubleoccur = true;
if ((args[i].equals("posgraph"))
&& ((state == 1) || (state == 2) || (state == 3) || (state == 4) || (state == 5)))
doubleoccur = true;
}
// Identify state (END)
if (doubleoccur == true) {
System.out.println("The main command must be 'frag' or 'noisetab' " +
"or 'graph' or 'decide' or 'extract' (only one of them).");
Exit();
}
// End States and one instance restriction
if (args.length == 0)
{
System.out.println(leu_gen_nfo);
Exit();
}
if (args.length == 1)
if ((args[0].equals("-h")) || (args[0].equals("-help"))
|| (args[0].equals("help"))) {
System.out.println(leu_gen_nfo);
Exit();
}
// Provide information and Exit(START) if "args" length is <3
if (args.length < 3) {
for (int i = 0; i < args.length; i++) {
if ((args[i].equals("frag")) || (args[i].equals("-frag")))
{
System.out.println(fragsinfo);
Exit();
}
if ((args[i].equals("graph")) || (args[i].equals("-graph"))) {
System.out.println(graphinfo);
Exit();
}
if ((args[i].equals("noisetab"))
|| (args[i].equals("-noisetab"))) {
System.out.println(tableinfo);
Exit();
}
if ((args[i].equals("decide")) || (args[i].equals("-decide"))) {
System.out.println(decideinfo);
Exit();
}
if ((args[i].equals("extract")) || (args[i].equals("-extract"))) {
System.out.println(extractinfo);
Exit();
}
if ((args[i].equals("posgraph")) || (args[i].equals("-posgraph"))) {
System.out.println(posgraphinfo);
Exit();
}
if ((args[i].equals("config"))
|| (args[i].equals("configuration"))
|| (args[i].equals("-config"))
|| (args[i].equals("-configuration"))) {
System.out.println(confinfo);
Exit();
}
}
}
// Provide information and Exit (END)
// Declare Variables (START)
String // OS = "",
// slash = "/",
root_pth = "", fast1 = "", fast2 = "", fast1_cm_fast2 = "",
fragout = "", shortread1out="", shortread2out="", shrts1c2out="", grorpvtb = "",
lrleng = "", separator="", gref_pth = "", pad="",
intable = "", outdecide = "", coverages = "", germlineAFs = "", pvalues="",
prmrs_pth = "", fragpipenp = "", minvrlps="", tables_path = "", msmcut="",
graphs_path = "", graph_type = "", graphs_overlap = "", graphs_range="", dcut = "",
outextract="", bamsextract="", positionextract="", alellextract="",
ptables_pre_path="", tempptable_path = "", pgraphs_path = "", pgraph_type = "",
pgraphs_overlap = "", pcoverages="", pgraphs_range="", pgermlineAFs = "", posgrphs = "",
tmptbpth="", tempostblnm="";
File fl;
double pvalued=0.0;
int k = 1, p = 0, dcuti = 500, msmcuti=-1;
int lrlengi = 0, minvrlpi=0;
// Get java version
String jv="";
jv = ManagementFactory.getRuntimeMXBean().getSpecVersion();
System.out.println("1 Java version : " + jv);
// Get java version
// Declare Variables(END)
String cfpath = System.getProperty("user.dir");
String[][] cfargs = ArgsConfigCheck(args);
String bsh_pth = cfargs[0][1];
String smtls_pth = cfargs[1][1];
// String bwa_pth = cfargs[2][1];
// String ref_pth = cfargs[3][1];
String rscrp_path = cfargs[4][1];
String tmppath = cfargs[5][1];
separator = cfargs[6][1];
for (int i = 0; i < 6; i++)
System.out.println(cfargs[i][0] + " " + cfargs[i][1]);
Vector<String> bms = new Vector<String>();
Vector<String> prrfsqv = new Vector<String>();
// STATES (START)
// correspondence states : frag 1, noisetab 2, graph 3, decide 4, extract 5
if (state != 0) {
// Five "if" statements for five states
// Each statement has a test "args" method call at the beginning
// If the arguments have errors then the testing method will
// provide an informative error message and then it will terminate
// the program.
// If the arguments are correct then the testing method will
// populate the corresponding two dimensional array (it holds modified
// arguments) and will returned here.
// Next the if statement will generate the final command method
// call. Once the final command method finishes its task
// the main method terminates the program.
// frag (START) state 1
if (state == 1) {
System.out.println("Make Long Reads! " + args.length);
BufferedReader br1 = null, br2 = null;
BufferedWriter bw = null;
GZIPOutputStream gzipout = null;
// gzipoutr1 = null, gzipoutr2 = null;
GZIPInputStream gzip1 = null, gzip2 = null;
OverlapArgs = testArgsforFrags(args);
for (int po = 0; po < OverlapArgs.length; po++)
System.out.println(OverlapArgs[po][0] + " : "
+ OverlapArgs[po][1]);
if (OverlapArgs[2][0].equals("bamfile"))
OverlapArgs[2][1] = "piped input bam file expeced.";
fragpipenp = OverlapArgs[0][1];
fast1_cm_fast2 = OverlapArgs[1][1];
fragout = OverlapArgs[2][1]; // output path
shortread1out = OverlapArgs[3][1];
shortread2out = OverlapArgs[4][1];
if( !(shortread1out==null) && !(shortread2out==null) )
shrts1c2out=shortread1out + "," + shortread2out;
lrleng = OverlapArgs[5][1]; // long read length
lrlengi = Integer.parseInt(lrleng);
minvrlps = OverlapArgs[6][1];
minvrlpi = Integer.parseInt(minvrlps);
if (OverlapArgs[0][1].equals("pipe")) {
System.out.println("main method 2 'pipe' no input file.\n"
+ "Proceed with Make Long Reads!");
gzipout = new GZIPOutputStream(
new FileOutputStream(fragout));
bw = new BufferedWriter(new OutputStreamWriter(gzipout));
// if then .., else null(START)
// gzipoutr1 = new GZIPOutputStream(
// new FileOutputStream(shortread1out));
// bw1 = new BufferedWriter(new OutputStreamWriter(gzipoutr1));
//
// gzipoutr2 = new GZIPOutputStream(
// new FileOutputStream(shortread2out));
// bw2 = new BufferedWriter(new OutputStreamWriter(gzipoutr2));
// if then .., else null(END)
br1 = new BufferedReader(new InputStreamReader(System.in));
br2 = null;
MakeLongReads(bw, shrts1c2out, br1, br2, lrlengi, p, minvrlpi, separator);
}
if ((OverlapArgs[0][1].equals("notpipe_gz"))
|| (OverlapArgs[0][1].equals("notpipe"))) {
if (OverlapArgs[1][0].equals("InTwofastq")) {
System.out
.println("main method 2 'not pipe' two input " +
"fastq.gz files.\n"
+ "Proceed with Make Long Reads!");
fast1 = "";
fast2 = "";
String[] wrdes = fast1_cm_fast2.split(",");
fast1 = wrdes[0];
fast2 = wrdes[1];
if (!(fast1.isEmpty())) {
gzip1 = new GZIPInputStream(new FileInputStream(
fast1));
br1 = new BufferedReader(new InputStreamReader(
gzip1));
}
if (!(fast2.isEmpty())) {
gzip2 = new GZIPInputStream(new FileInputStream(
fast2));
br2 = new BufferedReader(new InputStreamReader(
gzip2));
}
gzipout = new GZIPOutputStream(new FileOutputStream(
fragout));
bw = new BufferedWriter(new OutputStreamWriter(gzipout));
// if then .., else null(START)
// System.out.println(shortread1out + " " + shortread2out);
// if then .., else null(END)
// MakeLongReads(bw, br1, br2, lrlengi, p);
MakeLongReads(bw, shrts1c2out, br1, br2, lrlengi, p, minvrlpi, separator);
}
if (OverlapArgs[1][0].equals("InOnefastq")) {
System.out
.println("main method 2 'not pipe' one input " +
"fastq.gz file.\n"
+ "Proceed with Make Long Reads!");
fast1 = fast1_cm_fast2;
fast2 = "";
if (!(fast1.isEmpty())) {
gzip1 = new GZIPInputStream(new FileInputStream(
fast1));
br1 = new BufferedReader(new InputStreamReader(
gzip1));
}
if (!(fast2.isEmpty())) {
gzip2 = new GZIPInputStream(new FileInputStream(
fast2));
br2 = new BufferedReader(new InputStreamReader(
gzip2));
}
gzipout = new GZIPOutputStream(new FileOutputStream(
fragout));
bw = new BufferedWriter(new OutputStreamWriter(gzipout));
// gzipoutr1 = new GZIPOutputStream(
// new FileOutputStream(shortread1out));
// bw1 = new BufferedWriter(new OutputStreamWriter(gzipoutr1));
// gzipoutr2 = new GZIPOutputStream(
// new FileOutputStream(shortread2out));
// bw2 = new BufferedWriter(new OutputStreamWriter(gzipoutr2));
// if then .., else null(END)
// MakeLongReads(bw, br1, br2, lrlengi, p);
MakeLongReads(bw, shrts1c2out, br1, br2, lrlengi, p, minvrlpi, separator);
}
}
}
// frag (END)
// noisetab (START) state 2
if (state == 2) {
System.out.println("Make Tables! " + args.length);
TablesArgs = testArgsforTables(args);
for (int o1 = 0; o1 < TablesArgs.length; o1++) {
System.out.println(TablesArgs[o1][0] + " "
+ TablesArgs[o1][1]);
}
System.out.println("Java Version " + jv);
System.out.println();
String perc = TablesArgs[3][1];
String input = "";
String output = TablesArgs[2][1];
dcut = TablesArgs[4][1];
dcuti = Integer.parseInt(dcut);
prmrs_pth = TablesArgs[1][1];
gref_pth = TablesArgs[5][1];
pad=TablesArgs[6][1];
msmcut=TablesArgs[7][1];
msmcuti = Integer.parseInt(msmcut);
//jversion=TablesArgs[7][1];
// prrfsqv = GenomeRefParser(prmrs_pth, gref_pth);
System.out.println("Request Genome reference sequences!");
prrfsqv = IndependentGenomeRefParser(prmrs_pth, gref_pth);
if (prrfsqv.size() == 0) {
System.out
.println("Reference parser returned zero referense"+
"sequences\nExit.");
Exit();
}
if (TablesArgs[0][0].equals("bams")) {
String[] pwrds = TablesArgs[0][1].split(",");
for (int bm = 0; bm < pwrds.length; bm++)
bms.add(pwrds[bm]);
input = "none";
}
output = TablesArgs[2][1];
root_pth = new java.io.File(".").getCanonicalPath();
root_pth = root_pth + "/";
System.out.println("root path = " + root_pth);
for (int jk = 0; jk < bms.size(); jk++)
System.out.println(bms.get(jk));
/*
* TablesArgs[0][1]="bam,bam,...";
* TablesArgs[1][1]="interval"; TablesArgs[2][1]="output";
* TablesArgs[3][1]="quality"; TablesArgs[4][1]="distance";
* TablesArgs[5][1]="reference"; TablesArgs[6][1]="pad";
*/
System.out.println("main method 2 Proceed with Table!");
makeTables(bsh_pth, smtls_pth, input, output, perc, prrfsqv,
bms, tmppath, dcuti, pad, jv, msmcuti);
k = 0;
}
// noisetab (END)
// graph (START) state 3
if (state == 3) {
// type, coverage, range, overlap, fpval(optional) o input
// 1 5 6 4 3 2
System.out.println("Make Graphs! " + args.length);
// Thread.sleep(1000);
GraphsArgs = testArgsforGraphs(args);
graph_type = GraphsArgs[0][1];
tables_path = GraphsArgs[1][1];
graphs_path = GraphsArgs[2][1];
graphs_overlap = GraphsArgs[3][1];
coverages = GraphsArgs[4][1];
//germlineAFs = GraphsArgs[5][1];
graphs_range = GraphsArgs[5][1];
System.out.println("Graph Type " + GraphsArgs[0][0] + " "
+ GraphsArgs[0][1]);
System.out.println("Input Table(s) " + GraphsArgs[1][0] + " "
+ GraphsArgs[1][1]);
System.out.println("Output " + GraphsArgs[2][0] + " "
+ GraphsArgs[2][1]);
System.out.println("Overlap " + GraphsArgs[3][0] + " "
+ GraphsArgs[3][1]);
System.out.println("Coverage " + GraphsArgs[4][0] + " "
+ GraphsArgs[4][1]);
System.out.println("Range " + GraphsArgs[5][0] + " "
+ (Double.parseDouble(GraphsArgs[5][1])));
// + (1 - Double.parseDouble(GraphsArgs[5][1])));
if(rscrp_path.isEmpty())
{
System.out.println("R script executable has not been provided.\nExit.");
Exit();
}
// added to provide option for creation of frequency-p-value
// table
grorpvtb = GraphsArgs[2][0];
System.out.println("graph or pvalue table : " + grorpvtb);
System.out.println("main method 2 Proceed with Graph!\n\n");
CreateGraphs(graph_type, tables_path, graphs_path, rscrp_path,
bsh_pth, cfpath, grorpvtb, graphs_overlap, coverages,
graphs_range);
}
// graph(END)
// decide (START) state 4
if (state == 4) {
System.out.println("Decide!");
DecideArgs = testArgsforDecide(args);
intable = DecideArgs[0][1];
outdecide = DecideArgs[1][1];
coverages = DecideArgs[2][1];
germlineAFs = DecideArgs[3][1];
pvalues = DecideArgs[4][1];
pvalued = Double.parseDouble(pvalues);
System.out.println("input table : " + intable);
System.out.println("output results : " + outdecide);
System.out.println(DecideArgs[2][0] + " : " + coverages);
System.out.println(DecideArgs[3][0] + " : " + germlineAFs);
System.out.println(DecideArgs[4][0] + " : " + pvalued + "\n");
System.out.println("main method 2 Proceed with Decide!");
Decide(intable, outdecide, coverages, germlineAFs, pvalued);
}
// decide(END)
// extract (START) state 5
if (state == 5) {
System.out.println("Extract!");
ExtractArgs = testArgsforExtract(args);
bamsextract=ExtractArgs[0][1];
if (ExtractArgs[0][0].equals("bams")) {
String[] pwrds = bamsextract.split(",");
for (int bm = 0; bm < pwrds.length; bm++)
bms.add(pwrds[bm]);
//input = "none";
}
else if (ExtractArgs[0][0].equals("nobams"))
{
System.out.println("No bams to proceed!");
Exit();
}
//outextract="", bamsextract="", positionextract="", alellextract="";
outextract = ExtractArgs[3][1];
root_pth = new java.io.File(".").getCanonicalPath();
root_pth = root_pth + "/";
System.out.println("root path = " + root_pth);
//for (int jk = 0; jk < bms.size(); jk++)
//System.out.println(bms.get(jk));
alellextract = ExtractArgs[1][1];
positionextract = ExtractArgs[2][1];
System.out.println("bam files : " + bamsextract);
System.out.println("output results : " + outextract);
System.out.println("positionextract : " + positionextract);
System.out.println("alelextract : " + alellextract);
System.out.println("main method 2 Proceed with Extract!");
// Extract(intable, outdecide, coverages, germlineAFs, pvalued);
Extract(bsh_pth, smtls_pth, outextract, positionextract, alellextract,
bms, tmppath);
}
// decide(END)
// posgraph(START)
if (state == 6) {
// type, coverage, range, overlap, fpval(optional) o input
// 1 5 6 4 3 2
System.out.println("Make Position Graph! " + args.length);
// Thread.sleep(1000);
PosGraphsArgs = testArgsforPositionGraphs(args);
pgraph_type = PosGraphsArgs[0][1];
ptables_pre_path = PosGraphsArgs[1][1];
posgrphs = PosGraphsArgs[6][1];
// Change this to working directory
String tmp_pthpg = System.getProperty("user.dir");
UUID idptbl = UUID.randomUUID();
tempostblnm = String.valueOf(idptbl);
tmp_pthpg = tmp_pthpg + "/";
tmptbpth = tmp_pthpg + tempostblnm + ".tsv";
// Temporary table that must be deleted when graph is done
tempptable_path = generatePosTable(ptables_pre_path, posgrphs, tmptbpth);
if(tempptable_path.equals("zero_table_lines"))
{
System.out.println("Position '" + posgrphs + " has not found in the input table(s).\nExit.\n");
Exit();
}
System.out.println("\nTemp position table : " + tmptbpth);
pgraphs_path = PosGraphsArgs[2][1];
pgraphs_overlap = PosGraphsArgs[3][1];
pcoverages = PosGraphsArgs[4][1];
// pgermlineAFs = PosGraphsArgs[5][1];
pgraphs_range = PosGraphsArgs[5][1];
System.out.println("Graph Type " + PosGraphsArgs[0][0] + " "
+ PosGraphsArgs[0][1]);
System.out.println("Output " + PosGraphsArgs[2][0] + " "
+ PosGraphsArgs[2][1]);
System.out.println("Overlap " + PosGraphsArgs[3][0] + " "
+ PosGraphsArgs[3][1]);
System.out.println("Coverage " + PosGraphsArgs[4][0] + " "
+ PosGraphsArgs[4][1]);
System.out.println("Range " + PosGraphsArgs[5][0] + " "
+ (Double.parseDouble(PosGraphsArgs[5][1])));
// + (1 - Double.parseDouble(PosGraphsArgs[5][1])));
System.out.println("Position " + PosGraphsArgs[6][0] + " "
+ PosGraphsArgs[6][1]);
System.out.println("Input Table(s) " + PosGraphsArgs[1][0] + " "
+ PosGraphsArgs[1][1]);
if(rscrp_path.isEmpty())
{
System.out.println("R script executable has not been provided.\nExit.");
Exit();
}
// added to provide option for creation of frequency-p-value
// table
grorpvtb = PosGraphsArgs[2][0];
System.out.println("main method 6 Proceed with Position Graph!\n\n");
CreateGraphs(pgraph_type, tempptable_path, pgraphs_path, rscrp_path,
bsh_pth, cfpath, grorpvtb, pgraphs_overlap, pcoverages,
pgraphs_range);
System.out.println("graph or pvalue table : " + grorpvtb);
fl = new File(tempptable_path);
if(fl.exists())
{
System.out.println(fl.getName());
fl.delete();
}
//System.out.println("main method 6 Proceed with Position Graph!\n\n");
// CreatePosGraphs(pgraph_type, ptables_path, pgraphs_path, rscrp_path,
// bsh_pth, cfpath, grorpvtb, pgraphs_overlap, pcoverages,
// pgermlineAFs, posgrphs);
}
// posgraph(END)
}
// STATES(END)
System.out.println("End of Main method!");
}
// Main method(END)
public static String generatePosTable(String ptables_pre_path, String posgrphs, String respth) throws IOException, InterruptedException
{
String chrq="", posq="";
String[] wdpsq = posgrphs.split(":");
chrq=wdpsq[0];
posq=wdpsq[1];
Vector<String> crvect = new Vector<String>();
Vector<String> resvect = new Vector<String>();
String crtbpth="", fnm="", recrpos="";
File fl;
String[] wds = ptables_pre_path.split(",");
String line="", crchr="", crpos="", crref="", cralt="";
for(int i=0; i<wds.length; i++)
{
crtbpth=wds[i];
if(testFileExistence(crtbpth))
{
fl = new File(crtbpth);
fnm = fl.getName();
crvect = new Vector<String>();
crvect = readTheFileIncludeFirstLine(crtbpth, fnm);
if(i==0)
resvect.add(crvect.get(0));
for(int j=1; j<crvect.size(); j++)
{
String[] wfds = crvect.get(j).split("\t");
crchr = wfds[0];
crpos = wfds[1];
if( (crchr.equals(chrq)) && (crpos.equals(posq)) )
{
resvect.add(crvect.get(j));
j=crvect.size();
}
}
}
else
{
System.out.println("file : " + crtbpth +"\ndoesn't exist.");
}
}
if(resvect.size()>1)
writeToFile(respth, resvect);
else
respth="zero_table_lines";
System.out.println(resvect.size()-1 + " position-lines have been found.");
// for(int i=0; i<resvect.size(); i++)
// System.out.println(resvect.get(i));
return respth;
}
/**
* Method that checks for validity of user entered arguments. The method
* performs three tasks. It tests the paths/files if they exist. In returned
* two dimensional array usually it populates the [x][0] element with an
* informative value, and the [x][1] with the actual value. The method has
* no capability of termination.
*
* @param argmns
* @return resargs String[][] a two dimensional String array is returned
* @throws IOException
* (the method was designed to read a configuration file; now it
* tests for path existence)
*
**/
public static String[][] ArgsConfigCheck(String[] argmns)
throws IOException {
// ArgsConfigCheck method (START)
System.out.println("\nArgsConfigCheck method Start! ----------");
String confinfo = "configuration [main command doesnt exist)]\n"
+ "insread a simple prefix '-cf' followed by the suffix is used.\n"
+ "-cfsam [-cfsam] [path for samtools]\n"
+ "-cfR [-cfR] [path for R]\n"
//+ "-cfbwa [-cfbwa] [path for bwa]\n"
+ "-cftmp [-cftmp] [path for temporary folder]\n"
+ "-cfbash [-cfbash] [path for bash]\n";
//+ "-cfref [-cfref] [path for ref]";
String OS = "", root_pth = "", bsh_pth = "", smtls_pth = "",
bwa_pth = "", ref_bam_pth = "", rscrp_path = "", tmp_pth = "", inpth="",
slash = "/", separator="";
int corcnt = 0;
File fl;
String jcur="";
String[][] resargs = new String[7][2];
// Indices [x][0] are for info; [x][1] are for values
resargs[0][0] = "bsh_pth";
resargs[0][1] = "";
resargs[1][0] = "smtls_pth";
resargs[1][1] = "";
resargs[2][0] = "bwa_pth";
resargs[2][1] = "";
resargs[3][0] = "ref_bam_pth";
resargs[3][1] = "";
resargs[4][0] = "rscrp_path";
resargs[4][1] = "";
resargs[5][0] = "tmp_path";
resargs[5][0] = "";
resargs[6][0] = "separatordef";
resargs[6][1] = "";
for (int i = 0; i < 6; i++)
resargs[i][1] = "";
for (int i = 0; i < argmns.length; i++)
{
if ((argmns[i].equals("-cfbash")) && (i < argmns.length - 1))
{
if (testFileExistence(argmns[i + 1]))
{
bsh_pth = argmns[i + 1];
resargs[0][1] = bsh_pth;
corcnt = corcnt + 1;
System.out.println("bash executable exists!");
}
else
{
System.out.println("bash executable not found.\nExit.");
Exit();
}
// if (testParentDirectoryExistence(argmns[i + 1])) {
// bsh_pth = argmns[i + 1];
// resargs[0][1] = bsh_pth;
// corcnt = corcnt + 1;
// System.out.println("bash path directory exists!");
// } else {
// System.out.println("bash path directory not found.");
// resargs[0][1] = "";
// }
}
if ((argmns[i].equals("-cfR")) && (i < argmns.length - 1))
{
if (testFileExistence(argmns[i + 1]))
{
rscrp_path = argmns[i + 1];
resargs[4][1] = rscrp_path;
corcnt = corcnt + 1;
System.out.println("Rscript executable exists!");
}
else
{
System.out.println("Rscript executable not found.\nExit.");
Exit();
}
//if (testParentDirectoryExistence(argmns[i + 1])) {
// rscrp_path = argmns[i + 1];
// resargs[4][1] = rscrp_path;
// corcnt = corcnt + 1;
// System.out.println("R path directory exists!");
//} else {
// System.out.println("R path directory not found.");
// resargs[4][1] = "";
// }
}
if ((argmns[i].equals("-cfsam")) && (i < argmns.length - 1))
{
if (testFileExistence(argmns[i + 1]))
{
smtls_pth = argmns[i + 1];
resargs[1][1] = smtls_pth;
corcnt = corcnt + 1;
System.out.println("samtools executable exists!");
}
else
{
System.out.println("samtools executable not found.\nExit.");
Exit();
}
//if (testParentDirectoryExistence(argmns[i + 1])) {
// smtls_pth = argmns[i + 1];
// resargs[1][1] = smtls_pth;
// corcnt = corcnt + 1;
// System.out.println("samtools path directory exists!");
//} else {
// System.out.println("samtools path directory not found.");
// resargs[1][1] = "";
//}
}
if ((argmns[i].equals("-cfbwa")) && (i < argmns.length - 1)) {
if (testParentDirectoryExistence(argmns[i + 1])) {
bwa_pth = argmns[i + 1];
resargs[2][1] = bwa_pth;
corcnt = corcnt + 1;
System.out.println("bwa path directory exists!");
} else {
System.out.println("bwa path directory not found.");
resargs[2][1] = "";
}
}
if ((argmns[i].equals("-cfseparator")) && (i < argmns.length - 1))
{
separator = argmns[i + 1];
resargs[6][0] = "separator";
resargs[6][1] = separator;
corcnt = corcnt + 1;
System.out.println("separator has been stated!");
}
if ((argmns[i].equals("-cftmp")) && (i < argmns.length - 1))
{
jcur= argmns[i + 1];
fl=new File(jcur);
inpth = fl.getName();
if (jcur.equals(inpth))
{
root_pth = new java.io.File(".").getCanonicalPath();
root_pth = root_pth + "/";
jcur = root_pth + jcur;
fl=new File(jcur);
if(!fl.exists())
fl.mkdir();
if(!fl.exists())
{
System.out.println("Temporary path directory cannot be created.\nExit.");
Exit();
}
tmp_pth = jcur;
resargs[5][1] = tmp_pth;
corcnt = corcnt + 1;
}
else if (testParentDirectoryExistence(jcur))
{
fl=new File(jcur);
if(!fl.exists())
fl.mkdir();
if(!fl.exists())
{
System.out.println("Temporary path directory cannot be created.\nExit.");
Exit();
}
else
{
tmp_pth = jcur;
resargs[5][1] = tmp_pth;
corcnt = corcnt + 1;
System.out.println("Temporary path directory exists!");