-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMzTabTest.java
433 lines (414 loc) · 19.1 KB
/
MzTabTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
/*
* Copyright 2018 Leibniz-Institut für Analytische Wissenschaften – ISAS – e.V..
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.lifstools.mztab2.model;
import org.lifstools.mztab2.model.IndexedElement;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.lifstools.mztab2.model.Assay;
import org.lifstools.mztab2.model.CV;
import org.lifstools.mztab2.model.Comment;
import org.lifstools.mztab2.model.Contact;
import org.lifstools.mztab2.model.Database;
import org.lifstools.mztab2.model.Instrument;
import org.lifstools.mztab2.model.MsRun;
import org.lifstools.mztab2.model.MzTab;
import org.lifstools.mztab2.model.OptColumnMapping;
import org.lifstools.mztab2.model.Parameter;
import org.lifstools.mztab2.model.Publication;
import org.lifstools.mztab2.model.PublicationItem;
import org.lifstools.mztab2.model.Sample;
import org.lifstools.mztab2.model.SampleProcessing;
import org.lifstools.mztab2.model.SmallMoleculeEvidence;
import org.lifstools.mztab2.model.SmallMoleculeFeature;
import org.lifstools.mztab2.model.SmallMoleculeSummary;
import org.lifstools.mztab2.model.Software;
import org.lifstools.mztab2.model.SpectraRef;
import org.lifstools.mztab2.model.StudyVariable;
import org.lifstools.mztab2.model.Uri;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.Assert;
import org.junit.Test;
/**
*
* @author nilshoffmann
*/
public class MzTabTest {
@Test
public void testMzTabObjectCreation() {
MzTab mztab = createTestMzTab();
Assert.assertEquals("SomeId 1234", mztab.getMetadata().
getMzTabID());
Assert.assertEquals("2.0.0-M", mztab.getMetadata().
getMzTabVersion());
Assert.assertEquals("My first test experiment", mztab.getMetadata().
getTitle());
Assert.assertEquals("An experiment investigating interesting effects.",
mztab.getMetadata().
getDescription());
Assert.assertEquals((long) 1, (long) mztab.getMetadata().
getSampleProcessing().
get(0).
getId());
Assert.assertEquals("sep:00210", mztab.getMetadata().
getSampleProcessing().
get(0).
getSampleProcessing().
get(0).
getCvAccession());
Assert.assertEquals(2, mztab.getMetadata().getInstrument().size());
Assert.assertEquals(1, mztab.getMetadata().getSoftware().size());
Assert.assertEquals(2, mztab.getMetadata().getPublication().size());
Assert.assertEquals(2, mztab.getMetadata().getUri().size());
Assert.assertEquals(1, mztab.getMetadata().getExternalStudyUri().size());
Assert.assertEquals(2, mztab.getMetadata().getMsRun().size());
Assert.assertEquals(1, mztab.getMetadata().getCustom().size());
Assert.assertEquals(2, mztab.getMetadata().getSample().size());
Assert.assertEquals(2, mztab.getMetadata().getAssay().size());
Assert.assertEquals(2, mztab.getMetadata().getStudyVariable().size());
Assert.assertEquals(2, mztab.getMetadata().getCv().size());
Assert.assertEquals(1, mztab.getMetadata().getIdConfidenceMeasure().size());
Assert.assertEquals(1, mztab.getMetadata().getDatabase().size());
Assert.assertEquals(1, mztab.getSmallMoleculeSummary().size());
Assert.assertEquals(1, mztab.getSmallMoleculeFeature().size());
Assert.assertEquals(1, mztab.getSmallMoleculeEvidence().size());
}
public static MzTab createTestMzTab() {
int paramId = 1;
org.lifstools.mztab2.model.Metadata mtd = new org.lifstools.mztab2.model.Metadata();
mtd.mzTabID("SomeId 1234").
mzTabVersion("2.0.0-M").
title("My first test experiment").
description("An experiment investigating interesting effects.");
SampleProcessing sp = new SampleProcessing().id(1).
addSampleProcessingItem(new Parameter().id(paramId++).cvLabel("SEP").
cvAccession("sep:00210").
name("High Perfomance Liquid Chromatography"));
mtd.sampleProcessing(Arrays.asList(sp));
Instrument instrument1 = new Instrument().id(1).
name(
new Parameter().id(paramId++).cvLabel("MS").
cvAccession("MS:100049").
name("LTQ Orbitrap")).
source(
new Parameter().id(paramId++).cvLabel("MS").
cvAccession("MS:1000073").
name("ESI")).
analyzer(Arrays.asList(
new Parameter().id(paramId++).cvLabel("MS").
cvAccession("MS:1000291").
name("linear ion trap"))
).
detector(
new Parameter().id(paramId++).cvLabel("MS").
cvAccession("MS:1000253").
name("electron multiplier")
);
mtd.addInstrumentItem(instrument1);
Instrument instrument2 = new Instrument().id(2).
name(
new Parameter().id(paramId++).cvLabel("MS").
cvAccession("MS:1000031").
name("instrument model").
value("name of the instrument not included in the CV")).
source(new Parameter().id(paramId++).cvLabel("MS").
cvAccession("MS:1000598").
name("ETD")).
addAnalyzerItem(new Parameter().id(paramId++).cvLabel("MS").
cvAccession("MS:1000484").
name("orbitrap")).
detector(new Parameter().id(paramId++).cvLabel("MS").
cvAccession("MS:1000348").
name("focal plane collector"));
mtd.addInstrumentItem(instrument2);
Software software1 = new Software().id(1).
parameter(new Parameter().id(paramId++).cvLabel(
"MS").
cvAccession("MS:1001207").
name("Mascot").
value("2.3")).
setting(Arrays.asList("Fragment tolerance = 0.1Da",
"Parent tolerance = 0.5Da"));
mtd.addSoftwareItem(software1);
PublicationItem item1_1 = new PublicationItem().type(
PublicationItem.TypeEnum.PUBMED).
accession("21063943");
PublicationItem item1_2 = new PublicationItem().type(
PublicationItem.TypeEnum.DOI).
accession("10.1007/978-1-60761-987-1_6");
Publication publication1 = new Publication().id(1);
publication1.setPublicationItems(Arrays.asList(item1_1, item1_2));
PublicationItem item2_1 = new PublicationItem().type(
PublicationItem.TypeEnum.PUBMED).
accession("20615486");
PublicationItem item2_2 = new PublicationItem().type(
PublicationItem.TypeEnum.DOI).
accession("10.1016/j.jprot.2010.06.008");
Publication publication2 = new Publication().id(2);
publication2.setPublicationItems(Arrays.asList(item2_1, item2_2));
mtd.addPublicationItem(publication1).
addPublicationItem(publication2);
mtd.addContactItem(new Contact().id(1).
name("James D. Watson").
affiliation("Cambridge University, UK").
email("watson@cam.ac.uk"));
mtd.addContactItem(new Contact().id(2).
name("Francis Crick").
affiliation("Cambridge University, UK").
email("crick@cam.ac.uk"));
mtd.addUriItem(new Uri().id(1).
value(
"http://www.ebi.ac.uk/pride/url/to/experiment"));
mtd.addUriItem(new Uri().id(2).
value(
"http://proteomecentral.proteomexchange.org/cgi/GetDataset"));
mtd.addExternalStudyUriItem(new Uri().id(3).
value(
"https://www.ebi.ac.uk/metabolights/MTBLS400"));
MsRun msRun1 = new MsRun().name("file1").id(1).
location("file://ftp.ebi.ac.uk/path/to/file").
idFormat(new Parameter().id(paramId++).cvLabel("MS").
cvAccession("MS:1001530").
name(
"mzML unique identifier")).
format(new Parameter().id(paramId++).cvLabel("MS").
cvAccession("MS:1000584").
name("mzML file")).
addFragmentationMethodItem(
new Parameter().id(paramId++).cvLabel("MS").
cvAccession("MS:1000133").
name("CID"));
mtd.addMsRunItem(msRun1);
MsRun msRun2 = new MsRun().name("file2").id(2).
location("ftp://ftp.ebi.ac.uk/path/to/file").
format(new Parameter().id(paramId++).cvLabel("MS").
cvAccession("MS:1001062").
name("Mascot MGF file")).
hash("de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3").
hashMethod(
new Parameter().id(paramId++).cvLabel("MS").
cvAccession("MS:1000569").
name("SHA-1")).
addFragmentationMethodItem(new Parameter().id(paramId++).cvLabel("MS").
cvAccession("MS:1000422").
name("HCD"));
mtd.addMsRunItem(msRun2);
mtd.addCustomItem(new Parameter().id(paramId++).
name("MS operator").
value("Florian"));
Sample sample1 = new Sample().id(1).
description("Hepatocellular carcinoma samples.").
addSpeciesItem(new Parameter().id(paramId++).cvLabel("NEWT").
cvAccession("9606").
name(
"Homo sapiens (Human)")).
addSpeciesItem(new Parameter().id(paramId++).cvLabel("NEWT").
cvAccession("573824").
name("Human rhinovirus 1")).
addTissueItem(new Parameter().id(paramId++).cvLabel("BTO").
cvAccession("BTO:0000759").
name("liver")).
addCellTypeItem(new Parameter().id(paramId++).cvLabel("CL").
cvAccession("CL:0000182").
name("hepatocyte")).
addDiseaseItem(new Parameter().id(paramId++).cvLabel("DOID").
cvAccession("DOID:684").
name("hepatocellular carcinoma")).
addDiseaseItem(new Parameter().id(paramId++).cvLabel("DOID").
cvAccession("DOID:9451").
name("alcoholic fatty liver")).
addCustomItem(new Parameter().id(paramId++).name("Extraction date").
value("2011-12-21")).
addCustomItem(new Parameter().id(paramId++).name("Extraction reason").
value("liver biopsy"));
mtd.addSampleItem(sample1);
Sample sample2 = new Sample().id(2).
name("Sample 2").
description("Healthy control samples.").
addSpeciesItem(new Parameter().id(paramId++).cvLabel("NEWT").
cvAccession("9606").
name(
"Homo sapiens (Human)")).
addSpeciesItem(new Parameter().id(paramId++).cvLabel("NEWT").
cvAccession("12130").
name("Human rhinovirus 2")).
addTissueItem(new Parameter().id(paramId++).cvLabel("BTO").
cvAccession("BTO:0000759").
name("liver")).
addCellTypeItem(new Parameter().id(paramId++).cvLabel("CL").
cvAccession("CL:0000182").
name("hepatocyte")).
addCustomItem(new Parameter().id(paramId++).name("Extraction date").
value("2011-12-19")).
addCustomItem(new Parameter().id(paramId++).name("Extraction reason").
value("liver biopsy"));
mtd.addSampleItem(sample2);
Assay assay1 = new Assay().id(1).
name("Assay 1").
addMsRunRefItem(msRun1).
sampleRef(sample1);
mtd.addAssayItem(assay1);
Assay assay2 = new Assay().id(2).
name("Assay 2").
addMsRunRefItem(msRun2).
sampleRef(sample2);
mtd.addAssayItem(assay2);
StudyVariable studyVariable1 = new StudyVariable().
id(1).
name("Group A name").
description(
"Group A description").
addAssayRefsItem(
assay1).
addAssayRefsItem(assay2).
addFactorsItem(new Parameter().id(paramId++).name("spike-in").
value("0.74 fmol/uL"));
mtd.addStudyVariableItem(studyVariable1);
StudyVariable studyVariable2 = new StudyVariable().
id(2).
name("Grou B name").
description("Group B description").
addAssayRefsItem(assay1).
addAssayRefsItem(assay2).
addFactorsItem(new Parameter().id(paramId++).name("spike-in").
value("0.74 fmol/uL"));
mtd.addStudyVariableItem(studyVariable2);
mtd.addCvItem(new CV().id(1).
label("MS").
fullName("PSI-MS ontology").
version("3.54.0").
uri("https://raw.githubusercontent.com/HUPO-PSI/psi-ms-CV/master/psi-ms.obo"));
mtd.addCvItem(new CV().id(2).
label("SEP").
fullName("Sample Processing and Separation Techniques Ontology").
version("1.070708").
uri("http://purl.bioontology.org/ontology/SEP"));
mtd.addIdConfidenceMeasureItem(new Parameter().id(paramId++).
name("some confidence measure term"));
mtd.addDatabaseItem(new Database().id(1).//prefix("null").
param(new Parameter().id(paramId++).name("nd")));
mtd.setQuantificationMethod(new Parameter().id(paramId++).name("test quantification").value("test quant value"));
MzTab mzTab = new MzTab();
mzTab.metadata(mtd);
SmallMoleculeEvidence sme = new SmallMoleculeEvidence().smeId(1).
addIdConfidenceMeasureItem(1.00).
addSpectraRefItem(new SpectraRef().msRun(msRun2).
reference("index=2")).
charge(1).
chemicalFormula("C42H83NO3").
chemicalName("Cer(d18:1/24:0)").
databaseIdentifier("nd").
evidenceInputId("1").
expMassToCharge(650.6373).
msLevel(new Parameter().id(paramId++).cvLabel("MS").
cvAccession("MS:1000511").
name("ms level").
value("2")).
rank(1).
smiles(
"CCCCCCCCCCCCCCCCCCCCCCCC(=O)N[C@@H](CO)[C@H](O)/C=C/CCCCCCCCCCCCC").
theoreticalMassToCharge(649.6373).
uri("http://link.to.me/hj551a-2asdkj-12451").
addCommentItem(new Comment().prefix(Comment.PrefixEnum.COM).
msg("Needs further investigation"));
SmallMoleculeFeature smf = new SmallMoleculeFeature().smfId(1).
addSmeIdRefsItem(sme.getSmeId()).
adductIon("[M+H]1+").
charge(1).
expMassToCharge(650.6373).
retentionTimeInSeconds(346.34).
retentionTimeInSecondsEnd(349.87).
retentionTimeInSecondsStart(342.98).
smeIdRefAmbiguityCode(1).
addOptItem(new OptColumnMapping().identifier("global").
value("idk"));
mzTab.addSmallMoleculeFeatureItem(smf);
mzTab.addSmallMoleculeEvidenceItem(sme);
SmallMoleculeSummary smsi = new SmallMoleculeSummary();
smsi.smlId(1).
addSmfIdRefsItem(smf.getSmfId()).
chemicalName(Arrays.asList("Cer(d18:1/24:0)",
"N-(tetracosanoyl)-sphing-4-enine", "C24 Cer")).
addOptItem(new OptColumnMapping().identifier("global").
value("lipid_category").
param(new Parameter().id(paramId++).cvLabel("LM").
cvAccession("LM:SP").
name("Category").
value("Sphingolipids"))).
addOptItem(new OptColumnMapping().identifier("global").
value("lipid_species").
param(new Parameter().id(paramId++).cvLabel("LH").
cvAccession("LH:XXXXX").
name("Species").
value("Cer 42:1"))).
addOptItem(new OptColumnMapping().identifier("global").
value("lipid_best_id_level").
param(new Parameter().id(paramId++).cvLabel("LH").
cvAccession("LH:XXXXX").
name("Sub Species").
value("Cer d18:1/24:0"))).
addDatabaseIdentifierItem("LM:LMSP02010012").
addChemicalFormulaItem("C42H83NO3").
addSmilesItem(
"CCCCCCCCCCCCCCCCCCCCCCCC(=O)N[C@@H](CO)[C@H](O)/C=C/CCCCCCCCCCCCC").
addInchiItem(
"InChI=1S/C42H83NO3/c1-3-5-7-9-11-13-15-17-18-19-20-21-22-23-24-26-28-30-32-34-36-38-42(46)43-40(39-44)41(45)37-35-33-31-29-27-25-16-14-12-10-8-6-4-2/h35,37,40-41,44-45H,3-34,36,38-39H2,1-2H3,(H,43,46)/b37-35+/t40-,41+/m0/s1").
addUriItem(
"http://www.lipidmaps.org/data/LMSDRecord.php?LM_ID=LMSP02010012").
addTheoreticalNeutralMassItem(649.6373).
addAdductIonsItem("[M+H]1+").
reliability("1").
bestIdConfidenceMeasure(new Parameter().id(paramId++).name(
"qualifier ions exact mass")).
bestIdConfidenceValue(0.958).
addAbundanceAssayItem(4.448784E-05).
addAbundanceAssayItem(5.448784E-05).
addAbundanceStudyVariableItem(4.448784E-05).
addAbundanceStudyVariableItem(5.448784E-05).
addAbundanceVariationStudyVariableItem(0.0d).
addAbundanceVariationStudyVariableItem(0.00001d);
mzTab.addSmallMoleculeSummaryItem(smsi);
return mzTab;
}
@Test
public void testWriteReadViaJsonMapper() throws IOException {
File testFile = File.createTempFile(
"testWriteJson", ".json");
MzTab testMzTab = createTestMzTab();
ObjectMapper mapper = new ObjectMapper();
try (BufferedWriter bw = Files.newBufferedWriter(testFile.toPath(),
StandardCharsets.UTF_8, StandardOpenOption.WRITE)) {
bw.write(mapper.writeValueAsString(testMzTab));
} catch (IOException ex) {
Logger.getLogger(MzTabTest.class.getName()).
log(Level.SEVERE, null, ex);
}
MzTab restoredFile = mapper.readValue(testFile, MzTab.class);
Assert.assertEquals(testMzTab, restoredFile);
}
@Test
public void testIndexedElementProxy() {
MsRun mr = new MsRun().id(1).location("location");
IndexedElement ie = IndexedElement.of(mr);
Assert.assertEquals(mr.getId(), ie.getId());
}
}