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