annotate KinaMine-Galaxy-7-7/src/kinamine/Reporter.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.*;
67635b462045 Uploaded
jfb
parents:
diff changeset
13 import java.util.ArrayList;
67635b462045 Uploaded
jfb
parents:
diff changeset
14 import java.util.Collection;
67635b462045 Uploaded
jfb
parents:
diff changeset
15 import java.util.Map.Entry;
67635b462045 Uploaded
jfb
parents:
diff changeset
16 import java.util.Set;
67635b462045 Uploaded
jfb
parents:
diff changeset
17 import javafx.util.Pair;
67635b462045 Uploaded
jfb
parents:
diff changeset
18
67635b462045 Uploaded
jfb
parents:
diff changeset
19 /**
67635b462045 Uploaded
jfb
parents:
diff changeset
20 * Reporter class to write reports. Currently writes out in .csv format.
67635b462045 Uploaded
jfb
parents:
diff changeset
21 *
67635b462045 Uploaded
jfb
parents:
diff changeset
22 * @version 1.0
67635b462045 Uploaded
jfb
parents:
diff changeset
23 * @author murra668
67635b462045 Uploaded
jfb
parents:
diff changeset
24 * new author: blank121@umn.edu as of August 2017
67635b462045 Uploaded
jfb
parents:
diff changeset
25 */
67635b462045 Uploaded
jfb
parents:
diff changeset
26 public class Reporter {
67635b462045 Uploaded
jfb
parents:
diff changeset
27
67635b462045 Uploaded
jfb
parents:
diff changeset
28 /**
67635b462045 Uploaded
jfb
parents:
diff changeset
29 * Write reports for run.
67635b462045 Uploaded
jfb
parents:
diff changeset
30 *
67635b462045 Uploaded
jfb
parents:
diff changeset
31 * @param run
67635b462045 Uploaded
jfb
parents:
diff changeset
32 * @param outPath
67635b462045 Uploaded
jfb
parents:
diff changeset
33 * @param outGroup
67635b462045 Uploaded
jfb
parents:
diff changeset
34 */
67635b462045 Uploaded
jfb
parents:
diff changeset
35 static void writeReports(Run run, String outPath, String outGroup) {
67635b462045 Uploaded
jfb
parents:
diff changeset
36
67635b462045 Uploaded
jfb
parents:
diff changeset
37 /** Write substrates report. */
67635b462045 Uploaded
jfb
parents:
diff changeset
38 String outputFileSub = outPath + outGroup + "_Substrates.csv";
67635b462045 Uploaded
jfb
parents:
diff changeset
39 Reporter.substrates(run, outputFileSub);
67635b462045 Uploaded
jfb
parents:
diff changeset
40
67635b462045 Uploaded
jfb
parents:
diff changeset
41 /** Write substrate background frequency report. */
67635b462045 Uploaded
jfb
parents:
diff changeset
42 String outputFileFreq = outPath + outGroup + "_SubBackFreq.csv";
67635b462045 Uploaded
jfb
parents:
diff changeset
43 Reporter.frequencies(run, outputFileFreq);
67635b462045 Uploaded
jfb
parents:
diff changeset
44
67635b462045 Uploaded
jfb
parents:
diff changeset
45 }
67635b462045 Uploaded
jfb
parents:
diff changeset
46
67635b462045 Uploaded
jfb
parents:
diff changeset
47 /**
67635b462045 Uploaded
jfb
parents:
diff changeset
48 * Writes substrates report from the ids and motifs of each peptide.
67635b462045 Uploaded
jfb
parents:
diff changeset
49 *
67635b462045 Uploaded
jfb
parents:
diff changeset
50 * @param run
67635b462045 Uploaded
jfb
parents:
diff changeset
51 * @param outputFileName
67635b462045 Uploaded
jfb
parents:
diff changeset
52 */
67635b462045 Uploaded
jfb
parents:
diff changeset
53 private static void substrates(Run run, String outputFileName) {
67635b462045 Uploaded
jfb
parents:
diff changeset
54
67635b462045 Uploaded
jfb
parents:
diff changeset
55 /** Format header */
67635b462045 Uploaded
jfb
parents:
diff changeset
56 // String header = "Substrates," + "Species," + "Reference," + "-7," + "-6,"
67635b462045 Uploaded
jfb
parents:
diff changeset
57 // + "-5," + "-4," + "-3," + "-2," + "-1," + "0," + "1,"
67635b462045 Uploaded
jfb
parents:
diff changeset
58 // + "2," + "3," + "4," + "5," + "6," + "7," + "Phosphite"
67635b462045 Uploaded
jfb
parents:
diff changeset
59 // + "\n";
67635b462045 Uploaded
jfb
parents:
diff changeset
60 String header = "Substrates," + "Species," + "Reference," + "-7," + "-6,"
67635b462045 Uploaded
jfb
parents:
diff changeset
61 + "-5," + "-4," + "-3," + "-2," + "-1," + "0," + "1,"
67635b462045 Uploaded
jfb
parents:
diff changeset
62 + "2," + "3," + "4," + "5," + "6," + "7,"
67635b462045 Uploaded
jfb
parents:
diff changeset
63 +" ," +" ,"+ " ,"+ "Phosphite"
67635b462045 Uploaded
jfb
parents:
diff changeset
64 + "\n";
67635b462045 Uploaded
jfb
parents:
diff changeset
65
67635b462045 Uploaded
jfb
parents:
diff changeset
66 /** Initialize details */
67635b462045 Uploaded
jfb
parents:
diff changeset
67 String detail = null;
67635b462045 Uploaded
jfb
parents:
diff changeset
68
67635b462045 Uploaded
jfb
parents:
diff changeset
69 try (FileWriter writer = new FileWriter(outputFileName)) {
67635b462045 Uploaded
jfb
parents:
diff changeset
70
67635b462045 Uploaded
jfb
parents:
diff changeset
71 /* Write the column headers */
67635b462045 Uploaded
jfb
parents:
diff changeset
72 writer.append(header);
67635b462045 Uploaded
jfb
parents:
diff changeset
73
67635b462045 Uploaded
jfb
parents:
diff changeset
74 Collection<Motif> motifs = run.motifs.values();
67635b462045 Uploaded
jfb
parents:
diff changeset
75
67635b462045 Uploaded
jfb
parents:
diff changeset
76 /** Loop through each motif */
67635b462045 Uploaded
jfb
parents:
diff changeset
77 for (Motif motif : motifs) {
67635b462045 Uploaded
jfb
parents:
diff changeset
78
67635b462045 Uploaded
jfb
parents:
diff changeset
79 /** Format ID and blanks */
67635b462045 Uploaded
jfb
parents:
diff changeset
80 detail = "," + "," + motif.ref + ",";
67635b462045 Uploaded
jfb
parents:
diff changeset
81
67635b462045 Uploaded
jfb
parents:
diff changeset
82 String seq = motif.seq;
67635b462045 Uploaded
jfb
parents:
diff changeset
83 int index = motif.index;
67635b462045 Uploaded
jfb
parents:
diff changeset
84 //changing the numbers for index only changed where in the excel doc these motifs
67635b462045 Uploaded
jfb
parents:
diff changeset
85 //showed up
67635b462045 Uploaded
jfb
parents:
diff changeset
86 //I should fuck with this and try to reallign it
67635b462045 Uploaded
jfb
parents:
diff changeset
87 //I should do that now
67635b462045 Uploaded
jfb
parents:
diff changeset
88 if (index < 8) {
67635b462045 Uploaded
jfb
parents:
diff changeset
89 for (int i = index; i < 8; i++) {
67635b462045 Uploaded
jfb
parents:
diff changeset
90 detail += ",";
67635b462045 Uploaded
jfb
parents:
diff changeset
91 }
67635b462045 Uploaded
jfb
parents:
diff changeset
92 for (int j = 0; j < seq.length(); j++) {
67635b462045 Uploaded
jfb
parents:
diff changeset
93 detail += seq.charAt(j) + ",";
67635b462045 Uploaded
jfb
parents:
diff changeset
94 }
67635b462045 Uploaded
jfb
parents:
diff changeset
95 if (seq.length() - index < 7) {
67635b462045 Uploaded
jfb
parents:
diff changeset
96 for (int i = seq.length() - index; i < 7; i++) {
67635b462045 Uploaded
jfb
parents:
diff changeset
97 detail += ",";
67635b462045 Uploaded
jfb
parents:
diff changeset
98 }
67635b462045 Uploaded
jfb
parents:
diff changeset
99 }
67635b462045 Uploaded
jfb
parents:
diff changeset
100 } else if (seq.length() < 15) {
67635b462045 Uploaded
jfb
parents:
diff changeset
101 for (int j = 0; j < seq.length(); j++) {
67635b462045 Uploaded
jfb
parents:
diff changeset
102 detail += seq.charAt(j) + ",";
67635b462045 Uploaded
jfb
parents:
diff changeset
103 }
67635b462045 Uploaded
jfb
parents:
diff changeset
104 for (int i = seq.length(); i < 15; i++) {
67635b462045 Uploaded
jfb
parents:
diff changeset
105 detail += ",";
67635b462045 Uploaded
jfb
parents:
diff changeset
106 }
67635b462045 Uploaded
jfb
parents:
diff changeset
107
67635b462045 Uploaded
jfb
parents:
diff changeset
108 } else {
67635b462045 Uploaded
jfb
parents:
diff changeset
109 for (int j = 0; j < seq.length(); j++) {
67635b462045 Uploaded
jfb
parents:
diff changeset
110 detail += seq.charAt(j) + ",";
67635b462045 Uploaded
jfb
parents:
diff changeset
111 }
67635b462045 Uploaded
jfb
parents:
diff changeset
112 }
67635b462045 Uploaded
jfb
parents:
diff changeset
113
67635b462045 Uploaded
jfb
parents:
diff changeset
114 //
67635b462045 Uploaded
jfb
parents:
diff changeset
115 // if (index < 5) {
67635b462045 Uploaded
jfb
parents:
diff changeset
116 // for (int i = index; i < 5; i++) {
67635b462045 Uploaded
jfb
parents:
diff changeset
117 // detail += ",";
67635b462045 Uploaded
jfb
parents:
diff changeset
118 // }
67635b462045 Uploaded
jfb
parents:
diff changeset
119 // for (int j = 0; j < seq.length(); j++) {
67635b462045 Uploaded
jfb
parents:
diff changeset
120 // detail += seq.charAt(j) + ",";
67635b462045 Uploaded
jfb
parents:
diff changeset
121 // }
67635b462045 Uploaded
jfb
parents:
diff changeset
122 // if (seq.length() - index < 4) {
67635b462045 Uploaded
jfb
parents:
diff changeset
123 // for (int i = seq.length() - index; i < 4; i++) {
67635b462045 Uploaded
jfb
parents:
diff changeset
124 // detail += ",";
67635b462045 Uploaded
jfb
parents:
diff changeset
125 // }
67635b462045 Uploaded
jfb
parents:
diff changeset
126 // }
67635b462045 Uploaded
jfb
parents:
diff changeset
127 // } else if (seq.length() < 9) {
67635b462045 Uploaded
jfb
parents:
diff changeset
128 // for (int j = 0; j < seq.length(); j++) {
67635b462045 Uploaded
jfb
parents:
diff changeset
129 // detail += seq.charAt(j) + ",";
67635b462045 Uploaded
jfb
parents:
diff changeset
130 // }
67635b462045 Uploaded
jfb
parents:
diff changeset
131 // for (int i = seq.length(); i < 9; i++) {
67635b462045 Uploaded
jfb
parents:
diff changeset
132 // detail += ",";
67635b462045 Uploaded
jfb
parents:
diff changeset
133 // }
67635b462045 Uploaded
jfb
parents:
diff changeset
134 //
67635b462045 Uploaded
jfb
parents:
diff changeset
135 // } else {
67635b462045 Uploaded
jfb
parents:
diff changeset
136 // for (int j = 0; j < seq.length(); j++) {
67635b462045 Uploaded
jfb
parents:
diff changeset
137 // detail += seq.charAt(j) + ",";
67635b462045 Uploaded
jfb
parents:
diff changeset
138 // }
67635b462045 Uploaded
jfb
parents:
diff changeset
139 // }
67635b462045 Uploaded
jfb
parents:
diff changeset
140 ////////////////////////////////////////////////////////////////////////////////
67635b462045 Uploaded
jfb
parents:
diff changeset
141 /** Format trailing blanks */
67635b462045 Uploaded
jfb
parents:
diff changeset
142 detail += "," + "," + "," + seq + ",";
67635b462045 Uploaded
jfb
parents:
diff changeset
143
67635b462045 Uploaded
jfb
parents:
diff changeset
144 for (String id : motif.regenSeqs){
67635b462045 Uploaded
jfb
parents:
diff changeset
145 detail += id + ",";
67635b462045 Uploaded
jfb
parents:
diff changeset
146 }
67635b462045 Uploaded
jfb
parents:
diff changeset
147 detail += "\n";
67635b462045 Uploaded
jfb
parents:
diff changeset
148
67635b462045 Uploaded
jfb
parents:
diff changeset
149 /** Append each line of the report. */
67635b462045 Uploaded
jfb
parents:
diff changeset
150 writer.append(detail);
67635b462045 Uploaded
jfb
parents:
diff changeset
151 }
67635b462045 Uploaded
jfb
parents:
diff changeset
152
67635b462045 Uploaded
jfb
parents:
diff changeset
153 writer.flush();
67635b462045 Uploaded
jfb
parents:
diff changeset
154 writer.close();
67635b462045 Uploaded
jfb
parents:
diff changeset
155
67635b462045 Uploaded
jfb
parents:
diff changeset
156 } catch (IOException e) {
67635b462045 Uploaded
jfb
parents:
diff changeset
157 e.printStackTrace();
67635b462045 Uploaded
jfb
parents:
diff changeset
158 }
67635b462045 Uploaded
jfb
parents:
diff changeset
159 }
67635b462045 Uploaded
jfb
parents:
diff changeset
160
67635b462045 Uploaded
jfb
parents:
diff changeset
161 /**
67635b462045 Uploaded
jfb
parents:
diff changeset
162 * Write substrates background frequency report from each protein in the
67635b462045 Uploaded
jfb
parents:
diff changeset
163 * database.
67635b462045 Uploaded
jfb
parents:
diff changeset
164 *
67635b462045 Uploaded
jfb
parents:
diff changeset
165 * @param run
67635b462045 Uploaded
jfb
parents:
diff changeset
166 * @param outputFileName
67635b462045 Uploaded
jfb
parents:
diff changeset
167 */
67635b462045 Uploaded
jfb
parents:
diff changeset
168 private static void frequencies(Run run, String outputFileName) {
67635b462045 Uploaded
jfb
parents:
diff changeset
169
67635b462045 Uploaded
jfb
parents:
diff changeset
170 /** Initialize the header */
67635b462045 Uploaded
jfb
parents:
diff changeset
171 StringBuffer header = new StringBuffer();
67635b462045 Uploaded
jfb
parents:
diff changeset
172 header.append("Amino Acids,");
67635b462045 Uploaded
jfb
parents:
diff changeset
173
67635b462045 Uploaded
jfb
parents:
diff changeset
174 /** Write each protein accession. */
67635b462045 Uploaded
jfb
parents:
diff changeset
175 Object[] prots = run.database.keySet().toArray();
67635b462045 Uploaded
jfb
parents:
diff changeset
176 for (Object ref : prots) {
67635b462045 Uploaded
jfb
parents:
diff changeset
177 header.append(ref).append(",");
67635b462045 Uploaded
jfb
parents:
diff changeset
178 }
67635b462045 Uploaded
jfb
parents:
diff changeset
179 header.append("\n");
67635b462045 Uploaded
jfb
parents:
diff changeset
180
67635b462045 Uploaded
jfb
parents:
diff changeset
181 try (FileWriter writer = new FileWriter(outputFileName)) {
67635b462045 Uploaded
jfb
parents:
diff changeset
182
67635b462045 Uploaded
jfb
parents:
diff changeset
183 /* Write the column headers. */
67635b462045 Uploaded
jfb
parents:
diff changeset
184 writer.append(header);
67635b462045 Uploaded
jfb
parents:
diff changeset
185
67635b462045 Uploaded
jfb
parents:
diff changeset
186 Collection<Protein> proteins = run.database.values();
67635b462045 Uploaded
jfb
parents:
diff changeset
187
67635b462045 Uploaded
jfb
parents:
diff changeset
188 /** Write frequency of each amino acid. */
67635b462045 Uploaded
jfb
parents:
diff changeset
189 for (char acid : AminoAcid.ACIDS) {
67635b462045 Uploaded
jfb
parents:
diff changeset
190 StringBuffer detail = new StringBuffer();
67635b462045 Uploaded
jfb
parents:
diff changeset
191 detail.append(acid).append(",");
67635b462045 Uploaded
jfb
parents:
diff changeset
192 for (Protein protein : proteins) {
67635b462045 Uploaded
jfb
parents:
diff changeset
193 detail.append(protein.comp.get(acid)).append(",");
67635b462045 Uploaded
jfb
parents:
diff changeset
194 }
67635b462045 Uploaded
jfb
parents:
diff changeset
195 detail.append("\n");
67635b462045 Uploaded
jfb
parents:
diff changeset
196 writer.append(detail);
67635b462045 Uploaded
jfb
parents:
diff changeset
197 }
67635b462045 Uploaded
jfb
parents:
diff changeset
198
67635b462045 Uploaded
jfb
parents:
diff changeset
199 writer.append("Properties\n");
67635b462045 Uploaded
jfb
parents:
diff changeset
200
67635b462045 Uploaded
jfb
parents:
diff changeset
201 /** Write the property frequency of each amino acid. */
67635b462045 Uploaded
jfb
parents:
diff changeset
202 for (String prop : AminoAcid.PROPS) {
67635b462045 Uploaded
jfb
parents:
diff changeset
203 StringBuffer props = new StringBuffer();
67635b462045 Uploaded
jfb
parents:
diff changeset
204 props.append(prop).append(",");
67635b462045 Uploaded
jfb
parents:
diff changeset
205 for (Protein protein : proteins) {
67635b462045 Uploaded
jfb
parents:
diff changeset
206 props.append(protein.props.get(prop)).append(",");
67635b462045 Uploaded
jfb
parents:
diff changeset
207 }
67635b462045 Uploaded
jfb
parents:
diff changeset
208 props.append("\n");
67635b462045 Uploaded
jfb
parents:
diff changeset
209 writer.append(props);
67635b462045 Uploaded
jfb
parents:
diff changeset
210 }
67635b462045 Uploaded
jfb
parents:
diff changeset
211
67635b462045 Uploaded
jfb
parents:
diff changeset
212 writer.append("\n");
67635b462045 Uploaded
jfb
parents:
diff changeset
213
67635b462045 Uploaded
jfb
parents:
diff changeset
214 StringBuffer tyr = new StringBuffer("Number of Y,");
67635b462045 Uploaded
jfb
parents:
diff changeset
215 StringBuffer phosphTyr = new StringBuffer("Number of pY,");
67635b462045 Uploaded
jfb
parents:
diff changeset
216 StringBuffer aa = new StringBuffer("Total AAs,");
67635b462045 Uploaded
jfb
parents:
diff changeset
217
67635b462045 Uploaded
jfb
parents:
diff changeset
218 /** Write the number of tyrosine, phospho-tyrosine, and length. */
67635b462045 Uploaded
jfb
parents:
diff changeset
219 for (Protein protein : proteins) {
67635b462045 Uploaded
jfb
parents:
diff changeset
220 tyr.append(protein.numTyr).append(",");
67635b462045 Uploaded
jfb
parents:
diff changeset
221 phosphTyr.append(protein.phosphoTyr).append(",");
67635b462045 Uploaded
jfb
parents:
diff changeset
222 aa.append(protein.seq.length()).append(",");
67635b462045 Uploaded
jfb
parents:
diff changeset
223 }
67635b462045 Uploaded
jfb
parents:
diff changeset
224
67635b462045 Uploaded
jfb
parents:
diff changeset
225 writer.append(tyr + "\n");
67635b462045 Uploaded
jfb
parents:
diff changeset
226 writer.append(phosphTyr + "\n");
67635b462045 Uploaded
jfb
parents:
diff changeset
227 writer.append(aa + "\n");
67635b462045 Uploaded
jfb
parents:
diff changeset
228
67635b462045 Uploaded
jfb
parents:
diff changeset
229 writer.flush();
67635b462045 Uploaded
jfb
parents:
diff changeset
230 writer.close();
67635b462045 Uploaded
jfb
parents:
diff changeset
231
67635b462045 Uploaded
jfb
parents:
diff changeset
232 } catch (IOException e) {
67635b462045 Uploaded
jfb
parents:
diff changeset
233 e.printStackTrace();
67635b462045 Uploaded
jfb
parents:
diff changeset
234 }
67635b462045 Uploaded
jfb
parents:
diff changeset
235 }
67635b462045 Uploaded
jfb
parents:
diff changeset
236 }