annotate KinaMine-Galaxy-7-7/src/kinamine/KinaMineDriver.java @ 0:67635b462045 draft

Uploaded
author jfb
date Tue, 20 Feb 2018 14:31:15 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
67635b462045 Uploaded
jfb
parents:
diff changeset
1 /**
67635b462045 Uploaded
jfb
parents:
diff changeset
2 *****************************************************************************
67635b462045 Uploaded
jfb
parents:
diff changeset
3 * <p>
67635b462045 Uploaded
jfb
parents:
diff changeset
4 * Copyright (c) Regents of the University of Minnesota. All Rights Reserved.
67635b462045 Uploaded
jfb
parents:
diff changeset
5 * <p>
67635b462045 Uploaded
jfb
parents:
diff changeset
6 * Author: Kevin Murray University of Minnesota - (murra668@umn.edu)
67635b462045 Uploaded
jfb
parents:
diff changeset
7 * <p>
67635b462045 Uploaded
jfb
parents:
diff changeset
8 *****************************************************************************
67635b462045 Uploaded
jfb
parents:
diff changeset
9 */
67635b462045 Uploaded
jfb
parents:
diff changeset
10 package kinamine;
67635b462045 Uploaded
jfb
parents:
diff changeset
11
67635b462045 Uploaded
jfb
parents:
diff changeset
12 import java.io.BufferedReader;
67635b462045 Uploaded
jfb
parents:
diff changeset
13 import java.io.FileNotFoundException;
67635b462045 Uploaded
jfb
parents:
diff changeset
14 import java.io.FileReader;
67635b462045 Uploaded
jfb
parents:
diff changeset
15 import java.io.IOException;
67635b462045 Uploaded
jfb
parents:
diff changeset
16 import java.util.ArrayList;
67635b462045 Uploaded
jfb
parents:
diff changeset
17
67635b462045 Uploaded
jfb
parents:
diff changeset
18 /**
67635b462045 Uploaded
jfb
parents:
diff changeset
19 * Driver class for KinaMine. Processes arguments collected from GUI.
67635b462045 Uploaded
jfb
parents:
diff changeset
20 *
67635b462045 Uploaded
jfb
parents:
diff changeset
21 * @version 1.0
67635b462045 Uploaded
jfb
parents:
diff changeset
22 * @author murra668
67635b462045 Uploaded
jfb
parents:
diff changeset
23 */
67635b462045 Uploaded
jfb
parents:
diff changeset
24 public class KinaMineDriver {
67635b462045 Uploaded
jfb
parents:
diff changeset
25
67635b462045 Uploaded
jfb
parents:
diff changeset
26 /**
67635b462045 Uploaded
jfb
parents:
diff changeset
27 * Main run method for KinaMine. Processes arguments and stores file
67635b462045 Uploaded
jfb
parents:
diff changeset
28 * contents for compiling a run.
67635b462045 Uploaded
jfb
parents:
diff changeset
29 *
67635b462045 Uploaded
jfb
parents:
diff changeset
30 * @param args
67635b462045 Uploaded
jfb
parents:
diff changeset
31 * @param debug
67635b462045 Uploaded
jfb
parents:
diff changeset
32 * @return
67635b462045 Uploaded
jfb
parents:
diff changeset
33 */
67635b462045 Uploaded
jfb
parents:
diff changeset
34 public static boolean run(String[] args, boolean debug) {
67635b462045 Uploaded
jfb
parents:
diff changeset
35
67635b462045 Uploaded
jfb
parents:
diff changeset
36 /** Process aruments. */
67635b462045 Uploaded
jfb
parents:
diff changeset
37 String pepPath = args[0];
67635b462045 Uploaded
jfb
parents:
diff changeset
38 String fastaPath = args[1];
67635b462045 Uploaded
jfb
parents:
diff changeset
39 String outPath = args[2];
67635b462045 Uploaded
jfb
parents:
diff changeset
40 double fdrScore = Double.valueOf(args[3]);
67635b462045 Uploaded
jfb
parents:
diff changeset
41 String outGroup = "output";
67635b462045 Uploaded
jfb
parents:
diff changeset
42
67635b462045 Uploaded
jfb
parents:
diff changeset
43 /** Read peptide report. */
67635b462045 Uploaded
jfb
parents:
diff changeset
44 ArrayList<String> peptides = retTabFile(pepPath);
67635b462045 Uploaded
jfb
parents:
diff changeset
45 peptides.remove(0);
67635b462045 Uploaded
jfb
parents:
diff changeset
46
67635b462045 Uploaded
jfb
parents:
diff changeset
47 ArrayList<String> proteins = new ArrayList<>();
67635b462045 Uploaded
jfb
parents:
diff changeset
48
67635b462045 Uploaded
jfb
parents:
diff changeset
49 /** Read fasta database */
67635b462045 Uploaded
jfb
parents:
diff changeset
50 if (fastaPath.contains("fasta")){
67635b462045 Uploaded
jfb
parents:
diff changeset
51 proteins = retFastaFile(fastaPath);
67635b462045 Uploaded
jfb
parents:
diff changeset
52 } else {
67635b462045 Uploaded
jfb
parents:
diff changeset
53 proteins = retTabFile(fastaPath);
67635b462045 Uploaded
jfb
parents:
diff changeset
54 }
67635b462045 Uploaded
jfb
parents:
diff changeset
55
67635b462045 Uploaded
jfb
parents:
diff changeset
56
67635b462045 Uploaded
jfb
parents:
diff changeset
57 /** Create new run. */
67635b462045 Uploaded
jfb
parents:
diff changeset
58 Run run = new Run(peptides, proteins, fdrScore);
67635b462045 Uploaded
jfb
parents:
diff changeset
59
67635b462045 Uploaded
jfb
parents:
diff changeset
60 /** Write run reports. */
67635b462045 Uploaded
jfb
parents:
diff changeset
61 Reporter.writeReports(run, outPath, outGroup);
67635b462045 Uploaded
jfb
parents:
diff changeset
62
67635b462045 Uploaded
jfb
parents:
diff changeset
63 return true;
67635b462045 Uploaded
jfb
parents:
diff changeset
64 }
67635b462045 Uploaded
jfb
parents:
diff changeset
65
67635b462045 Uploaded
jfb
parents:
diff changeset
66 /**
67635b462045 Uploaded
jfb
parents:
diff changeset
67 * Reads tabular files.
67635b462045 Uploaded
jfb
parents:
diff changeset
68 *
67635b462045 Uploaded
jfb
parents:
diff changeset
69 * @param path
67635b462045 Uploaded
jfb
parents:
diff changeset
70 * @return Arraylist of lines.
67635b462045 Uploaded
jfb
parents:
diff changeset
71 */
67635b462045 Uploaded
jfb
parents:
diff changeset
72 public static ArrayList<String> retTabFile(String path) {
67635b462045 Uploaded
jfb
parents:
diff changeset
73
67635b462045 Uploaded
jfb
parents:
diff changeset
74 /** Initialize lines */
67635b462045 Uploaded
jfb
parents:
diff changeset
75 ArrayList<String> lines = new ArrayList<>();
67635b462045 Uploaded
jfb
parents:
diff changeset
76
67635b462045 Uploaded
jfb
parents:
diff changeset
77 try {
67635b462045 Uploaded
jfb
parents:
diff changeset
78
67635b462045 Uploaded
jfb
parents:
diff changeset
79 /** Configure reader. */
67635b462045 Uploaded
jfb
parents:
diff changeset
80 FileReader fr = new FileReader(path);
67635b462045 Uploaded
jfb
parents:
diff changeset
81 BufferedReader br = new BufferedReader(fr);
67635b462045 Uploaded
jfb
parents:
diff changeset
82
67635b462045 Uploaded
jfb
parents:
diff changeset
83 /** Initialize first line, headers - discard */
67635b462045 Uploaded
jfb
parents:
diff changeset
84 String line = br.readLine();
67635b462045 Uploaded
jfb
parents:
diff changeset
85
67635b462045 Uploaded
jfb
parents:
diff changeset
86 /**
67635b462045 Uploaded
jfb
parents:
diff changeset
87 * Read each line in the configuration file and add each line to an
67635b462045 Uploaded
jfb
parents:
diff changeset
88 * array (to be returned)
67635b462045 Uploaded
jfb
parents:
diff changeset
89 */
67635b462045 Uploaded
jfb
parents:
diff changeset
90 while (line != null) {
67635b462045 Uploaded
jfb
parents:
diff changeset
91
67635b462045 Uploaded
jfb
parents:
diff changeset
92 /** If line is all tabs, end of file */
67635b462045 Uploaded
jfb
parents:
diff changeset
93 if (line.startsWith("\t")) {
67635b462045 Uploaded
jfb
parents:
diff changeset
94 break;
67635b462045 Uploaded
jfb
parents:
diff changeset
95 }
67635b462045 Uploaded
jfb
parents:
diff changeset
96
67635b462045 Uploaded
jfb
parents:
diff changeset
97 /** Add line to list. */
67635b462045 Uploaded
jfb
parents:
diff changeset
98 lines.add(line);
67635b462045 Uploaded
jfb
parents:
diff changeset
99 line = br.readLine();
67635b462045 Uploaded
jfb
parents:
diff changeset
100 }
67635b462045 Uploaded
jfb
parents:
diff changeset
101
67635b462045 Uploaded
jfb
parents:
diff changeset
102 /** Close the file */
67635b462045 Uploaded
jfb
parents:
diff changeset
103 br.close();
67635b462045 Uploaded
jfb
parents:
diff changeset
104
67635b462045 Uploaded
jfb
parents:
diff changeset
105 } catch (FileNotFoundException filenotfoundexxption) {
67635b462045 Uploaded
jfb
parents:
diff changeset
106 System.out.println(path + ", does not exist");
67635b462045 Uploaded
jfb
parents:
diff changeset
107 } catch (IOException ioexception) {
67635b462045 Uploaded
jfb
parents:
diff changeset
108 ioexception.printStackTrace();
67635b462045 Uploaded
jfb
parents:
diff changeset
109 }
67635b462045 Uploaded
jfb
parents:
diff changeset
110
67635b462045 Uploaded
jfb
parents:
diff changeset
111 return lines;
67635b462045 Uploaded
jfb
parents:
diff changeset
112 }
67635b462045 Uploaded
jfb
parents:
diff changeset
113
67635b462045 Uploaded
jfb
parents:
diff changeset
114 public static ArrayList<String> retFastaFile(String path) {
67635b462045 Uploaded
jfb
parents:
diff changeset
115
67635b462045 Uploaded
jfb
parents:
diff changeset
116 /** Initialize lines */
67635b462045 Uploaded
jfb
parents:
diff changeset
117 ArrayList<String> lines = new ArrayList<>();
67635b462045 Uploaded
jfb
parents:
diff changeset
118
67635b462045 Uploaded
jfb
parents:
diff changeset
119 try {
67635b462045 Uploaded
jfb
parents:
diff changeset
120
67635b462045 Uploaded
jfb
parents:
diff changeset
121 /** Configure reader. */
67635b462045 Uploaded
jfb
parents:
diff changeset
122 FileReader fr = new FileReader(path);
67635b462045 Uploaded
jfb
parents:
diff changeset
123 BufferedReader br = new BufferedReader(fr);
67635b462045 Uploaded
jfb
parents:
diff changeset
124
67635b462045 Uploaded
jfb
parents:
diff changeset
125 String line = br.readLine();
67635b462045 Uploaded
jfb
parents:
diff changeset
126 String prot = "";
67635b462045 Uploaded
jfb
parents:
diff changeset
127
67635b462045 Uploaded
jfb
parents:
diff changeset
128 while (line != null) {
67635b462045 Uploaded
jfb
parents:
diff changeset
129
67635b462045 Uploaded
jfb
parents:
diff changeset
130 if (line.startsWith(">")){
67635b462045 Uploaded
jfb
parents:
diff changeset
131 String[] temp = line.split(" ");
67635b462045 Uploaded
jfb
parents:
diff changeset
132 prot = temp[0].trim() + "\t \t";
67635b462045 Uploaded
jfb
parents:
diff changeset
133 } else {
67635b462045 Uploaded
jfb
parents:
diff changeset
134 prot += line.trim();
67635b462045 Uploaded
jfb
parents:
diff changeset
135 lines.add(prot);
67635b462045 Uploaded
jfb
parents:
diff changeset
136 }
67635b462045 Uploaded
jfb
parents:
diff changeset
137
67635b462045 Uploaded
jfb
parents:
diff changeset
138 line = br.readLine();
67635b462045 Uploaded
jfb
parents:
diff changeset
139 }
67635b462045 Uploaded
jfb
parents:
diff changeset
140
67635b462045 Uploaded
jfb
parents:
diff changeset
141 br.close();
67635b462045 Uploaded
jfb
parents:
diff changeset
142
67635b462045 Uploaded
jfb
parents:
diff changeset
143 } catch (FileNotFoundException filenotfoundexxption) {
67635b462045 Uploaded
jfb
parents:
diff changeset
144 System.out.println(path + ", does not exist");
67635b462045 Uploaded
jfb
parents:
diff changeset
145 } catch (IOException ioexception) {
67635b462045 Uploaded
jfb
parents:
diff changeset
146 ioexception.printStackTrace();
67635b462045 Uploaded
jfb
parents:
diff changeset
147 }
67635b462045 Uploaded
jfb
parents:
diff changeset
148
67635b462045 Uploaded
jfb
parents:
diff changeset
149 return lines;
67635b462045 Uploaded
jfb
parents:
diff changeset
150 }
67635b462045 Uploaded
jfb
parents:
diff changeset
151
67635b462045 Uploaded
jfb
parents:
diff changeset
152 }