3700 |
07 May 10 |
fredrik |
1 |
package satoshi; |
3700 |
07 May 10 |
fredrik |
2 |
|
3700 |
07 May 10 |
fredrik |
3 |
import org.proteios.core.BaseException; |
3700 |
07 May 10 |
fredrik |
4 |
import org.proteios.core.DbControl; |
3700 |
07 May 10 |
fredrik |
5 |
import org.proteios.core.Directory; |
3700 |
07 May 10 |
fredrik |
6 |
import org.proteios.core.File; |
3700 |
07 May 10 |
fredrik |
7 |
import org.proteios.core.FileType; |
3700 |
07 May 10 |
fredrik |
8 |
import org.proteios.core.Hit; |
3700 |
07 May 10 |
fredrik |
9 |
import org.proteios.core.ItemFactory; |
3700 |
07 May 10 |
fredrik |
10 |
import org.proteios.core.ItemQuery; |
3700 |
07 May 10 |
fredrik |
11 |
import org.proteios.core.ItemResultList; |
4300 |
13 Mar 12 |
fredrik |
12 |
import org.proteios.core.ObservedModification; |
3700 |
07 May 10 |
fredrik |
13 |
import org.proteios.core.Peptide; |
3700 |
07 May 10 |
fredrik |
14 |
import org.proteios.core.Permission; |
3700 |
07 May 10 |
fredrik |
15 |
import org.proteios.core.PermissionDeniedException; |
3700 |
07 May 10 |
fredrik |
16 |
import org.proteios.core.ProgressReporter; |
3700 |
07 May 10 |
fredrik |
17 |
import org.proteios.core.Project; |
4300 |
13 Mar 12 |
fredrik |
18 |
import org.proteios.core.SearchModification; |
3700 |
07 May 10 |
fredrik |
19 |
import org.proteios.core.SessionControl; |
3700 |
07 May 10 |
fredrik |
20 |
import org.proteios.core.plugin.About; |
3700 |
07 May 10 |
fredrik |
21 |
import org.proteios.core.plugin.AboutImpl; |
3700 |
07 May 10 |
fredrik |
22 |
import org.proteios.core.plugin.AbstractPlugin; |
3700 |
07 May 10 |
fredrik |
23 |
import org.proteios.core.plugin.ParameterValues; |
3700 |
07 May 10 |
fredrik |
24 |
import org.proteios.core.plugin.Plugin; |
3700 |
07 May 10 |
fredrik |
25 |
import org.proteios.core.plugin.Request; |
3700 |
07 May 10 |
fredrik |
26 |
import org.proteios.core.plugin.Response; |
3700 |
07 May 10 |
fredrik |
27 |
import org.proteios.core.query.Expressions; |
3700 |
07 May 10 |
fredrik |
28 |
import org.proteios.core.query.Hql; |
4300 |
13 Mar 12 |
fredrik |
29 |
import org.proteios.core.query.Orders; |
3700 |
07 May 10 |
fredrik |
30 |
import org.proteios.core.query.Restrictions; |
3700 |
07 May 10 |
fredrik |
31 |
import org.proteios.io.MgfFileReader; |
4328 |
08 May 12 |
fredrik |
32 |
import org.proteios.io.MzMLFileReader; |
3700 |
07 May 10 |
fredrik |
33 |
import org.proteios.io.PeakListFileImpl; |
3700 |
07 May 10 |
fredrik |
34 |
import org.proteios.io.PeakListFileInterface; |
3700 |
07 May 10 |
fredrik |
35 |
import org.proteios.io.SpectrumInterface; |
3700 |
07 May 10 |
fredrik |
36 |
import org.proteios.io.SpectrumPrecursor; |
3700 |
07 May 10 |
fredrik |
37 |
|
4545 |
26 Feb 14 |
fredrik |
38 |
import se.lth.immun.chem.Ion; |
4545 |
26 Feb 14 |
fredrik |
39 |
import se.lth.immun.chem.ModifiedAminoAcid; |
4545 |
26 Feb 14 |
fredrik |
40 |
import se.lth.immun.chem.Modifier; |
4545 |
26 Feb 14 |
fredrik |
41 |
import se.lth.immun.chem.PeptideFragment; |
4545 |
26 Feb 14 |
fredrik |
42 |
import se.lth.immun.chem.PeptideUtil; |
4545 |
26 Feb 14 |
fredrik |
43 |
|
3700 |
07 May 10 |
fredrik |
44 |
import java.io.BufferedWriter; |
4300 |
13 Mar 12 |
fredrik |
45 |
import java.io.IOException; |
3700 |
07 May 10 |
fredrik |
46 |
import java.io.OutputStream; |
3700 |
07 May 10 |
fredrik |
47 |
import java.io.OutputStreamWriter; |
3700 |
07 May 10 |
fredrik |
48 |
import java.text.DecimalFormat; |
3772 |
17 Aug 10 |
fredrik |
49 |
import java.text.DecimalFormatSymbols; |
3700 |
07 May 10 |
fredrik |
50 |
import java.util.ArrayList; |
4300 |
13 Mar 12 |
fredrik |
51 |
import java.util.Collections; |
4300 |
13 Mar 12 |
fredrik |
52 |
import java.util.Comparator; |
3700 |
07 May 10 |
fredrik |
53 |
import java.util.Iterator; |
3700 |
07 May 10 |
fredrik |
54 |
import java.util.List; |
3772 |
17 Aug 10 |
fredrik |
55 |
import java.util.Locale; |
3700 |
07 May 10 |
fredrik |
56 |
|
3700 |
07 May 10 |
fredrik |
57 |
/** |
3700 |
07 May 10 |
fredrik |
* This is a plugin for export of Spectrum libraries from search results |
3700 |
07 May 10 |
fredrik |
59 |
* |
3700 |
07 May 10 |
fredrik |
* @author satoshi |
3700 |
07 May 10 |
fredrik |
61 |
*/ |
4338 |
25 Jun 12 |
fredrik |
62 |
public class LibraryExportPlugin extends AbstractPlugin implements Plugin |
3700 |
07 May 10 |
fredrik |
63 |
|
3700 |
07 May 10 |
fredrik |
64 |
{ |
3700 |
07 May 10 |
fredrik |
65 |
private static final org.apache.log4j.Logger log = org.apache.log4j.LogManager |
4338 |
25 Jun 12 |
fredrik |
66 |
.getLogger("org.proteios.io"); |
3700 |
07 May 10 |
fredrik |
67 |
|
3700 |
07 May 10 |
fredrik |
68 |
/** |
3700 |
07 May 10 |
fredrik |
* Key to identify the file parameter. The action that creates a job using |
3700 |
07 May 10 |
fredrik |
* this plugin should name the incomming file parameter with this key. |
3700 |
07 May 10 |
fredrik |
71 |
*/ |
3700 |
07 May 10 |
fredrik |
// public static final String FILEPARAM = "file"; |
3700 |
07 May 10 |
fredrik |
73 |
public static final String OUTFILEPARAM = "outfile"; |
3700 |
07 May 10 |
fredrik |
74 |
public static final String OUTFILEPARAM2 = "outfile2"; |
3700 |
07 May 10 |
fredrik |
75 |
public static final String FDRCUTOFFPARAM = "fdrCutOff"; |
4264 |
26 Oct 11 |
fredrik |
76 |
public static final String SSLPARAM = "sslFormat"; |
3700 |
07 May 10 |
fredrik |
77 |
public static final String MSPPARAM = "mspFormat"; |
4545 |
26 Feb 14 |
fredrik |
78 |
public static final String EVALUEPARAM = "eValue"; |
4545 |
26 Feb 14 |
fredrik |
79 |
public static final String FRAGMENTTOLERANCEPARAM = "fragTol"; |
3700 |
07 May 10 |
fredrik |
80 |
private static final Double MONOISTOPIC_PROTON_MASS = 1.007276035; |
3700 |
07 May 10 |
fredrik |
81 |
|
3700 |
07 May 10 |
fredrik |
82 |
/** |
3700 |
07 May 10 |
fredrik |
* // parameters to be imported. |
3700 |
07 May 10 |
fredrik |
84 |
* |
3700 |
07 May 10 |
fredrik |
* @see #init(SessionControl, ParameterValues, ParameterValues) |
3700 |
07 May 10 |
fredrik |
86 |
*/ |
3700 |
07 May 10 |
fredrik |
// private File file = null; |
3700 |
07 May 10 |
fredrik |
88 |
private String outfile = null; |
3700 |
07 May 10 |
fredrik |
89 |
private String outfile2 = null; |
3700 |
07 May 10 |
fredrik |
90 |
private double fdrCutOff = 0.01; // default 0.01 |
3700 |
07 May 10 |
fredrik |
91 |
private boolean mgfFormat = true; // to be used for X!hunter |
3700 |
07 May 10 |
fredrik |
92 |
private boolean mspFormat = true; // to be used for SpectraSt |
4264 |
26 Oct 11 |
fredrik |
93 |
private boolean sslFormat = true; |
4545 |
26 Feb 14 |
fredrik |
94 |
private boolean eValue = false; |
3700 |
07 May 10 |
fredrik |
// other variables |
3700 |
07 May 10 |
fredrik |
96 |
private Project project = null; |
3700 |
07 May 10 |
fredrik |
97 |
private boolean fileNameAssigned = false; |
3700 |
07 May 10 |
fredrik |
98 |
private boolean fileNameAssigned2 = false; |
4264 |
26 Oct 11 |
fredrik |
99 |
private int spectrumNumber = 1; |
4545 |
26 Feb 14 |
fredrik |
100 |
private double mzTolerance = 0.5d; |
3700 |
07 May 10 |
fredrik |
101 |
|
3700 |
07 May 10 |
fredrik |
// SessionControl sc; // instantiated below |
3700 |
07 May 10 |
fredrik |
103 |
|
3700 |
07 May 10 |
fredrik |
104 |
/* |
3700 |
07 May 10 |
fredrik |
* (non-Javadoc) |
4338 |
25 Jun 12 |
fredrik |
106 |
* |
3700 |
07 May 10 |
fredrik |
* @see org.proteios.core.plugin.Plugin#getAbout() |
3700 |
07 May 10 |
fredrik |
108 |
*/ |
4338 |
25 Jun 12 |
fredrik |
109 |
public About getAbout() { |
3700 |
07 May 10 |
fredrik |
110 |
return new AboutImpl("Spectrum Library export", |
4338 |
25 Jun 12 |
fredrik |
111 |
"Export spectrum library from hits", "0.3", "", |
4338 |
25 Jun 12 |
fredrik |
112 |
"Satoshi Okawa", "", "www.proteios.org"); |
3700 |
07 May 10 |
fredrik |
113 |
} |
3700 |
07 May 10 |
fredrik |
114 |
|
3700 |
07 May 10 |
fredrik |
115 |
/* |
3700 |
07 May 10 |
fredrik |
* (non-Javadoc) |
4338 |
25 Jun 12 |
fredrik |
117 |
* |
3700 |
07 May 10 |
fredrik |
* @see org.proteios.core.plugin.Plugin#getMainType() |
3700 |
07 May 10 |
fredrik |
119 |
*/ |
4338 |
25 Jun 12 |
fredrik |
120 |
public MainType getMainType() { |
3700 |
07 May 10 |
fredrik |
121 |
return MainType.EXPORT; |
3700 |
07 May 10 |
fredrik |
122 |
} |
3700 |
07 May 10 |
fredrik |
123 |
|
3700 |
07 May 10 |
fredrik |
124 |
public void init(SessionControl sc, ParameterValues configuration, |
4338 |
25 Jun 12 |
fredrik |
125 |
ParameterValues job) throws BaseException { |
3700 |
07 May 10 |
fredrik |
126 |
super.init(sc, configuration, job); |
3700 |
07 May 10 |
fredrik |
// this.sc = sc; |
3700 |
07 May 10 |
fredrik |
// Before running this plugin it's initialized here. |
3700 |
07 May 10 |
fredrik |
129 |
} |
3700 |
07 May 10 |
fredrik |
130 |
|
3700 |
07 May 10 |
fredrik |
131 |
/* |
3700 |
07 May 10 |
fredrik |
* (non-Javadoc) |
4338 |
25 Jun 12 |
fredrik |
133 |
* |
3700 |
07 May 10 |
fredrik |
* @see |
3700 |
07 May 10 |
fredrik |
* org.proteios.core.plugin.Plugin#run(org.proteios.core.plugin.Request, |
3700 |
07 May 10 |
fredrik |
* org.proteios.core.plugin.Response, org.proteios.core.ProgressReporter) |
3700 |
07 May 10 |
fredrik |
137 |
*/ |
3700 |
07 May 10 |
fredrik |
138 |
public void run(Request request, Response response, |
4338 |
25 Jun 12 |
fredrik |
139 |
ProgressReporter progress) { |
3700 |
07 May 10 |
fredrik |
140 |
String command = request.getCommand(); |
4338 |
25 Jun 12 |
fredrik |
141 |
if (command.equals(Request.COMMAND_EXECUTE)) { |
3700 |
07 May 10 |
fredrik |
142 |
Directory outCoreDir = (Directory) job.getValue("directory"); |
3700 |
07 May 10 |
fredrik |
143 |
project = (Project) job.getValue("project"); |
4264 |
26 Oct 11 |
fredrik |
144 |
log.info("Library export for project:" + project); |
3700 |
07 May 10 |
fredrik |
145 |
String filename = (String) job.getValue(OUTFILEPARAM); |
3700 |
07 May 10 |
fredrik |
146 |
String filename2 = (String) job.getValue(OUTFILEPARAM2); // for .msp |
3700 |
07 May 10 |
fredrik |
147 |
fdrCutOff = ((Float) job.getValue(FDRCUTOFFPARAM)).doubleValue(); |
4545 |
26 Feb 14 |
fredrik |
148 |
mzTolerance = ((Float) job.getValue(FRAGMENTTOLERANCEPARAM)).doubleValue(); |
4264 |
26 Oct 11 |
fredrik |
149 |
mgfFormat = false; |
4264 |
26 Oct 11 |
fredrik |
150 |
sslFormat = ((Boolean) job.getValue(SSLPARAM)).booleanValue(); |
3700 |
07 May 10 |
fredrik |
151 |
mspFormat = ((Boolean) job.getValue(MSPPARAM)).booleanValue(); |
4545 |
26 Feb 14 |
fredrik |
152 |
eValue = ((Boolean) job.getValue(EVALUEPARAM)).booleanValue(); |
3700 |
07 May 10 |
fredrik |
153 |
if (filename == null && filename2 == null) // stop |
3700 |
07 May 10 |
fredrik |
154 |
{ |
4338 |
25 Jun 12 |
fredrik |
155 |
throw new BaseException("Failed to initialize job. [outfile=" |
4338 |
25 Jun 12 |
fredrik |
156 |
+ filename + "][fdrCutOff=" + fdrCutOff + "]"); |
3700 |
07 May 10 |
fredrik |
157 |
} |
3700 |
07 May 10 |
fredrik |
158 |
|
4338 |
25 Jun 12 |
fredrik |
159 |
if (outCoreDir == null) { |
4338 |
25 Jun 12 |
fredrik |
160 |
throw new BaseException("Failed to initialize job. [outfile=" |
4338 |
25 Jun 12 |
fredrik |
161 |
+ outCoreDir + "][fdrCutOff=" + fdrCutOff + "]"); |
3700 |
07 May 10 |
fredrik |
162 |
} |
3700 |
07 May 10 |
fredrik |
163 |
doExport(outCoreDir, filename, filename2, progress); |
3700 |
07 May 10 |
fredrik |
164 |
/* |
3700 |
07 May 10 |
fredrik |
* Add the prefix to the file. This is where you'd put your fancy |
3700 |
07 May 10 |
fredrik |
* algorithm that does something to the file in question. |
3700 |
07 May 10 |
fredrik |
167 |
*/ |
3700 |
07 May 10 |
fredrik |
// file.setName(prefix + file.getName()); |
3700 |
07 May 10 |
fredrik |
// file.getDbControl().commit(); |
3700 |
07 May 10 |
fredrik |
170 |
response.setDone(getSuccessMessage()); |
4338 |
25 Jun 12 |
fredrik |
171 |
} else { |
3700 |
07 May 10 |
fredrik |
172 |
response.setError("Unknown command: " + command, null); |
3700 |
07 May 10 |
fredrik |
173 |
} |
3700 |
07 May 10 |
fredrik |
174 |
} |
3700 |
07 May 10 |
fredrik |
175 |
|
3700 |
07 May 10 |
fredrik |
176 |
/** |
3700 |
07 May 10 |
fredrik |
* Called if successful to let the subclass generate a simple message that |
3700 |
07 May 10 |
fredrik |
* is sent back to the core and user interface. The default implementation |
3700 |
07 May 10 |
fredrik |
* always returns null. |
3700 |
07 May 10 |
fredrik |
180 |
* |
3700 |
07 May 10 |
fredrik |
* @return String with success message. |
3700 |
07 May 10 |
fredrik |
182 |
*/ |
4338 |
25 Jun 12 |
fredrik |
183 |
protected String getSuccessMessage() { |
3779 |
18 Aug 10 |
fredrik |
184 |
String retval = "Done."; |
3779 |
18 Aug 10 |
fredrik |
185 |
if (outfile != null) |
3779 |
18 Aug 10 |
fredrik |
186 |
retval += " Library exported: " + outfile; |
3779 |
18 Aug 10 |
fredrik |
187 |
if (outfile2 != null) |
3779 |
18 Aug 10 |
fredrik |
188 |
retval += " Library exported: " + outfile2; |
3779 |
18 Aug 10 |
fredrik |
189 |
return retval; |
3700 |
07 May 10 |
fredrik |
190 |
} |
3700 |
07 May 10 |
fredrik |
191 |
|
3700 |
07 May 10 |
fredrik |
192 |
/** |
3700 |
07 May 10 |
fredrik |
* Checks before file writing |
3700 |
07 May 10 |
fredrik |
194 |
*/ |
3700 |
07 May 10 |
fredrik |
195 |
public void doExport(Directory outCoreDir, String filename, |
4338 |
25 Jun 12 |
fredrik |
196 |
String filename2, ProgressReporter progress) throws BaseException { |
3700 |
07 May 10 |
fredrik |
197 |
/* |
3700 |
07 May 10 |
fredrik |
* Check if output core directory exists. If so, try to create a core |
3700 |
07 May 10 |
fredrik |
* file in it with specified filename. If a previous core file already |
3700 |
07 May 10 |
fredrik |
* exists with the desired name, try again with a counter of type "_001" |
3700 |
07 May 10 |
fredrik |
* added to the base filename (base filename = filename without file |
3700 |
07 May 10 |
fredrik |
* extension). |
3700 |
07 May 10 |
fredrik |
203 |
*/ |
3700 |
07 May 10 |
fredrik |
204 |
/* |
3700 |
07 May 10 |
fredrik |
* Check if core output directory may be written to. |
3700 |
07 May 10 |
fredrik |
206 |
*/ |
4338 |
25 Jun 12 |
fredrik |
207 |
try { |
3700 |
07 May 10 |
fredrik |
208 |
outCoreDir.checkPermission(Permission.WRITE); |
4338 |
25 Jun 12 |
fredrik |
209 |
} catch (PermissionDeniedException e) { |
4338 |
25 Jun 12 |
fredrik |
210 |
log.warn("You do not have permission to write to directory " |
4338 |
25 Jun 12 |
fredrik |
211 |
+ outCoreDir.getName() + ": " + e); |
3700 |
07 May 10 |
fredrik |
212 |
throw new BaseException(e); |
3700 |
07 May 10 |
fredrik |
213 |
} |
3700 |
07 May 10 |
fredrik |
214 |
/* |
3700 |
07 May 10 |
fredrik |
* Find unique filename to use. |
3700 |
07 May 10 |
fredrik |
216 |
*/ |
3700 |
07 May 10 |
fredrik |
217 |
DbControl dc = sc.newDbControl(); |
3700 |
07 May 10 |
fredrik |
218 |
ItemFactory factory = new ItemFactory(dc); |
3700 |
07 May 10 |
fredrik |
219 |
String coreFilename = new String(filename); |
3700 |
07 May 10 |
fredrik |
220 |
String coreFilename2 = new String(filename2); |
3700 |
07 May 10 |
fredrik |
221 |
File outCoreFile = factory.create(File.class); |
3700 |
07 May 10 |
fredrik |
222 |
File outCoreFile2 = factory.create(File.class); |
3700 |
07 May 10 |
fredrik |
223 |
outCoreFile.setName("file"); |
3700 |
07 May 10 |
fredrik |
224 |
outCoreFile2.setName("file2"); |
3700 |
07 May 10 |
fredrik |
225 |
|
3700 |
07 May 10 |
fredrik |
226 |
/* |
3700 |
07 May 10 |
fredrik |
* Extract basename and optional fileextension, including ".". |
3700 |
07 May 10 |
fredrik |
228 |
*/ |
4338 |
25 Jun 12 |
fredrik |
229 |
log.info("testtest:: doExport(): coreFilename = \"" + coreFilename |
4338 |
25 Jun 12 |
fredrik |
230 |
+ "\""); |
3700 |
07 May 10 |
fredrik |
231 |
|
4338 |
25 Jun 12 |
fredrik |
232 |
if (mgfFormat || sslFormat) { |
3700 |
07 May 10 |
fredrik |
233 |
String basename = new String(coreFilename); |
3700 |
07 May 10 |
fredrik |
// If there was no file name suffix we add the following: |
3700 |
07 May 10 |
fredrik |
235 |
String fileextension = new String(".mgf"); |
4338 |
25 Jun 12 |
fredrik |
236 |
if (sslFormat) { |
4264 |
26 Oct 11 |
fredrik |
237 |
fileextension = ".ssl"; |
4264 |
26 Oct 11 |
fredrik |
238 |
} |
3700 |
07 May 10 |
fredrik |
239 |
int dotIndex = coreFilename.lastIndexOf("."); |
3700 |
07 May 10 |
fredrik |
240 |
|
4338 |
25 Jun 12 |
fredrik |
241 |
if (dotIndex >= 0) { |
3700 |
07 May 10 |
fredrik |
242 |
/* |
3700 |
07 May 10 |
fredrik |
* String coreFilename contains at least one ".". |
3700 |
07 May 10 |
fredrik |
244 |
*/ |
3700 |
07 May 10 |
fredrik |
245 |
basename = coreFilename.substring(0, dotIndex); |
4338 |
25 Jun 12 |
fredrik |
246 |
if (dotIndex < coreFilename.length()) { |
3700 |
07 May 10 |
fredrik |
247 |
fileextension = coreFilename.substring(dotIndex); |
3700 |
07 May 10 |
fredrik |
248 |
} |
3700 |
07 May 10 |
fredrik |
249 |
} |
3700 |
07 May 10 |
fredrik |
250 |
|
3700 |
07 May 10 |
fredrik |
251 |
log.info("testtest:: doExport(): basename = \"" + basename + "\""); |
4338 |
25 Jun 12 |
fredrik |
252 |
log.info("testtest:: doExport(): fileextension = \"" |
4338 |
25 Jun 12 |
fredrik |
253 |
+ fileextension + "\""); |
3700 |
07 May 10 |
fredrik |
254 |
int counter = 0; |
3700 |
07 May 10 |
fredrik |
255 |
coreFilename = basename + fileextension; |
4338 |
25 Jun 12 |
fredrik |
256 |
while (File.exists(dc, outCoreDir, coreFilename)) { |
3700 |
07 May 10 |
fredrik |
257 |
/* |
3700 |
07 May 10 |
fredrik |
* Append counter of type "_001" to base filename, and try |
3700 |
07 May 10 |
fredrik |
* again. |
3700 |
07 May 10 |
fredrik |
260 |
*/ |
3700 |
07 May 10 |
fredrik |
261 |
counter++; |
3700 |
07 May 10 |
fredrik |
262 |
String counterStr = new String("_"); |
4338 |
25 Jun 12 |
fredrik |
263 |
if (counter < 100) { |
3700 |
07 May 10 |
fredrik |
264 |
counterStr = counterStr + "0"; |
3700 |
07 May 10 |
fredrik |
265 |
} |
4338 |
25 Jun 12 |
fredrik |
266 |
if (counter < 10) { |
3700 |
07 May 10 |
fredrik |
267 |
counterStr = counterStr + "0"; |
3700 |
07 May 10 |
fredrik |
268 |
} |
3700 |
07 May 10 |
fredrik |
269 |
counterStr = counterStr + Integer.toString(counter); |
3700 |
07 May 10 |
fredrik |
270 |
|
4338 |
25 Jun 12 |
fredrik |
271 |
log.info("testtest:: doExport(): counterStr = \"" + counterStr |
4338 |
25 Jun 12 |
fredrik |
272 |
+ "\""); |
3700 |
07 May 10 |
fredrik |
273 |
/* |
3700 |
07 May 10 |
fredrik |
* Get new trial core filename. |
3700 |
07 May 10 |
fredrik |
275 |
*/ |
3700 |
07 May 10 |
fredrik |
276 |
coreFilename = basename + counterStr + fileextension; |
4338 |
25 Jun 12 |
fredrik |
277 |
log.info("testtest:: doExport(): trial coreFilename = \"" |
4338 |
25 Jun 12 |
fredrik |
278 |
+ coreFilename + "\""); |
3700 |
07 May 10 |
fredrik |
279 |
} |
3700 |
07 May 10 |
fredrik |
280 |
/* |
3700 |
07 May 10 |
fredrik |
* Create the new core file. |
3700 |
07 May 10 |
fredrik |
282 |
*/ |
3700 |
07 May 10 |
fredrik |
283 |
outCoreFile.setDirectory(outCoreDir); |
3700 |
07 May 10 |
fredrik |
284 |
/* |
3700 |
07 May 10 |
fredrik |
* There should be no problems naming the new core file now. |
3700 |
07 May 10 |
fredrik |
286 |
*/ |
3700 |
07 May 10 |
fredrik |
287 |
outCoreFile.setName(coreFilename); |
3700 |
07 May 10 |
fredrik |
288 |
fileNameAssigned = true; |
3700 |
07 May 10 |
fredrik |
289 |
/* |
3700 |
07 May 10 |
fredrik |
* Save core file item before getting uploadstream |
3700 |
07 May 10 |
fredrik |
291 |
*/ |
3700 |
07 May 10 |
fredrik |
292 |
dc.saveItem(outCoreFile); |
3700 |
07 May 10 |
fredrik |
293 |
/* |
3700 |
07 May 10 |
fredrik |
* Call doExport(File, ProgressReporter) to export the PeakListSet |
3700 |
07 May 10 |
fredrik |
* data to core File. |
3700 |
07 May 10 |
fredrik |
296 |
*/ |
3700 |
07 May 10 |
fredrik |
297 |
outfile = outCoreDir.getName() + "/" + outCoreFile.getName(); |
3700 |
07 May 10 |
fredrik |
298 |
} |
3700 |
07 May 10 |
fredrik |
299 |
|
3700 |
07 May 10 |
fredrik |
// Repeat for .msp file |
4338 |
25 Jun 12 |
fredrik |
301 |
if (mspFormat || sslFormat) { |
3700 |
07 May 10 |
fredrik |
302 |
String basename = new String(coreFilename2); |
3700 |
07 May 10 |
fredrik |
// If there was no file name suffix we add the following: |
3700 |
07 May 10 |
fredrik |
304 |
String fileextension = new String(".msp"); |
4338 |
25 Jun 12 |
fredrik |
305 |
if (sslFormat) { |
4264 |
26 Oct 11 |
fredrik |
306 |
fileextension = ".ssl"; |
4264 |
26 Oct 11 |
fredrik |
307 |
} |
4264 |
26 Oct 11 |
fredrik |
308 |
|
3700 |
07 May 10 |
fredrik |
309 |
int dotIndex = coreFilename2.lastIndexOf("."); |
3700 |
07 May 10 |
fredrik |
310 |
|
4338 |
25 Jun 12 |
fredrik |
311 |
if (dotIndex >= 0) { |
3700 |
07 May 10 |
fredrik |
312 |
/* |
3700 |
07 May 10 |
fredrik |
* String coreFilename contains at least one ".". |
3700 |
07 May 10 |
fredrik |
314 |
*/ |
3700 |
07 May 10 |
fredrik |
315 |
basename = coreFilename2.substring(0, dotIndex); |
4338 |
25 Jun 12 |
fredrik |
316 |
if (dotIndex < coreFilename2.length()) { |
3700 |
07 May 10 |
fredrik |
317 |
fileextension = coreFilename2.substring(dotIndex); |
3700 |
07 May 10 |
fredrik |
318 |
} |
3700 |
07 May 10 |
fredrik |
319 |
} |
3700 |
07 May 10 |
fredrik |
320 |
|
3700 |
07 May 10 |
fredrik |
321 |
log.info("testtest:: doExport(): basename = \"" + basename + "\""); |
4338 |
25 Jun 12 |
fredrik |
322 |
log.info("testtest:: doExport(): fileextension = \"" |
4338 |
25 Jun 12 |
fredrik |
323 |
+ fileextension + "\""); |
3700 |
07 May 10 |
fredrik |
324 |
int counter = 0; |
3700 |
07 May 10 |
fredrik |
325 |
coreFilename2 = basename + fileextension; |
4338 |
25 Jun 12 |
fredrik |
326 |
while (File.exists(dc, outCoreDir, coreFilename2)) { |
3700 |
07 May 10 |
fredrik |
327 |
/* |
3700 |
07 May 10 |
fredrik |
* Append counter of type "_001" to base filename, and try |
3700 |
07 May 10 |
fredrik |
* again. |
3700 |
07 May 10 |
fredrik |
330 |
*/ |
3700 |
07 May 10 |
fredrik |
331 |
counter++; |
3700 |
07 May 10 |
fredrik |
332 |
String counterStr = new String("_"); |
4338 |
25 Jun 12 |
fredrik |
333 |
if (counter < 100) { |
3700 |
07 May 10 |
fredrik |
334 |
counterStr = counterStr + "0"; |
3700 |
07 May 10 |
fredrik |
335 |
} |
4338 |
25 Jun 12 |
fredrik |
336 |
if (counter < 10) { |
3700 |
07 May 10 |
fredrik |
337 |
counterStr = counterStr + "0"; |
3700 |
07 May 10 |
fredrik |
338 |
} |
3700 |
07 May 10 |
fredrik |
339 |
counterStr = counterStr + Integer.toString(counter); |
3700 |
07 May 10 |
fredrik |
340 |
|
4338 |
25 Jun 12 |
fredrik |
341 |
log.info("testtest:: doExport(): counterStr = \"" + counterStr |
4338 |
25 Jun 12 |
fredrik |
342 |
+ "\""); |
3700 |
07 May 10 |
fredrik |
343 |
/* |
3700 |
07 May 10 |
fredrik |
* Get new trial core filename. |
3700 |
07 May 10 |
fredrik |
345 |
*/ |
3700 |
07 May 10 |
fredrik |
346 |
coreFilename2 = basename + counterStr + fileextension; |
4338 |
25 Jun 12 |
fredrik |
347 |
log.info("testtest:: doExport(): trial coreFilename = \"" |
4338 |
25 Jun 12 |
fredrik |
348 |
+ coreFilename2 + "\""); |
3700 |
07 May 10 |
fredrik |
349 |
} |
3700 |
07 May 10 |
fredrik |
350 |
/* |
3700 |
07 May 10 |
fredrik |
* Create the new core file. |
3700 |
07 May 10 |
fredrik |
352 |
*/ |
3700 |
07 May 10 |
fredrik |
// log.debug(">>2" + outCoreFile2 + "\t" + outCoreDir + "\n"); |
3700 |
07 May 10 |
fredrik |
354 |
outCoreFile2.setDirectory(outCoreDir); |
3700 |
07 May 10 |
fredrik |
355 |
/* |
3700 |
07 May 10 |
fredrik |
* There should be no problems naming the new core file now. |
3700 |
07 May 10 |
fredrik |
357 |
*/ |
3700 |
07 May 10 |
fredrik |
358 |
outCoreFile2.setName(coreFilename2); |
3700 |
07 May 10 |
fredrik |
359 |
fileNameAssigned2 = true; |
4547 |
28 Feb 14 |
fredrik |
360 |
outCoreFile2.setMimeType("text/plain"); |
3700 |
07 May 10 |
fredrik |
361 |
/* |
3700 |
07 May 10 |
fredrik |
* Save core file item before getting uploadstream |
3700 |
07 May 10 |
fredrik |
363 |
*/ |
3700 |
07 May 10 |
fredrik |
364 |
dc.saveItem(outCoreFile2); |
3700 |
07 May 10 |
fredrik |
365 |
/* |
3700 |
07 May 10 |
fredrik |
* Call doExport(File, ProgressReporter) to export the PeakListSet |
3700 |
07 May 10 |
fredrik |
* data to core File. |
3700 |
07 May 10 |
fredrik |
368 |
*/ |
3700 |
07 May 10 |
fredrik |
369 |
outfile2 = outCoreDir.getName() + "/" + outCoreFile2.getName(); |
3700 |
07 May 10 |
fredrik |
370 |
} |
3700 |
07 May 10 |
fredrik |
371 |
|
3700 |
07 May 10 |
fredrik |
372 |
doExport(outCoreFile, outCoreFile2, progress); |
3700 |
07 May 10 |
fredrik |
373 |
dc.commit(); |
3700 |
07 May 10 |
fredrik |
374 |
log.info("testtest:: doExport(): commit()"); |
3700 |
07 May 10 |
fredrik |
375 |
} |
3700 |
07 May 10 |
fredrik |
376 |
|
3700 |
07 May 10 |
fredrik |
377 |
/** |
3700 |
07 May 10 |
fredrik |
* Perform the actual table generation and export CombinedHits -> |
3700 |
07 May 10 |
fredrik |
* JobOrPlugin |
3700 |
07 May 10 |
fredrik |
380 |
*/ |
3700 |
07 May 10 |
fredrik |
381 |
|
3700 |
07 May 10 |
fredrik |
382 |
public void doExport(File outCoreFile, File outCoreFile2, |
4338 |
25 Jun 12 |
fredrik |
383 |
ProgressReporter progress) throws BaseException { |
4338 |
25 Jun 12 |
fredrik |
384 |
try { |
3700 |
07 May 10 |
fredrik |
385 |
BufferedWriter output = null; |
3700 |
07 May 10 |
fredrik |
386 |
BufferedWriter output2 = null; |
3700 |
07 May 10 |
fredrik |
387 |
|
4338 |
25 Jun 12 |
fredrik |
388 |
if (fileNameAssigned) { |
3700 |
07 May 10 |
fredrik |
389 |
OutputStream outstream = outCoreFile.getUploadStream(false); |
4264 |
26 Oct 11 |
fredrik |
390 |
output = new BufferedWriter(new OutputStreamWriter(outstream)); |
4338 |
25 Jun 12 |
fredrik |
391 |
if (sslFormat) { |
4264 |
26 Oct 11 |
fredrik |
392 |
output.write("file\tscan\tcharge\tsequence\n"); |
4338 |
25 Jun 12 |
fredrik |
393 |
} else { // for .mgf |
4264 |
26 Oct 11 |
fredrik |
394 |
output.write("SEARCH=MIS" + "\n" // .MGF file headers |
4264 |
26 Oct 11 |
fredrik |
395 |
+ "REPTYPE=Peptide" + "\n" + "LIBSIZE=" + "\n"); |
4264 |
26 Oct 11 |
fredrik |
396 |
} |
3700 |
07 May 10 |
fredrik |
397 |
} |
4338 |
25 Jun 12 |
fredrik |
398 |
if (fileNameAssigned2) { |
3700 |
07 May 10 |
fredrik |
399 |
OutputStream outstream2 = outCoreFile2.getUploadStream(false); |
3700 |
07 May 10 |
fredrik |
400 |
output2 = new BufferedWriter(new OutputStreamWriter(outstream2)); // for |
3700 |
07 May 10 |
fredrik |
// .msp |
3700 |
07 May 10 |
fredrik |
402 |
} |
3700 |
07 May 10 |
fredrik |
403 |
DbControl dc = sc.newDbControl(); |
3700 |
07 May 10 |
fredrik |
// ItemFactory factory = new ItemFactory(dc); |
3700 |
07 May 10 |
fredrik |
405 |
|
3700 |
07 May 10 |
fredrik |
406 |
ItemQuery<Hit> hitQuery = Hit.getQuery(); |
3700 |
07 May 10 |
fredrik |
407 |
hitQuery.restrictPermanent(Restrictions.eq(Hql.property("project"), |
4338 |
25 Jun 12 |
fredrik |
408 |
Hql.entity(project))); |
3778 |
18 Aug 10 |
fredrik |
409 |
hitQuery.restrictPermanent(Restrictions.eq(Hql.property("protein"), |
4338 |
25 Jun 12 |
fredrik |
410 |
Expressions.parameter("protein"))); |
3778 |
18 Aug 10 |
fredrik |
411 |
hitQuery.setPermanentParameter("protein", false, null); |
4545 |
26 Feb 14 |
fredrik |
412 |
if (!eValue) |
4545 |
26 Feb 14 |
fredrik |
413 |
{ |
4545 |
26 Feb 14 |
fredrik |
414 |
hitQuery.restrict(Restrictions.lteq(Hql.property("combinedFDR"), |
4338 |
25 Jun 12 |
fredrik |
415 |
Expressions.aFloat((float) fdrCutOff))); |
4545 |
26 Feb 14 |
fredrik |
416 |
} |
4545 |
26 Feb 14 |
fredrik |
417 |
else |
4545 |
26 Feb 14 |
fredrik |
418 |
{ |
4545 |
26 Feb 14 |
fredrik |
419 |
hitQuery.restrict(Restrictions.lteq(Hql.property("expectationValue"), |
4545 |
26 Feb 14 |
fredrik |
420 |
Expressions.aFloat((float) fdrCutOff))); |
4545 |
26 Feb 14 |
fredrik |
421 |
|
4545 |
26 Feb 14 |
fredrik |
422 |
} |
4332 |
14 May 12 |
fredrik |
423 |
hitQuery.restrict(Restrictions.neq(Hql.property("scoreType"), |
4338 |
25 Jun 12 |
fredrik |
424 |
Expressions.string("Proteios aligned"))); |
4300 |
13 Mar 12 |
fredrik |
425 |
hitQuery.order(Orders.asc(Hql.property("charge"))); |
4300 |
13 Mar 12 |
fredrik |
426 |
hitQuery.order(Orders.asc(Hql.property("description"))); |
4545 |
26 Feb 14 |
fredrik |
427 |
if (!eValue) hitQuery.order(Orders.asc(Hql.property("combinedFDR"))); |
4300 |
13 Mar 12 |
fredrik |
428 |
hitQuery.order(Orders.asc(Hql.property("expectationValue"))); |
4300 |
13 Mar 12 |
fredrik |
429 |
List<String> sequencesForCharge = new ArrayList<String>(); |
4300 |
13 Mar 12 |
fredrik |
430 |
List<Hit> retainHits = new ArrayList<Hit>(); |
3700 |
07 May 10 |
fredrik |
431 |
ItemResultList<Hit> hitlist = hitQuery.list(dc); |
4300 |
13 Mar 12 |
fredrik |
432 |
int currentCharge = 0; |
4545 |
26 Feb 14 |
fredrik |
433 |
log.debug("Number of hits:"+hitlist.size()); |
4338 |
25 Jun 12 |
fredrik |
434 |
for (Hit h : hitlist) { |
4338 |
25 Jun 12 |
fredrik |
435 |
if (currentCharge != h.getCharge().intValue()) { |
4300 |
13 Mar 12 |
fredrik |
436 |
currentCharge = h.getCharge(); |
4300 |
13 Mar 12 |
fredrik |
437 |
sequencesForCharge = new ArrayList<String>(); |
4300 |
13 Mar 12 |
fredrik |
438 |
} |
4300 |
13 Mar 12 |
fredrik |
439 |
String s = h.getDescription(); |
4549 |
06 Mar 14 |
fredrik |
440 |
if (s.contains("delta:")) |
4549 |
06 Mar 14 |
fredrik |
441 |
{ |
4549 |
06 Mar 14 |
fredrik |
442 |
log.debug("Truncating:"+s); |
4549 |
06 Mar 14 |
fredrik |
443 |
s = s.substring(0, s.indexOf(" delta:")); |
4549 |
06 Mar 14 |
fredrik |
444 |
log.debug("Result:"+s); |
4549 |
06 Mar 14 |
fredrik |
445 |
} |
4338 |
25 Jun 12 |
fredrik |
446 |
if (!sequencesForCharge.contains(s)) { |
4300 |
13 Mar 12 |
fredrik |
447 |
sequencesForCharge.add(s); |
4300 |
13 Mar 12 |
fredrik |
448 |
retainHits.add(h); |
4300 |
13 Mar 12 |
fredrik |
449 |
} |
4300 |
13 Mar 12 |
fredrik |
450 |
} |
4300 |
13 Mar 12 |
fredrik |
451 |
Comparator<Hit> comparator = new PeakListHitComparator(); |
4301 |
13 Mar 12 |
fredrik |
452 |
Collections.sort(retainHits, comparator); |
4300 |
13 Mar 12 |
fredrik |
453 |
Iterator<Hit> hitit = retainHits.iterator(); |
3700 |
07 May 10 |
fredrik |
454 |
|
3700 |
07 May 10 |
fredrik |
// store pklFiles |
3700 |
07 May 10 |
fredrik |
456 |
List<Hit> hitList = new ArrayList<Hit>(); |
3700 |
07 May 10 |
fredrik |
457 |
File pklFile = null; |
4338 |
25 Jun 12 |
fredrik |
458 |
while (hitit.hasNext()) { |
3700 |
07 May 10 |
fredrik |
459 |
Hit currentHit = hitit.next(); |
4545 |
26 Feb 14 |
fredrik |
460 |
if (pklFile == null) |
4545 |
26 Feb 14 |
fredrik |
461 |
{ |
4545 |
26 Feb 14 |
fredrik |
462 |
pklFile = currentHit.getPeakListFile(); |
4545 |
26 Feb 14 |
fredrik |
463 |
} |
4545 |
26 Feb 14 |
fredrik |
464 |
if (pklFile != currentHit.getPeakListFile()) |
4545 |
26 Feb 14 |
fredrik |
465 |
{ |
4545 |
26 Feb 14 |
fredrik |
466 |
retrieveAndWriteSpectra(pklFile, hitList, output, |
4338 |
25 Jun 12 |
fredrik |
467 |
output2, dc); |
4545 |
26 Feb 14 |
fredrik |
// empty hitList |
3778 |
18 Aug 10 |
fredrik |
469 |
hitList.clear(); |
4545 |
26 Feb 14 |
fredrik |
470 |
pklFile = currentHit.getPeakListFile(); |
4545 |
26 Feb 14 |
fredrik |
471 |
} |
4545 |
26 Feb 14 |
fredrik |
472 |
log.debug("Adding hit:"+currentHit.getDescription()); |
4545 |
26 Feb 14 |
fredrik |
473 |
hitList.add(currentHit); |
3700 |
07 May 10 |
fredrik |
474 |
} |
4545 |
26 Feb 14 |
fredrik |
475 |
log.debug("At final"); |
4545 |
26 Feb 14 |
fredrik |
476 |
if (!hitList.isEmpty()) retrieveAndWriteSpectra(pklFile, hitList, output, output2,dc); |
4338 |
25 Jun 12 |
fredrik |
477 |
if (output != null) { |
3700 |
07 May 10 |
fredrik |
// log.debug(">3 output closed\n"); |
3700 |
07 May 10 |
fredrik |
479 |
output.close(); |
3700 |
07 May 10 |
fredrik |
480 |
} |
4338 |
25 Jun 12 |
fredrik |
481 |
if (output2 != null) { |
3700 |
07 May 10 |
fredrik |
// log.debug(">4 output2 closed\n"); |
3700 |
07 May 10 |
fredrik |
483 |
output2.close(); |
3700 |
07 May 10 |
fredrik |
484 |
} |
3700 |
07 May 10 |
fredrik |
485 |
dc.commit(); |
4338 |
25 Jun 12 |
fredrik |
486 |
if (progress != null) { |
3700 |
07 May 10 |
fredrik |
487 |
progress.display(100, "Completed"); |
3700 |
07 May 10 |
fredrik |
488 |
} |
4338 |
25 Jun 12 |
fredrik |
489 |
} catch (Exception e) { |
3700 |
07 May 10 |
fredrik |
490 |
throw new BaseException(e); |
3700 |
07 May 10 |
fredrik |
491 |
} |
3700 |
07 May 10 |
fredrik |
492 |
} |
3700 |
07 May 10 |
fredrik |
493 |
|
4338 |
25 Jun 12 |
fredrik |
494 |
public void done() { |
4338 |
25 Jun 12 |
fredrik |
// Called when the execution has ended. Do some cleanup if you need here |
3700 |
07 May 10 |
fredrik |
496 |
} |
3700 |
07 May 10 |
fredrik |
497 |
|
3700 |
07 May 10 |
fredrik |
// The list of modifications patterns |
3700 |
07 May 10 |
fredrik |
// String oxidation1 = "(Oxidation)\\s\\((\w)\\)"; // group 1 and 2 |
3700 |
07 May 10 |
fredrik |
// String oxidation2 = "(d+)\\s(Oxidation)\\s\\((\w)\\)"; //group 1, 2, and |
3700 |
07 May 10 |
fredrik |
// 3 |
3700 |
07 May 10 |
fredrik |
// List<Pattern> Modifications = new ArrayList<Pattern>(); |
3700 |
07 May 10 |
fredrik |
// Pattern monoOxidation = Pattern.compile("(Oxidation)\s\((\w)\)"); |
3700 |
07 May 10 |
fredrik |
// Pattern multipleOxidation = Pattern.compile(oxidation2); |
3700 |
07 May 10 |
fredrik |
// Modifications.add(o1); |
3700 |
07 May 10 |
fredrik |
// Modifications.add(o2); |
3700 |
07 May 10 |
fredrik |
507 |
|
3700 |
07 May 10 |
fredrik |
508 |
public void processModificationMGF(BufferedWriter output, String sequence, |
4338 |
25 Jun 12 |
fredrik |
509 |
String modification) { |
4338 |
25 Jun 12 |
fredrik |
510 |
try { |
3700 |
07 May 10 |
fredrik |
// Modifications modType; // enum |
3700 |
07 May 10 |
fredrik |
512 |
Integer modificationN = 0; |
3700 |
07 May 10 |
fredrik |
513 |
int count = 0; |
3700 |
07 May 10 |
fredrik |
514 |
String[] Mod = modification.split(" "); |
4338 |
25 Jun 12 |
fredrik |
515 |
if (Mod.length == 2 && Mod[0].equalsIgnoreCase("oxidation")) { // modification |
4338 |
25 Jun 12 |
fredrik |
// number |
4338 |
25 Jun 12 |
fredrik |
// is |
4338 |
25 Jun 12 |
fredrik |
// 1 |
3700 |
07 May 10 |
fredrik |
519 |
modificationN = 1; |
4338 |
25 Jun 12 |
fredrik |
520 |
for (int o = 0; o < sequence.length(); o++) { |
4338 |
25 Jun 12 |
fredrik |
521 |
if (Mod[1].equals("(" + sequence.charAt(o) + ")") |
4338 |
25 Jun 12 |
fredrik |
522 |
&& count < modificationN) { // the first to appear |
3700 |
07 May 10 |
fredrik |
523 |
output.write("PEPMOD=15.9949@" + (o + 1) + "\n"); |
3700 |
07 May 10 |
fredrik |
524 |
count++; // take only once |
3700 |
07 May 10 |
fredrik |
// log.debug(">2PEPMOD=15.9949@" + (o+1) + "\n"); |
3700 |
07 May 10 |
fredrik |
526 |
} |
3700 |
07 May 10 |
fredrik |
527 |
} |
4338 |
25 Jun 12 |
fredrik |
528 |
} else if (Mod.length == 3 && Mod[1].equalsIgnoreCase("oxidation")) { |
4338 |
25 Jun 12 |
fredrik |
529 |
for (int o = 0; o < sequence.length(); o++) { |
4338 |
25 Jun 12 |
fredrik |
530 |
if (Mod[2].equals("(" + sequence.charAt(o) + ")") |
4338 |
25 Jun 12 |
fredrik |
531 |
&& count < modificationN) { // the first to appear |
3700 |
07 May 10 |
fredrik |
532 |
output.write("PEPMOD=15.9949@" + (o + 1) + "\n"); |
3700 |
07 May 10 |
fredrik |
533 |
count++; // take only once |
3700 |
07 May 10 |
fredrik |
// log.debug(">3PEPMOD=15.9949@" + (o+1) + "\n"); |
3700 |
07 May 10 |
fredrik |
535 |
} |
3700 |
07 May 10 |
fredrik |
536 |
} |
4338 |
25 Jun 12 |
fredrik |
537 |
} else if (Mod[0].contains("@")) { // when a result is from xtandem |
3700 |
07 May 10 |
fredrik |
538 |
modificationN = 1; |
4338 |
25 Jun 12 |
fredrik |
539 |
for (int q = 0; q < Mod.length; q++) { |
3700 |
07 May 10 |
fredrik |
540 |
String[] arr = Mod[0].split("@"); |
4338 |
25 Jun 12 |
fredrik |
541 |
for (int o = 0; o < sequence.length(); o++) { |
3700 |
07 May 10 |
fredrik |
542 |
char c = arr[1].charAt(0); |
4338 |
25 Jun 12 |
fredrik |
543 |
if (c == sequence.charAt(o) && count < modificationN) { // the |
4338 |
25 Jun 12 |
fredrik |
// first |
4338 |
25 Jun 12 |
fredrik |
// to |
4338 |
25 Jun 12 |
fredrik |
// appear |
4338 |
25 Jun 12 |
fredrik |
547 |
output.write("PEPMOD=" + arr[0] + "@" + (o + 1) |
4338 |
25 Jun 12 |
fredrik |
548 |
+ "\n"); |
3700 |
07 May 10 |
fredrik |
549 |
count++; // take only once |
3700 |
07 May 10 |
fredrik |
// log.debug(">3PEPMOD=" + arr[0] + "@" + arr[1] + |
3700 |
07 May 10 |
fredrik |
// "\n"); |
3700 |
07 May 10 |
fredrik |
552 |
} |
3700 |
07 May 10 |
fredrik |
553 |
} |
3700 |
07 May 10 |
fredrik |
554 |
} |
3700 |
07 May 10 |
fredrik |
555 |
} |
4338 |
25 Jun 12 |
fredrik |
556 |
} catch (Exception e) { |
3700 |
07 May 10 |
fredrik |
557 |
throw new BaseException(e); |
3700 |
07 May 10 |
fredrik |
558 |
} |
3700 |
07 May 10 |
fredrik |
559 |
} |
3700 |
07 May 10 |
fredrik |
560 |
|
3700 |
07 May 10 |
fredrik |
561 |
public String processModificationMSP(BufferedWriter output2, |
4300 |
13 Mar 12 |
fredrik |
562 |
ItemFactory factory, String sequence, String modstring, |
4338 |
25 Jun 12 |
fredrik |
563 |
List<SearchModification> fixedMods) throws IOException { |
4485 |
10 Jun 13 |
fredrik |
564 |
List<ObservedModification> mods = ObservedModification.getModList(sequence, modstring, |
4338 |
25 Jun 12 |
fredrik |
565 |
fixedMods, factory); |
4300 |
13 Mar 12 |
fredrik |
566 |
List<Integer> positions = new ArrayList<Integer>(); |
4300 |
13 Mar 12 |
fredrik |
567 |
String modout = "" + mods.size(); |
4338 |
25 Jun 12 |
fredrik |
568 |
for (ObservedModification om : mods) { |
4338 |
25 Jun 12 |
fredrik |
569 |
if (om.getName().equals("Oxidation")) { |
4300 |
13 Mar 12 |
fredrik |
570 |
positions.add(om.getPosition()); |
3700 |
07 May 10 |
fredrik |
571 |
} |
4338 |
25 Jun 12 |
fredrik |
572 |
modout += "/" + om.getPosition() + "," + om.getModifiedAminoAcid() |
4338 |
25 Jun 12 |
fredrik |
573 |
+ "," + om.getName(); |
4300 |
13 Mar 12 |
fredrik |
574 |
} |
4300 |
13 Mar 12 |
fredrik |
575 |
char[] seq = sequence.toCharArray(); |
4338 |
25 Jun 12 |
fredrik |
576 |
if (sequence.contains(" ")) { |
4300 |
13 Mar 12 |
fredrik |
577 |
seq = sequence.substring(0, sequence.indexOf(" ")).toCharArray(); |
4300 |
13 Mar 12 |
fredrik |
578 |
} |
4300 |
13 Mar 12 |
fredrik |
579 |
output2.write("Name: "); |
4338 |
25 Jun 12 |
fredrik |
580 |
for (int i = 0; i < seq.length; i++) { |
4338 |
25 Jun 12 |
fredrik |
581 |
if (seq[i] == 'M' && positions.contains(Integer.valueOf(i))) { |
4300 |
13 Mar 12 |
fredrik |
582 |
output2.write("M(O)"); |
4338 |
25 Jun 12 |
fredrik |
583 |
} else { |
4300 |
13 Mar 12 |
fredrik |
584 |
output2.write(seq[i]); |
3700 |
07 May 10 |
fredrik |
585 |
} |
4300 |
13 Mar 12 |
fredrik |
586 |
} |
4300 |
13 Mar 12 |
fredrik |
587 |
output2.write("/"); |
4300 |
13 Mar 12 |
fredrik |
588 |
return modout; |
3700 |
07 May 10 |
fredrik |
589 |
|
3700 |
07 May 10 |
fredrik |
590 |
} |
3700 |
07 May 10 |
fredrik |
591 |
|
4264 |
26 Oct 11 |
fredrik |
592 |
public void retrieveAndWriteSpectra(File pklFile, List<Hit> peptideHits, |
4338 |
25 Jun 12 |
fredrik |
593 |
BufferedWriter output, BufferedWriter output2, DbControl dc) { |
4338 |
25 Jun 12 |
fredrik |
594 |
try { |
3700 |
07 May 10 |
fredrik |
// updating arraylists for each pklFile |
3700 |
07 May 10 |
fredrik |
596 |
List<String> requestSpectraStringID = new ArrayList<String>(); |
3700 |
07 May 10 |
fredrik |
597 |
List<String> requestSpectraSEQ = new ArrayList<String>(); |
3700 |
07 May 10 |
fredrik |
598 |
List<String> requestSpectraModification = new ArrayList<String>(); |
4547 |
28 Feb 14 |
fredrik |
599 |
List<String> requestSpectraProtein = new ArrayList<String>(); |
3700 |
07 May 10 |
fredrik |
600 |
List<Float> requestSpectraEXP = new ArrayList<Float>(); |
3700 |
07 May 10 |
fredrik |
601 |
List<List<String>> requestSpectraExternalID = new ArrayList<List<String>>(); |
3700 |
07 May 10 |
fredrik |
602 |
List<File> requestSpectraPeaklistFileName = new ArrayList<File>(); |
3700 |
07 May 10 |
fredrik |
603 |
List<Float> requestSpectraFDR = new ArrayList<Float>(); |
3700 |
07 May 10 |
fredrik |
604 |
List<Float> requestSpectraExperimentalMassD = new ArrayList<Float>(); |
3700 |
07 May 10 |
fredrik |
605 |
List<Float> requestSpectraDeltaMassD = new ArrayList<Float>(); |
4338 |
25 Jun 12 |
fredrik |
606 |
ItemFactory factory = new ItemFactory(dc); |
3700 |
07 May 10 |
fredrik |
607 |
List<Integer> requestSpectraCharge = new ArrayList<Integer>(); |
4485 |
10 Jun 13 |
fredrik |
608 |
List<SearchModification> fixedMods = SearchModification.getFixedMods(peptideHits |
4338 |
25 Jun 12 |
fredrik |
609 |
.get(0).getIdentificationResultFile(), dc, factory); |
3778 |
18 Aug 10 |
fredrik |
610 |
DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US); |
3778 |
18 Aug 10 |
fredrik |
611 |
DecimalFormat fourDecimals = new DecimalFormat("####.0000", dfs); |
3700 |
07 May 10 |
fredrik |
// correct only unique ones |
3700 |
07 May 10 |
fredrik |
613 |
int requestSpectraNr = 0; |
4545 |
26 Feb 14 |
fredrik |
614 |
log.debug("PKL file:"+pklFile.getName()+" hits:"+peptideHits.size()); |
4338 |
25 Jun 12 |
fredrik |
615 |
for (Hit phit : peptideHits) { |
3778 |
18 Aug 10 |
fredrik |
// make sure the file format and its interface |
3778 |
18 Aug 10 |
fredrik |
617 |
if (!requestSpectraStringID |
4338 |
25 Jun 12 |
fredrik |
618 |
.contains(phit.getSpectrumStringId())) { |
3778 |
18 Aug 10 |
fredrik |
619 |
requestSpectraStringID.add(phit.getSpectrumStringId()); |
4547 |
28 Feb 14 |
fredrik |
620 |
String externalID = phit.getExternalId(); |
4586 |
13 Nov 15 |
fredrik |
621 |
if (phit.getDescription().contains("Asn->Asp")) phit.setDescription(phit.getDescription().replace("Asn->Asp", "Deamidation")); |
3778 |
18 Aug 10 |
fredrik |
622 |
String[] s1 = phit.getDescription().split(" ", 2); |
4545 |
26 Feb 14 |
fredrik |
623 |
if (s1.length == 2 && s1[1].contains(">")) |
4545 |
26 Feb 14 |
fredrik |
624 |
{ |
4545 |
26 Feb 14 |
fredrik |
625 |
log.debug("Sequence:"+s1[0]+" mod:"+s1[1]); |
4545 |
26 Feb 14 |
fredrik |
626 |
String[] parts = s1[1].split(" "); |
4545 |
26 Feb 14 |
fredrik |
627 |
String newString = null; |
4545 |
26 Feb 14 |
fredrik |
628 |
for (String s2:parts) |
4545 |
26 Feb 14 |
fredrik |
629 |
{ |
4545 |
26 Feb 14 |
fredrik |
630 |
if (s2.contains(">")) |
4545 |
26 Feb 14 |
fredrik |
631 |
{ |
4545 |
26 Feb 14 |
fredrik |
632 |
int pos = Integer.parseInt(s2.substring(s2.indexOf('@')+2,s2.indexOf('('))); |
4545 |
26 Feb 14 |
fredrik |
633 |
char newchar = s2.charAt(s2.indexOf('>')+1); |
4547 |
28 Feb 14 |
fredrik |
634 |
externalID += " " + s2.substring(s2.indexOf('>')-1,s2.indexOf('>')+2) + "@" + pos; |
4545 |
26 Feb 14 |
fredrik |
635 |
if (pos>0) --pos; |
4545 |
26 Feb 14 |
fredrik |
636 |
String newSeq = s1[0].substring(0,pos)+newchar+s1[0].substring(pos+1); |
4545 |
26 Feb 14 |
fredrik |
637 |
s1[0]=newSeq; |
4545 |
26 Feb 14 |
fredrik |
638 |
log.debug("new Sequence:"+newSeq); |
4545 |
26 Feb 14 |
fredrik |
639 |
} |
4545 |
26 Feb 14 |
fredrik |
640 |
else |
4545 |
26 Feb 14 |
fredrik |
641 |
{ |
4545 |
26 Feb 14 |
fredrik |
642 |
if (newString == null) newString=s2; |
4545 |
26 Feb 14 |
fredrik |
643 |
else newString+=" "+s2; |
4545 |
26 Feb 14 |
fredrik |
644 |
} |
4545 |
26 Feb 14 |
fredrik |
645 |
} |
4545 |
26 Feb 14 |
fredrik |
646 |
s1[1]=newString; |
4545 |
26 Feb 14 |
fredrik |
647 |
} |
4547 |
28 Feb 14 |
fredrik |
648 |
requestSpectraProtein.add(externalID); |
3778 |
18 Aug 10 |
fredrik |
649 |
requestSpectraSEQ.add(s1[0]); // sequence |
4338 |
25 Jun 12 |
fredrik |
650 |
if (s1.length == 2) { |
3778 |
18 Aug 10 |
fredrik |
651 |
requestSpectraModification.add(s1[1]); // modification |
3778 |
18 Aug 10 |
fredrik |
// if any |
3778 |
18 Aug 10 |
fredrik |
// log.debug(">" + s1[0] + "\t" + s1[1]); |
4338 |
25 Jun 12 |
fredrik |
654 |
} else { |
3778 |
18 Aug 10 |
fredrik |
655 |
requestSpectraModification.add(null); // put |
3778 |
18 Aug 10 |
fredrik |
// something |
3778 |
18 Aug 10 |
fredrik |
// so that |
3778 |
18 Aug 10 |
fredrik |
// the order |
3778 |
18 Aug 10 |
fredrik |
// is kept |
3778 |
18 Aug 10 |
fredrik |
// log.debug(">" + s1[0] + "\n"); |
3778 |
18 Aug 10 |
fredrik |
661 |
} |
3778 |
18 Aug 10 |
fredrik |
// expectation value |
3778 |
18 Aug 10 |
fredrik |
663 |
requestSpectraEXP.add(phit.getExpectationValue()); |
3778 |
18 Aug 10 |
fredrik |
// combinedFDR |
3778 |
18 Aug 10 |
fredrik |
665 |
requestSpectraFDR.add(phit.getCombinedFDR()); |
3778 |
18 Aug 10 |
fredrik |
// experimental mass |
3778 |
18 Aug 10 |
fredrik |
667 |
requestSpectraExperimentalMassD.add(phit |
4338 |
25 Jun 12 |
fredrik |
668 |
.getExperimentalMassInDaltons()); |
3778 |
18 Aug 10 |
fredrik |
// delta mass |
3778 |
18 Aug 10 |
fredrik |
670 |
requestSpectraDeltaMassD.add(phit.getDeltaMassInDaltons()); |
3778 |
18 Aug 10 |
fredrik |
// charge |
3778 |
18 Aug 10 |
fredrik |
672 |
requestSpectraCharge.add(phit.getCharge()); |
3700 |
07 May 10 |
fredrik |
673 |
|
3778 |
18 Aug 10 |
fredrik |
// IPI IDs and get the appropriate Peptide for |
3778 |
18 Aug 10 |
fredrik |
// positional info for each hit |
3778 |
18 Aug 10 |
fredrik |
676 |
requestSpectraPeaklistFileName.add(phit.getPeakListFile()); |
3778 |
18 Aug 10 |
fredrik |
677 |
String[] s2 = phit.getExternalId().split(","); |
3700 |
07 May 10 |
fredrik |
678 |
|
3778 |
18 Aug 10 |
fredrik |
// Start positions |
3778 |
18 Aug 10 |
fredrik |
680 |
List<String> idlist = new ArrayList<String>(); |
4338 |
25 Jun 12 |
fredrik |
681 |
if (mgfFormat) { |
4338 |
25 Jun 12 |
fredrik |
682 |
for (int i = 0; i < s2.length; i++) { |
4338 |
25 Jun 12 |
fredrik |
683 |
String id2 = s2[i] |
4338 |
25 Jun 12 |
fredrik |
684 |
+ "@" |
4338 |
25 Jun 12 |
fredrik |
685 |
+ getStartPosition(s2[i], |
4338 |
25 Jun 12 |
fredrik |
686 |
phit.getDescription(), dc); |
3778 |
18 Aug 10 |
fredrik |
687 |
idlist.add(id2); |
3700 |
07 May 10 |
fredrik |
688 |
} |
3778 |
18 Aug 10 |
fredrik |
689 |
} |
3778 |
18 Aug 10 |
fredrik |
690 |
requestSpectraNr++; |
3778 |
18 Aug 10 |
fredrik |
691 |
log.debug("Retrieved startpos:" + requestSpectraNr); |
4264 |
26 Oct 11 |
fredrik |
692 |
requestSpectraExternalID.add(idlist); |
4264 |
26 Oct 11 |
fredrik |
693 |
} |
4264 |
26 Oct 11 |
fredrik |
694 |
} |
4338 |
25 Jun 12 |
fredrik |
695 |
if (sslFormat) { |
4264 |
26 Oct 11 |
fredrik |
// output for .ssl and output2 for .ms2 |
4264 |
26 Oct 11 |
fredrik |
697 |
PeakListFileInterface peaklistReader = null; |
4338 |
25 Jun 12 |
fredrik |
698 |
if (requestSpectraStringID.size() > 0) { |
4338 |
25 Jun 12 |
fredrik |
699 |
log.info("Spectra to retrieve:" |
4338 |
25 Jun 12 |
fredrik |
700 |
+ requestSpectraStringID.size()); |
4338 |
25 Jun 12 |
fredrik |
701 |
if (pklFile.getFileType().getSystemId() |
4338 |
25 Jun 12 |
fredrik |
702 |
.equals(FileType.MGF_PEAK_LIST)) { |
4338 |
25 Jun 12 |
fredrik |
703 |
MgfFileReader mgfReader = new MgfFileReader( |
4338 |
25 Jun 12 |
fredrik |
704 |
pklFile.getDownloadStream(0)); |
4264 |
26 Oct 11 |
fredrik |
705 |
mgfReader.setTitleUsedAsId(true); |
4264 |
26 Oct 11 |
fredrik |
706 |
peaklistReader = (PeakListFileInterface) mgfReader; |
4338 |
25 Jun 12 |
fredrik |
707 |
} else if (pklFile.getFileType().getSystemId() |
4338 |
25 Jun 12 |
fredrik |
708 |
.equals(FileType.MZML)) { |
4338 |
25 Jun 12 |
fredrik |
709 |
peaklistReader = new MzMLFileReader( |
4338 |
25 Jun 12 |
fredrik |
710 |
pklFile.getDownloadStream(0)); |
4338 |
25 Jun 12 |
fredrik |
711 |
} else if (pklFile.getFileType().getSystemId() |
4338 |
25 Jun 12 |
fredrik |
712 |
.equals(FileType.MZDATA)) { // mzData |
4338 |
25 Jun 12 |
fredrik |
713 |
peaklistReader = new PeakListFileImpl( |
4338 |
25 Jun 12 |
fredrik |
714 |
pklFile.getDownloadStream(0)); |
4338 |
25 Jun 12 |
fredrik |
715 |
} else { |
4264 |
26 Oct 11 |
fredrik |
716 |
throw new BaseException( |
4338 |
25 Jun 12 |
fredrik |
717 |
pklFile.getName() |
4338 |
25 Jun 12 |
fredrik |
718 |
+ " is not an MGF or mzData file. Cannot retrieve reporter ion intensities"); |
4264 |
26 Oct 11 |
fredrik |
719 |
} |
4264 |
26 Oct 11 |
fredrik |
720 |
} |
4264 |
26 Oct 11 |
fredrik |
721 |
String ms2file = outfile2; |
4338 |
25 Jun 12 |
fredrik |
722 |
if (outfile2.contains("/")) { |
4264 |
26 Oct 11 |
fredrik |
723 |
ms2file = outfile2.substring(outfile2.lastIndexOf("/") + 1); |
4264 |
26 Oct 11 |
fredrik |
724 |
} |
4264 |
26 Oct 11 |
fredrik |
725 |
Iterator<SpectrumInterface> specins = peaklistReader |
4338 |
25 Jun 12 |
fredrik |
726 |
.getSpectrum(requestSpectraStringID); |
4264 |
26 Oct 11 |
fredrik |
727 |
int i = 0; |
4338 |
25 Jun 12 |
fredrik |
728 |
while (specins.hasNext()) { |
4264 |
26 Oct 11 |
fredrik |
729 |
SpectrumInterface spec = specins.next(); |
3700 |
07 May 10 |
fredrik |
730 |
|
4264 |
26 Oct 11 |
fredrik |
731 |
double[] masses; |
4264 |
26 Oct 11 |
fredrik |
732 |
List<SpectrumPrecursor> precursors; |
4264 |
26 Oct 11 |
fredrik |
733 |
double[] intensities; |
3700 |
07 May 10 |
fredrik |
734 |
|
4338 |
25 Jun 12 |
fredrik |
735 |
if (spec.listMass() != null) { |
4264 |
26 Oct 11 |
fredrik |
736 |
masses = spec.listMass(); |
4338 |
25 Jun 12 |
fredrik |
737 |
} else { |
4264 |
26 Oct 11 |
fredrik |
738 |
masses = null; |
4264 |
26 Oct 11 |
fredrik |
739 |
} |
4338 |
25 Jun 12 |
fredrik |
740 |
if (spec.getPrecursors() != null) { |
4264 |
26 Oct 11 |
fredrik |
741 |
precursors = spec.getPrecursors(); |
4338 |
25 Jun 12 |
fredrik |
742 |
} else { |
4264 |
26 Oct 11 |
fredrik |
743 |
precursors = null; |
4264 |
26 Oct 11 |
fredrik |
744 |
} |
4338 |
25 Jun 12 |
fredrik |
745 |
if (spec.listIntensities() != null) { |
4264 |
26 Oct 11 |
fredrik |
746 |
intensities = spec.listIntensities(); |
4338 |
25 Jun 12 |
fredrik |
747 |
} else { |
4264 |
26 Oct 11 |
fredrik |
748 |
intensities = null; |
4264 |
26 Oct 11 |
fredrik |
749 |
} |
4338 |
25 Jun 12 |
fredrik |
750 |
if (precursors != null && intensities != null |
4338 |
25 Jun 12 |
fredrik |
751 |
&& requestSpectraModification.get(i) == null) { |
4264 |
26 Oct 11 |
fredrik |
752 |
Float deltaMassD = requestSpectraDeltaMassD.get(i); |
4264 |
26 Oct 11 |
fredrik |
753 |
Integer charge = requestSpectraCharge.get(i); |
4264 |
26 Oct 11 |
fredrik |
754 |
Float experimentalMassD = requestSpectraExperimentalMassD |
4338 |
25 Jun 12 |
fredrik |
755 |
.get(i); |
4264 |
26 Oct 11 |
fredrik |
// Calculate the theoretical m/z and mass |
4338 |
25 Jun 12 |
fredrik |
757 |
Float mz = new Float((experimentalMassD - deltaMassD) |
4338 |
25 Jun 12 |
fredrik |
758 |
/ charge + MONOISTOPIC_PROTON_MASS); |
4264 |
26 Oct 11 |
fredrik |
759 |
Float mass = experimentalMassD - deltaMassD; |
4338 |
25 Jun 12 |
fredrik |
760 |
output.write(ms2file + "\t" + spectrumNumber + "\t" |
4338 |
25 Jun 12 |
fredrik |
761 |
+ charge + "\t" + requestSpectraSEQ.get(i) |
4338 |
25 Jun 12 |
fredrik |
762 |
+ "\n"); |
4338 |
25 Jun 12 |
fredrik |
763 |
output2.write("S\t" + spectrumNumber + "\t" |
4338 |
25 Jun 12 |
fredrik |
764 |
+ spectrumNumber + "\t" + mz + "\n"); |
4338 |
25 Jun 12 |
fredrik |
765 |
output2.write("I\t" |
4338 |
25 Jun 12 |
fredrik |
766 |
+ requestSpectraPeaklistFileName.get(i) |
4338 |
25 Jun 12 |
fredrik |
767 |
.getName() + " " |
4338 |
25 Jun 12 |
fredrik |
768 |
+ requestSpectraStringID.get(i) + "\n"); |
4264 |
26 Oct 11 |
fredrik |
769 |
output2.write("Z\t" + charge + "\t" + mass + "\n"); |
4264 |
26 Oct 11 |
fredrik |
770 |
double max = 0; |
4264 |
26 Oct 11 |
fredrik |
771 |
double[] normalizedIntensities = new double[intensities.length]; |
4338 |
25 Jun 12 |
fredrik |
772 |
for (double inte : intensities) { |
4338 |
25 Jun 12 |
fredrik |
773 |
if (inte > max) { |
4264 |
26 Oct 11 |
fredrik |
774 |
max = inte; |
4264 |
26 Oct 11 |
fredrik |
775 |
} |
4264 |
26 Oct 11 |
fredrik |
776 |
} |
4264 |
26 Oct 11 |
fredrik |
777 |
double ratio = 100 / max; |
4338 |
25 Jun 12 |
fredrik |
778 |
for (int j = 0; j < intensities.length; j++) { |
4264 |
26 Oct 11 |
fredrik |
779 |
normalizedIntensities[j] = ratio * intensities[j]; |
4264 |
26 Oct 11 |
fredrik |
780 |
} |
4264 |
26 Oct 11 |
fredrik |
781 |
|
4264 |
26 Oct 11 |
fredrik |
// print out masses and intensities |
4338 |
25 Jun 12 |
fredrik |
783 |
if (masses.length == normalizedIntensities.length) { |
4338 |
25 Jun 12 |
fredrik |
784 |
for (int k = 0; k < masses.length; k++) { |
4338 |
25 Jun 12 |
fredrik |
785 |
output2.write(fourDecimals.format(masses[k]) |
4338 |
25 Jun 12 |
fredrik |
786 |
+ " " + normalizedIntensities[k] + "\n"); |
4264 |
26 Oct 11 |
fredrik |
787 |
} |
4264 |
26 Oct 11 |
fredrik |
788 |
} |
4264 |
26 Oct 11 |
fredrik |
789 |
spectrumNumber++; |
4264 |
26 Oct 11 |
fredrik |
790 |
} |
4264 |
26 Oct 11 |
fredrik |
791 |
i++; |
3700 |
07 May 10 |
fredrik |
792 |
} |
4338 |
25 Jun 12 |
fredrik |
793 |
} else if (mgfFormat) { |
3700 |
07 May 10 |
fredrik |
794 |
PeakListFileInterface peaklistReader = null; |
4338 |
25 Jun 12 |
fredrik |
795 |
if (requestSpectraStringID.size() > 0) { |
4338 |
25 Jun 12 |
fredrik |
796 |
log.info("Spectra to retrieve:" |
4338 |
25 Jun 12 |
fredrik |
797 |
+ requestSpectraStringID.size()); |
4338 |
25 Jun 12 |
fredrik |
798 |
if (pklFile.getFileType().getSystemId() |
4338 |
25 Jun 12 |
fredrik |
799 |
.equals(FileType.MGF_PEAK_LIST)) { |
4338 |
25 Jun 12 |
fredrik |
800 |
MgfFileReader mgfReader = new MgfFileReader( |
4338 |
25 Jun 12 |
fredrik |
801 |
pklFile.getDownloadStream(0)); |
3700 |
07 May 10 |
fredrik |
802 |
mgfReader.setTitleUsedAsId(true); |
3700 |
07 May 10 |
fredrik |
803 |
peaklistReader = (PeakListFileInterface) mgfReader; |
4338 |
25 Jun 12 |
fredrik |
804 |
} else if (pklFile.getFileType().getSystemId() |
4338 |
25 Jun 12 |
fredrik |
805 |
.equals(FileType.MZML)) { |
4338 |
25 Jun 12 |
fredrik |
806 |
peaklistReader = new MzMLFileReader( |
4338 |
25 Jun 12 |
fredrik |
807 |
pklFile.getDownloadStream(0)); |
4338 |
25 Jun 12 |
fredrik |
808 |
} else if (pklFile.getFileType().getSystemId() |
4338 |
25 Jun 12 |
fredrik |
809 |
.equals(FileType.MZDATA)) { // mzData |
4338 |
25 Jun 12 |
fredrik |
810 |
peaklistReader = new PeakListFileImpl( |
4338 |
25 Jun 12 |
fredrik |
811 |
pklFile.getDownloadStream(0)); |
4338 |
25 Jun 12 |
fredrik |
812 |
} else { |
3700 |
07 May 10 |
fredrik |
813 |
throw new BaseException( |
4338 |
25 Jun 12 |
fredrik |
814 |
pklFile.getName() |
4338 |
25 Jun 12 |
fredrik |
815 |
+ " is not an MGF or mzData file. Cannot retrieve reporter ion intensities"); |
3700 |
07 May 10 |
fredrik |
816 |
} |
3700 |
07 May 10 |
fredrik |
817 |
} |
3700 |
07 May 10 |
fredrik |
818 |
Iterator<SpectrumInterface> specins = peaklistReader |
4338 |
25 Jun 12 |
fredrik |
819 |
.getSpectrum(requestSpectraStringID); |
3700 |
07 May 10 |
fredrik |
820 |
int i = 0; |
4338 |
25 Jun 12 |
fredrik |
821 |
while (specins.hasNext()) { |
3700 |
07 May 10 |
fredrik |
822 |
SpectrumInterface spec = specins.next(); |
3700 |
07 May 10 |
fredrik |
823 |
|
3700 |
07 May 10 |
fredrik |
824 |
double[] masses; |
3700 |
07 May 10 |
fredrik |
825 |
double[] intensities; |
3700 |
07 May 10 |
fredrik |
826 |
double retentionTime = -1; |
3700 |
07 May 10 |
fredrik |
827 |
|
4338 |
25 Jun 12 |
fredrik |
828 |
if (spec.listMass() != null) { |
3700 |
07 May 10 |
fredrik |
829 |
masses = spec.listMass(); |
4338 |
25 Jun 12 |
fredrik |
830 |
} else { |
3700 |
07 May 10 |
fredrik |
831 |
masses = null; |
3700 |
07 May 10 |
fredrik |
832 |
} |
4338 |
25 Jun 12 |
fredrik |
833 |
if (spec.listIntensities() != null) { |
3700 |
07 May 10 |
fredrik |
834 |
intensities = spec.listIntensities(); |
4338 |
25 Jun 12 |
fredrik |
835 |
} else { |
3700 |
07 May 10 |
fredrik |
836 |
intensities = null; |
3700 |
07 May 10 |
fredrik |
837 |
} |
4338 |
25 Jun 12 |
fredrik |
838 |
if (spec.getRetentionTimeInMinutes() != null) { |
3700 |
07 May 10 |
fredrik |
839 |
retentionTime = spec.getRetentionTimeInMinutes(); |
3700 |
07 May 10 |
fredrik |
840 |
} |
3700 |
07 May 10 |
fredrik |
841 |
|
3700 |
07 May 10 |
fredrik |
842 |
output.write("BEGIN IONS" + "\n"); |
4338 |
25 Jun 12 |
fredrik |
843 |
output.write("#SPECTRUMID=" + requestSpectraStringID.get(i) |
4338 |
25 Jun 12 |
fredrik |
844 |
+ "\n"); |
4338 |
25 Jun 12 |
fredrik |
845 |
output.write("#PEAKLISTFILE=" |
4338 |
25 Jun 12 |
fredrik |
846 |
+ requestSpectraPeaklistFileName.get(i) + "\n"); |
3700 |
07 May 10 |
fredrik |
847 |
output.write("#RETENTIONTIME=" + retentionTime + "\n"); |
4338 |
25 Jun 12 |
fredrik |
848 |
output.write("#COMBINEDFDR=" + requestSpectraFDR.get(i) |
4338 |
25 Jun 12 |
fredrik |
849 |
+ "\n"); |
3700 |
07 May 10 |
fredrik |
850 |
Float experimentalMassD = requestSpectraExperimentalMassD |
4338 |
25 Jun 12 |
fredrik |
851 |
.get(i); |
4338 |
25 Jun 12 |
fredrik |
852 |
output.write("#EXPERIMENTALMASS=" + experimentalMassD |
4338 |
25 Jun 12 |
fredrik |
853 |
+ "\n"); |
3700 |
07 May 10 |
fredrik |
854 |
Float deltaMassD = requestSpectraDeltaMassD.get(i); |
3700 |
07 May 10 |
fredrik |
855 |
output.write("#DELTAMASS=" + deltaMassD + "\n"); |
3700 |
07 May 10 |
fredrik |
856 |
Integer charge = requestSpectraCharge.get(i); |
3700 |
07 May 10 |
fredrik |
857 |
|
3700 |
07 May 10 |
fredrik |
// Calculate the theoretical m/z and mass |
4338 |
25 Jun 12 |
fredrik |
859 |
Float mz = new Float((experimentalMassD - deltaMassD) |
4338 |
25 Jun 12 |
fredrik |
860 |
/ charge + MONOISTOPIC_PROTON_MASS); |
3700 |
07 May 10 |
fredrik |
861 |
Float mass = experimentalMassD - deltaMassD; |
3700 |
07 May 10 |
fredrik |
862 |
|
3700 |
07 May 10 |
fredrik |
863 |
output.write("#THEORETICALMASS=" + mass + "\n"); |
3700 |
07 May 10 |
fredrik |
// if (retentionTime != -1) { |
3700 |
07 May 10 |
fredrik |
// output.write(retentionTime + "\n"); |
3700 |
07 May 10 |
fredrik |
866 |
// } |
3700 |
07 May 10 |
fredrik |
// print out precursors |
4338 |
25 Jun 12 |
fredrik |
868 |
output.write("PEPMASS=" + mz + "\n" + "CHARGE=" + charge |
4338 |
25 Jun 12 |
fredrik |
869 |
+ "\n"); |
4338 |
25 Jun 12 |
fredrik |
870 |
output.write("PEPSEQ=" + requestSpectraSEQ.get(i) + "\n" |
4338 |
25 Jun 12 |
fredrik |
871 |
+ "PEPEXP=" + requestSpectraEXP.get(i) + "\n"); |
3700 |
07 May 10 |
fredrik |
872 |
|
4338 |
25 Jun 12 |
fredrik |
873 |
if (requestSpectraModification.get(i) != null) { |
3700 |
07 May 10 |
fredrik |
874 |
processModificationMGF(output, |
4338 |
25 Jun 12 |
fredrik |
875 |
requestSpectraSEQ.get(i), |
4338 |
25 Jun 12 |
fredrik |
876 |
requestSpectraModification.get(i)); |
3700 |
07 May 10 |
fredrik |
877 |
} |
4338 |
25 Jun 12 |
fredrik |
878 |
output.write("#1-EVALUE=" + (1 - requestSpectraEXP.get(i)) |
4338 |
25 Jun 12 |
fredrik |
879 |
+ "\n"); |
3700 |
07 May 10 |
fredrik |
880 |
List<String> acclist = requestSpectraExternalID.get(i); |
4338 |
25 Jun 12 |
fredrik |
881 |
for (String acc : acclist) { |
3700 |
07 May 10 |
fredrik |
882 |
output.write("PEPACC=" + acc + "\n"); |
3700 |
07 May 10 |
fredrik |
883 |
} |
3700 |
07 May 10 |
fredrik |
884 |
|
3700 |
07 May 10 |
fredrik |
// output.write("GPMp=" + "Null" + "\n"); |
3700 |
07 May 10 |
fredrik |
// (phit.getExperimentalMassInDaltons() - |
3700 |
07 May 10 |
fredrik |
// phit.getDeltaMassInDaltons()) + "\t" + |
3700 |
07 May 10 |
fredrik |
// phit.getPeakListFile() + "\t" + |
3700 |
07 May 10 |
fredrik |
// phit.getSpectrumStringId() + "\t" + |
3700 |
07 May 10 |
fredrik |
// phit.getCombinedFDR() + "\n"); |
3700 |
07 May 10 |
fredrik |
// output.write(retentionTime + "\n"); |
3700 |
07 May 10 |
fredrik |
892 |
|
3700 |
07 May 10 |
fredrik |
// normalized intensities so that the most intense |
3700 |
07 May 10 |
fredrik |
// peak has the value of 100 |
3700 |
07 May 10 |
fredrik |
895 |
double max = 0; |
3700 |
07 May 10 |
fredrik |
896 |
double[] normalizedIntensities = new double[intensities.length]; |
4338 |
25 Jun 12 |
fredrik |
897 |
for (double inte : intensities) { |
4338 |
25 Jun 12 |
fredrik |
898 |
if (inte > max) { |
3700 |
07 May 10 |
fredrik |
899 |
max = inte; |
3700 |
07 May 10 |
fredrik |
900 |
} |
3700 |
07 May 10 |
fredrik |
901 |
} |
3700 |
07 May 10 |
fredrik |
902 |
double ratio = 100 / max; |
4338 |
25 Jun 12 |
fredrik |
903 |
for (int j = 0; j < intensities.length; j++) { |
3700 |
07 May 10 |
fredrik |
904 |
normalizedIntensities[j] = ratio * intensities[j]; |
3700 |
07 May 10 |
fredrik |
905 |
} |
3700 |
07 May 10 |
fredrik |
906 |
|
3700 |
07 May 10 |
fredrik |
// print out masses and intensities |
4338 |
25 Jun 12 |
fredrik |
908 |
if (masses.length == normalizedIntensities.length) { |
4338 |
25 Jun 12 |
fredrik |
909 |
for (int k = 0; k < masses.length; k++) { |
3700 |
07 May 10 |
fredrik |
910 |
output.write(masses[k] + " " + // tab cannot be |
4338 |
25 Jun 12 |
fredrik |
// accepted |
4338 |
25 Jun 12 |
fredrik |
912 |
normalizedIntensities[k] + "\n"); |
3700 |
07 May 10 |
fredrik |
913 |
} |
4338 |
25 Jun 12 |
fredrik |
914 |
} else { |
4338 |
25 Jun 12 |
fredrik |
915 |
output.write("The length of the two arrays is not equal\n"); |
3700 |
07 May 10 |
fredrik |
916 |
} |
3700 |
07 May 10 |
fredrik |
917 |
|
3700 |
07 May 10 |
fredrik |
// First check if there are any peptide hits that are |
3700 |
07 May 10 |
fredrik |
// missing total |
3700 |
07 May 10 |
fredrik |
// intensity and if missing either of them, |
3700 |
07 May 10 |
fredrik |
// if (phit.getSpectrumId() != null && |
3700 |
07 May 10 |
fredrik |
// phit.getSpectrumId().intValue() > 0 && |
3700 |
07 May 10 |
fredrik |
// (phit.getTotalIntensity() == null || phit |
3700 |
07 May 10 |
fredrik |
// .getRetentionTimeInMinutes() == null)) |
3700 |
07 May 10 |
fredrik |
925 |
// { |
3700 |
07 May 10 |
fredrik |
926 |
|
3700 |
07 May 10 |
fredrik |
// double totint = 0; |
3700 |
07 May 10 |
fredrik |
// totalIntensities.add(new Double(totint)); |
3700 |
07 May 10 |
fredrik |
// calculating total intensity |
3700 |
07 May 10 |
fredrik |
// double[] intensities = spec.listIntensities(); |
3700 |
07 May 10 |
fredrik |
// for (int i = 0; i < intensities.length; i++) |
3700 |
07 May 10 |
fredrik |
932 |
// { |
3700 |
07 May 10 |
fredrik |
// totint += intensities[i]; |
3700 |
07 May 10 |
fredrik |
934 |
// } |
3700 |
07 May 10 |
fredrik |
// totalIntensities.add(new Double(totint)); |
3700 |
07 May 10 |
fredrik |
936 |
// } |
3700 |
07 May 10 |
fredrik |
937 |
|
3700 |
07 May 10 |
fredrik |
938 |
output.write("END IONS" + "\n\n"); |
3700 |
07 May 10 |
fredrik |
939 |
i++; |
3700 |
07 May 10 |
fredrik |
940 |
} |
3700 |
07 May 10 |
fredrik |
// output.write(requestSpectraNr + "\n"); |
3700 |
07 May 10 |
fredrik |
942 |
} |
3700 |
07 May 10 |
fredrik |
943 |
|
4264 |
26 Oct 11 |
fredrik |
944 |
else if (mspFormat) // use output2 |
3700 |
07 May 10 |
fredrik |
945 |
{ |
3700 |
07 May 10 |
fredrik |
946 |
PeakListFileInterface peaklistReader = null; |
4338 |
25 Jun 12 |
fredrik |
947 |
if (requestSpectraStringID.size() > 0) { |
4338 |
25 Jun 12 |
fredrik |
948 |
log.info("Spectra to retrieve:" |
4338 |
25 Jun 12 |
fredrik |
949 |
+ requestSpectraStringID.size()); |
4338 |
25 Jun 12 |
fredrik |
950 |
if (pklFile.getFileType().getSystemId() |
4338 |
25 Jun 12 |
fredrik |
951 |
.equals(FileType.MGF_PEAK_LIST)) { |
4338 |
25 Jun 12 |
fredrik |
952 |
MgfFileReader mgfReader = new MgfFileReader( |
4338 |
25 Jun 12 |
fredrik |
953 |
pklFile.getDownloadStream(0)); |
3700 |
07 May 10 |
fredrik |
954 |
mgfReader.setTitleUsedAsId(true); |
3700 |
07 May 10 |
fredrik |
955 |
peaklistReader = (PeakListFileInterface) mgfReader; |
4338 |
25 Jun 12 |
fredrik |
956 |
} else if (pklFile.getFileType().getSystemId() |
4338 |
25 Jun 12 |
fredrik |
957 |
.equals(FileType.MZML)) { |
4338 |
25 Jun 12 |
fredrik |
958 |
peaklistReader = new MzMLFileReader( |
4338 |
25 Jun 12 |
fredrik |
959 |
pklFile.getDownloadStream(0)); |
4338 |
25 Jun 12 |
fredrik |
960 |
} else if (pklFile.getFileType().getSystemId() |
4338 |
25 Jun 12 |
fredrik |
961 |
.equals(FileType.MZDATA)) { // mzData |
4338 |
25 Jun 12 |
fredrik |
962 |
peaklistReader = new PeakListFileImpl( |
4338 |
25 Jun 12 |
fredrik |
963 |
pklFile.getDownloadStream(0)); |
4338 |
25 Jun 12 |
fredrik |
964 |
} else { |
3700 |
07 May 10 |
fredrik |
965 |
throw new BaseException( |
4338 |
25 Jun 12 |
fredrik |
966 |
pklFile.getName() |
4338 |
25 Jun 12 |
fredrik |
967 |
+ " is not an MGF or mzData file. Cannot retrieve reporter ion intensities"); |
3700 |
07 May 10 |
fredrik |
968 |
} |
3700 |
07 May 10 |
fredrik |
969 |
} |
3700 |
07 May 10 |
fredrik |
970 |
Iterator<SpectrumInterface> specins = peaklistReader |
4338 |
25 Jun 12 |
fredrik |
971 |
.getSpectrum(requestSpectraStringID); |
3700 |
07 May 10 |
fredrik |
972 |
int i = 0; |
4338 |
25 Jun 12 |
fredrik |
973 |
while (specins.hasNext()) { |
3700 |
07 May 10 |
fredrik |
974 |
SpectrumInterface spec = specins.next(); |
3700 |
07 May 10 |
fredrik |
975 |
|
3700 |
07 May 10 |
fredrik |
976 |
double[] masses; |
3700 |
07 May 10 |
fredrik |
977 |
double[] intensities; |
3700 |
07 May 10 |
fredrik |
978 |
double retentionTime = -1; |
3700 |
07 May 10 |
fredrik |
979 |
|
4338 |
25 Jun 12 |
fredrik |
980 |
if (spec.listMass() != null) { |
3700 |
07 May 10 |
fredrik |
981 |
masses = spec.listMass(); |
4338 |
25 Jun 12 |
fredrik |
982 |
} else { |
3700 |
07 May 10 |
fredrik |
983 |
masses = null; |
3700 |
07 May 10 |
fredrik |
984 |
} |
4338 |
25 Jun 12 |
fredrik |
985 |
if (spec.listIntensities() != null) { |
3700 |
07 May 10 |
fredrik |
986 |
intensities = spec.listIntensities(); |
4338 |
25 Jun 12 |
fredrik |
987 |
} else { |
3700 |
07 May 10 |
fredrik |
988 |
intensities = null; |
3700 |
07 May 10 |
fredrik |
989 |
} |
4338 |
25 Jun 12 |
fredrik |
990 |
if (spec.getRetentionTimeInMinutes() != null) { |
3700 |
07 May 10 |
fredrik |
991 |
retentionTime = spec.getRetentionTimeInMinutes(); |
3700 |
07 May 10 |
fredrik |
992 |
} |
3700 |
07 May 10 |
fredrik |
993 |
Float experimentalMassD = requestSpectraExperimentalMassD |
4338 |
25 Jun 12 |
fredrik |
994 |
.get(i); |
3700 |
07 May 10 |
fredrik |
995 |
Float deltaMassD = requestSpectraDeltaMassD.get(i); |
3700 |
07 May 10 |
fredrik |
996 |
Integer charge = requestSpectraCharge.get(i); |
3700 |
07 May 10 |
fredrik |
// Calculate the theoretical m/z and mass |
4338 |
25 Jun 12 |
fredrik |
998 |
Float mz = new Float((experimentalMassD - deltaMassD) |
4338 |
25 Jun 12 |
fredrik |
999 |
/ charge + MONOISTOPIC_PROTON_MASS); |
3700 |
07 May 10 |
fredrik |
1000 |
Float mass = experimentalMassD - deltaMassD; |
4300 |
13 Mar 12 |
fredrik |
1001 |
String mods = processModificationMSP(output2, factory, |
4338 |
25 Jun 12 |
fredrik |
1002 |
requestSpectraSEQ.get(i), |
4338 |
25 Jun 12 |
fredrik |
1003 |
requestSpectraModification.get(i), fixedMods); |
4545 |
26 Feb 14 |
fredrik |
1004 |
List<ObservedModification> obsMods = ObservedModification.getModList(requestSpectraSEQ.get(i), requestSpectraModification.get(i), |
4545 |
26 Feb 14 |
fredrik |
1005 |
fixedMods, factory); |
4545 |
26 Feb 14 |
fredrik |
1006 |
se.lth.immun.chem.Peptide pep = PeptideUtil.standardPeptideFromString(requestSpectraSEQ.get(i)); |
4545 |
26 Feb 14 |
fredrik |
1007 |
for (ObservedModification om : obsMods) |
4545 |
26 Feb 14 |
fredrik |
1008 |
{ |
4545 |
26 Feb 14 |
fredrik |
1009 |
int pos = om.getPosition(); |
4548 |
28 Feb 14 |
fredrik |
1010 |
if (om.getDiffFormula()!=null) |
4548 |
28 Feb 14 |
fredrik |
1011 |
{ |
4548 |
28 Feb 14 |
fredrik |
1012 |
ModifiedAminoAcid maa = new ModifiedAminoAcid(pep.aminoAcids[pos],Modifier.parseMolecule(om.getDiffFormula())); |
4548 |
28 Feb 14 |
fredrik |
1013 |
pep.aminoAcids[pos]=maa; |
4548 |
28 Feb 14 |
fredrik |
1014 |
} |
4548 |
28 Feb 14 |
fredrik |
1015 |
else |
4548 |
28 Feb 14 |
fredrik |
1016 |
{ |
4548 |
28 Feb 14 |
fredrik |
1017 |
output2.write("WARNING! Couldn't calculate modification properly for peptide:"+om.getName()+"\n"); |
4548 |
28 Feb 14 |
fredrik |
1018 |
} |
4545 |
26 Feb 14 |
fredrik |
1019 |
} |
4545 |
26 Feb 14 |
fredrik |
1020 |
List<Ion<PeptideFragment>> ions = PeptideUtil.possibleYAndBIons(pep, 2); |
4300 |
13 Mar 12 |
fredrik |
1021 |
output2.write(charge + "\n" + "MW: " + mass + "\n"); |
3700 |
07 May 10 |
fredrik |
// List<Double> parent = new ArrayList<Double>(); |
3700 |
07 May 10 |
fredrik |
// List<Integer> charge = new ArrayList<Integer>(); |
3700 |
07 May 10 |
fredrik |
// log.debug(precursors.size()); |
3700 |
07 May 10 |
fredrik |
// if (!precursors.equals(null)) { |
3700 |
07 May 10 |
fredrik |
// for (int k=0; k < precursors.size(); k++) { |
3700 |
07 May 10 |
fredrik |
// SpectrumPrecursor sp = precursors.get(k); |
3700 |
07 May 10 |
fredrik |
// parent.add(sp.getMassToChargeRatio()); |
3700 |
07 May 10 |
fredrik |
// charge.add(sp.getCharge()); |
3700 |
07 May 10 |
fredrik |
// output2.write(charge.get(k) |
3700 |
07 May 10 |
fredrik |
// + "\n" + "MW: " + parent.get(k)*charge.get(k) + "\n"); |
3700 |
07 May 10 |
fredrik |
1032 |
// } |
3700 |
07 May 10 |
fredrik |
1033 |
// } |
3700 |
07 May 10 |
fredrik |
// else { |
3700 |
07 May 10 |
fredrik |
// output2.write("null" + "\n" + "null\n"); |
3700 |
07 May 10 |
fredrik |
1036 |
// } |
3700 |
07 May 10 |
fredrik |
1037 |
|
3700 |
07 May 10 |
fredrik |
// comment line |
3700 |
07 May 10 |
fredrik |
1039 |
output2.write("Comment:"); |
3700 |
07 May 10 |
fredrik |
1040 |
output2.write(" OrigFile=" + pklFile.getName()); // Used to |
3700 |
07 May 10 |
fredrik |
// be |
3700 |
07 May 10 |
fredrik |
// PeakListfile |
3700 |
07 May 10 |
fredrik |
1043 |
output2.write(" RetentionTime=" + retentionTime); |
4338 |
25 Jun 12 |
fredrik |
1044 |
output2.write(" 1-evalue=" + (1 - requestSpectraEXP.get(i))); |
3700 |
07 May 10 |
fredrik |
1045 |
output2.write(" CombinedFDR=" + requestSpectraFDR.get(i)); |
3700 |
07 May 10 |
fredrik |
1046 |
output2.write(" ExperimentalMass=" + experimentalMassD); |
3700 |
07 May 10 |
fredrik |
1047 |
output2.write(" DeltaMass=" + deltaMassD); |
3700 |
07 May 10 |
fredrik |
1048 |
output2.write(" Parent=" + mz); // used to be TheoreticalMZ |
3700 |
07 May 10 |
fredrik |
// output2.write(" Spec= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Pep=Tryptic"); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Fullname= "); |
4547 |
28 Feb 14 |
fredrik |
1052 |
output2.write(" Protein=\""+requestSpectraProtein.get(i)+"\""); |
4338 |
25 Jun 12 |
fredrik |
1053 |
if (mods == null) { |
4300 |
13 Mar 12 |
fredrik |
1054 |
output2.write(" Mods=0 \n"); |
4338 |
25 Jun 12 |
fredrik |
1055 |
} else { |
4300 |
13 Mar 12 |
fredrik |
1056 |
output2.write(" Mods=" + mods + " \n"); |
3700 |
07 May 10 |
fredrik |
1057 |
} |
3700 |
07 May 10 |
fredrik |
// output2.write(" Parent=" + parent.get(0)); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Inst= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Mz_diff= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Mz_exact= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Mz_az= "); |
4547 |
28 Feb 14 |
fredrik |
1063 |
|
3700 |
07 May 10 |
fredrik |
// output2.write(" /gene= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" /function= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Pseq= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Organism= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Se= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Sample= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Nreps= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Missing= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Parent_med= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Max2med_orig= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Dotfull= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Dot_cons= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Unassign_all= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Unassigned= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Dotbest= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Flags= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Naa= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" DUScorr= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Dottheory= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Pfin= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Probcorr= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Tfratio= "); |
3700 |
07 May 10 |
fredrik |
// output2.write(" Pfract= "); |
3700 |
07 May 10 |
fredrik |
1087 |
|
3700 |
07 May 10 |
fredrik |
// normalized intensities so that the most intense |
3700 |
07 May 10 |
fredrik |
// peak has the value of 10000 (changed from 100) |
3700 |
07 May 10 |
fredrik |
1090 |
double max = 0; |
4338 |
25 Jun 12 |
fredrik |
1091 |
for (double inte : intensities) { |
4338 |
25 Jun 12 |
fredrik |
1092 |
if (inte > max) { |
3700 |
07 May 10 |
fredrik |
1093 |
max = inte; |
3700 |
07 May 10 |
fredrik |
1094 |
} |
3700 |
07 May 10 |
fredrik |
1095 |
} |
3700 |
07 May 10 |
fredrik |
1096 |
double ratio = 10000 / max; |
3700 |
07 May 10 |
fredrik |
1097 |
List<Double> mzs = new ArrayList<Double>(); |
3700 |
07 May 10 |
fredrik |
1098 |
List<Integer> ints = new ArrayList<Integer>(); |
4338 |
25 Jun 12 |
fredrik |
1099 |
for (int j = 0; j < intensities.length; j++) { |
3700 |
07 May 10 |
fredrik |
1100 |
int ni = (int) (ratio * intensities[j]); |
4338 |
25 Jun 12 |
fredrik |
1101 |
if (ni > 5) { |
3700 |
07 May 10 |
fredrik |
1102 |
mzs.add(new Double(masses[j])); |
3700 |
07 May 10 |
fredrik |
1103 |
ints.add(new Integer(ni)); |
3700 |
07 May 10 |
fredrik |
1104 |
} |
3700 |
07 May 10 |
fredrik |
1105 |
} |
3700 |
07 May 10 |
fredrik |
1106 |
|
3700 |
07 May 10 |
fredrik |
1107 |
output2.write("Num peaks: " + mzs.size() + "\n"); |
3700 |
07 May 10 |
fredrik |
// print out masses and intensities |
4338 |
25 Jun 12 |
fredrik |
1109 |
for (int l = 0; l < mzs.size(); l++) { |
4546 |
27 Feb 14 |
fredrik |
1110 |
List<Ion<PeptideFragment>> matchedIons = PeptideUtil.matchingIons(ions, mzs.get(l), mzTolerance); |
4546 |
27 Feb 14 |
fredrik |
1111 |
if (!matchedIons.isEmpty()) |
4545 |
26 Feb 14 |
fredrik |
1112 |
{ |
4546 |
27 Feb 14 |
fredrik |
1113 |
double mzTheoretical = matchedIons.get(0).mz(); |
4546 |
27 Feb 14 |
fredrik |
1114 |
String s = PeptideUtil.matchedIonsAsString(matchedIons); |
4546 |
27 Feb 14 |
fredrik |
1115 |
output2.write(fourDecimals.format(mzTheoretical) + "\t" |
4546 |
27 Feb 14 |
fredrik |
1116 |
+ ints.get(l) + "\t\""+s+"\"\n"); |
4545 |
26 Feb 14 |
fredrik |
1117 |
} |
4545 |
26 Feb 14 |
fredrik |
1118 |
else |
4545 |
26 Feb 14 |
fredrik |
1119 |
{ |
4546 |
27 Feb 14 |
fredrik |
1120 |
output2.write(fourDecimals.format(mzs.get(l)) + "\t" |
4546 |
27 Feb 14 |
fredrik |
1121 |
+ ints.get(l) + "\t\"?\"\n"); |
4545 |
26 Feb 14 |
fredrik |
1122 |
} |
3700 |
07 May 10 |
fredrik |
1123 |
} |
3700 |
07 May 10 |
fredrik |
1124 |
output2.write("\n"); |
3700 |
07 May 10 |
fredrik |
1125 |
i++; |
3700 |
07 May 10 |
fredrik |
// output.write(requestSpectraNr + "\n"); |
3700 |
07 May 10 |
fredrik |
1127 |
} // while |
3700 |
07 May 10 |
fredrik |
1128 |
} // if |
4338 |
25 Jun 12 |
fredrik |
1129 |
} catch (Exception e) { |
3700 |
07 May 10 |
fredrik |
1130 |
throw new BaseException(e); |
3700 |
07 May 10 |
fredrik |
1131 |
} |
3700 |
07 May 10 |
fredrik |
1132 |
} |
3700 |
07 May 10 |
fredrik |
1133 |
|
4300 |
13 Mar 12 |
fredrik |
1134 |
|
4300 |
13 Mar 12 |
fredrik |
1135 |
|
4338 |
25 Jun 12 |
fredrik |
1136 |
private int getStartPosition(String accession, String sequence, DbControl dc) { |
3700 |
07 May 10 |
fredrik |
1137 |
ItemQuery<Peptide> pepQuery = Peptide.getQuery(); |
3700 |
07 May 10 |
fredrik |
1138 |
String[] s = sequence.split(" "); |
3700 |
07 May 10 |
fredrik |
1139 |
List<Peptide> pepList = null; |
4338 |
25 Jun 12 |
fredrik |
1140 |
if (accession != null && accession.length() > 0 && sequence != null |
4338 |
25 Jun 12 |
fredrik |
1141 |
&& sequence.length() > 0) { |
3700 |
07 May 10 |
fredrik |
1142 |
pepQuery.restrict(Restrictions.eq(Hql.property("accessionNumber"), |
4338 |
25 Jun 12 |
fredrik |
1143 |
Expressions.parameter("accessionNumber"))); |
3700 |
07 May 10 |
fredrik |
1144 |
pepQuery.setParameter("accessionNumber", accession, null); |
3700 |
07 May 10 |
fredrik |
1145 |
pepQuery.restrict(Restrictions.eq(Hql.property("sequence"), |
4338 |
25 Jun 12 |
fredrik |
1146 |
Expressions.parameter("sequence"))); |
3700 |
07 May 10 |
fredrik |
1147 |
pepQuery.setParameter("sequence", s[0], null); |
3700 |
07 May 10 |
fredrik |
1148 |
pepList = pepQuery.list(dc); |
3700 |
07 May 10 |
fredrik |
1149 |
} |
4338 |
25 Jun 12 |
fredrik |
1150 |
if (pepList != null && !pepList.isEmpty()) { |
3700 |
07 May 10 |
fredrik |
1151 |
return pepList.get(0).getStartPosition(); |
4338 |
25 Jun 12 |
fredrik |
1152 |
} else { |
3700 |
07 May 10 |
fredrik |
1153 |
return 0; |
3700 |
07 May 10 |
fredrik |
1154 |
} |
3700 |
07 May 10 |
fredrik |
1155 |
} |
4301 |
13 Mar 12 |
fredrik |
1156 |
|
4338 |
25 Jun 12 |
fredrik |
1157 |
private class PeakListHitComparator implements Comparator<Hit> { |
4301 |
13 Mar 12 |
fredrik |
1158 |
@Override |
4338 |
25 Jun 12 |
fredrik |
1159 |
public int compare(Hit o1, Hit o2) { |
4301 |
13 Mar 12 |
fredrik |
1160 |
return o1.getPeakListFile().getId() - o2.getPeakListFile().getId(); |
4301 |
13 Mar 12 |
fredrik |
1161 |
} |
4300 |
13 Mar 12 |
fredrik |
1162 |
} |
4300 |
13 Mar 12 |
fredrik |
1163 |
|
3700 |
07 May 10 |
fredrik |
1164 |
} |