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