1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.io.specimen.abcd206.in;
|
11
|
|
12
|
import static org.junit.Assert.assertEquals;
|
13
|
import static org.junit.Assert.assertNotNull;
|
14
|
import static org.junit.Assert.assertTrue;
|
15
|
|
16
|
import java.io.FileNotFoundException;
|
17
|
import java.net.URI;
|
18
|
import java.net.URISyntaxException;
|
19
|
import java.net.URL;
|
20
|
import java.text.ParseException;
|
21
|
import java.util.List;
|
22
|
import java.util.Set;
|
23
|
import java.util.UUID;
|
24
|
|
25
|
import org.joda.time.DateTime;
|
26
|
import org.junit.Assert;
|
27
|
import org.junit.Test;
|
28
|
import org.unitils.dbunit.annotation.DataSet;
|
29
|
import org.unitils.spring.annotation.SpringBeanByName;
|
30
|
import org.unitils.spring.annotation.SpringBeanByType;
|
31
|
|
32
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
33
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
34
|
import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
|
35
|
import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultImport;
|
36
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
37
|
import eu.etaxonomy.cdm.model.media.MediaUtils;
|
38
|
import eu.etaxonomy.cdm.model.molecular.Amplification;
|
39
|
import eu.etaxonomy.cdm.model.molecular.AmplificationResult;
|
40
|
import eu.etaxonomy.cdm.model.molecular.DnaQuality;
|
41
|
import eu.etaxonomy.cdm.model.molecular.DnaSample;
|
42
|
import eu.etaxonomy.cdm.model.molecular.Primer;
|
43
|
import eu.etaxonomy.cdm.model.molecular.Sequence;
|
44
|
import eu.etaxonomy.cdm.model.molecular.SequenceDirection;
|
45
|
import eu.etaxonomy.cdm.model.molecular.SequenceString;
|
46
|
import eu.etaxonomy.cdm.model.molecular.SingleRead;
|
47
|
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
|
48
|
import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
|
49
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
50
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
51
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
52
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
53
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
54
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
55
|
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
|
56
|
|
57
|
/**
|
58
|
* @author a.mueller
|
59
|
* @created 29.01.2009
|
60
|
*/
|
61
|
public class AbcdGgbnImportTest extends CdmTransactionalIntegrationTest {
|
62
|
|
63
|
@SpringBeanByName
|
64
|
private CdmApplicationAwareDefaultImport<?> defaultImport;
|
65
|
|
66
|
@SpringBeanByType
|
67
|
private IOccurrenceService occurrenceService;
|
68
|
|
69
|
@SpringBeanByType
|
70
|
private IReferenceService referenceService;
|
71
|
|
72
|
/**
|
73
|
* Tests import import of DNA unit and all its parameters
|
74
|
* and sub derivatives (sequence, amplification, etc.)
|
75
|
* @throws ParseException
|
76
|
*/
|
77
|
@Test
|
78
|
@DataSet( value="../../../BlankDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
79
|
public void testImportGgbn() throws ParseException {
|
80
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/db6.xml";
|
81
|
URL url = this.getClass().getResource(inputFile);
|
82
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
83
|
|
84
|
Abcd206ImportConfigurator importConfigurator = null;
|
85
|
try {
|
86
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(url.toURI(), null,false);
|
87
|
} catch (URISyntaxException e) {
|
88
|
e.printStackTrace();
|
89
|
Assert.fail();
|
90
|
}
|
91
|
assertNotNull("Configurator could not be created", importConfigurator);
|
92
|
|
93
|
boolean result = defaultImport.invoke(importConfigurator);
|
94
|
assertTrue("Return value for import.invoke should be true", result);
|
95
|
assertEquals("Number of derived units is incorrect", 1, occurrenceService.count(DerivedUnit.class));
|
96
|
assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
|
97
|
assertEquals("Number of field units is incorrect", 1, occurrenceService.count(FieldUnit.class));
|
98
|
|
99
|
//associated specimen
|
100
|
FindOccurrencesConfigurator config = new FindOccurrencesConfigurator();
|
101
|
config.setSignificantIdentifier("B 10 0066577");
|
102
|
List<SpecimenOrObservationBase> records = occurrenceService.findByTitle(config).getRecords();
|
103
|
assertEquals(1, records.size());
|
104
|
SpecimenOrObservationBase derivedUnitSpecimen = records.iterator().next();
|
105
|
assertEquals(DerivedUnit.class, derivedUnitSpecimen.getClass());
|
106
|
DerivedUnit specimen = (DerivedUnit) derivedUnitSpecimen;
|
107
|
assertEquals("Herbarium Berolinense", specimen.getCollection().getName());
|
108
|
assertTrue(SpecimenOrObservationType.DnaSample!=specimen.getRecordBasis());
|
109
|
|
110
|
//dna sample
|
111
|
FindOccurrencesConfigurator dnaConfig = new FindOccurrencesConfigurator();
|
112
|
dnaConfig.setSignificantIdentifier("DB 6");
|
113
|
List<SpecimenOrObservationBase> dnaRecords = occurrenceService.findByTitle(dnaConfig).getRecords();
|
114
|
assertEquals(1, dnaRecords.size());
|
115
|
SpecimenOrObservationBase dnaSpecimen = dnaRecords.iterator().next();
|
116
|
assertEquals(DnaSample.class, dnaSpecimen.getClass());
|
117
|
DnaSample dnaSample = (DnaSample) dnaSpecimen;
|
118
|
DerivationEvent derivedFrom = dnaSample.getDerivedFrom();
|
119
|
assertNotNull(derivedFrom);
|
120
|
assertEquals("Wrong derivation type!", DerivationEventType.DNA_EXTRACTION(), derivedFrom.getType());
|
121
|
assertEquals("Wrong number of originals", 1, derivedFrom.getOriginals().size());
|
122
|
assertEquals("DNA Bank", dnaSample.getCollection().getCode());
|
123
|
assertEquals(SpecimenOrObservationType.DnaSample, dnaSample.getRecordBasis());
|
124
|
//preservation/preparation
|
125
|
assertNotNull(derivedFrom.getActor());
|
126
|
assertEquals("Bansemer, Jana", derivedFrom.getActor().getTitleCache());
|
127
|
assertNotNull(derivedFrom.getTimeperiod());
|
128
|
assertEquals((Integer)2002,derivedFrom.getTimeperiod().getStartYear());
|
129
|
assertEquals((Integer)8,derivedFrom.getTimeperiod().getStartMonth());
|
130
|
assertEquals((Integer)13,derivedFrom.getTimeperiod().getStartDay());
|
131
|
assertNotNull(dnaSample.getPreservation());
|
132
|
|
133
|
|
134
|
//dna quality
|
135
|
DnaQuality dnaQuality = dnaSample.getDnaQuality();
|
136
|
assertNotNull("Dna quality is null", dnaQuality!=null);
|
137
|
assertEquals(new Double("0.77"),dnaQuality.getRatioOfAbsorbance260_230());
|
138
|
assertEquals(new Double("1.38"),dnaQuality.getRatioOfAbsorbance260_280());
|
139
|
assertEquals(new DateTime(2008, 4, 15, 0, 0),dnaQuality.getQualityCheckDate());
|
140
|
// assertEquals(MeasurementUnit.NewInstance(, label, labelAbbrev)DateTime(2008, 4, 15, 0, 0),dnaQuality.getQualityCheckDate());
|
141
|
|
142
|
//amplifications
|
143
|
Set<AmplificationResult> amplificationResults = dnaSample.getAmplificationResults();
|
144
|
assertNotNull(amplificationResults);
|
145
|
assertEquals(1, amplificationResults.size());
|
146
|
AmplificationResult amplificationResult = amplificationResults.iterator().next();
|
147
|
Amplification amplification = amplificationResult.getAmplification();
|
148
|
assertNotNull("Amplification is null", amplification);
|
149
|
DefinedTerm dnaMarker = amplification.getDnaMarker();
|
150
|
assertNotNull(dnaMarker);
|
151
|
assertEquals("ITS (ITS1, 5.8S rRNA, ITS2)", dnaMarker.getLabel());
|
152
|
|
153
|
//amplification primers
|
154
|
Primer forwardPrimer = amplification.getForwardPrimer();
|
155
|
assertNotNull(forwardPrimer);
|
156
|
assertEquals("PIpetB1411F", forwardPrimer.getLabel());
|
157
|
assertEquals("5´-GCCGTMTTTATGTTAATGC-3´", forwardPrimer.getSequence().getString());
|
158
|
assertNotNull(forwardPrimer.getPublishedIn());
|
159
|
assertEquals("Löhne & Borsch 2005", forwardPrimer.getPublishedIn().getTitle());
|
160
|
|
161
|
Primer reversePrimer = amplification.getReversePrimer();
|
162
|
assertNotNull(reversePrimer);
|
163
|
assertEquals("PIpetD738R", reversePrimer.getLabel());
|
164
|
assertEquals("5´-AATTTAGCYCTTAATACAGG-3´", reversePrimer.getSequence().getString());
|
165
|
|
166
|
//sequencing
|
167
|
Set<Sequence> sequences = dnaSample.getSequences();
|
168
|
assertNotNull(sequences);
|
169
|
assertEquals(1, sequences.size());
|
170
|
Sequence sequence = sequences.iterator().next();
|
171
|
SequenceString consensusSequence = sequence.getConsensusSequence();
|
172
|
assertNotNull(consensusSequence);
|
173
|
assertEquals(
|
174
|
"TTTCGGGTCC TTTATAGTGA AGATATAGCA TAGATAGTTG TAATCCATTA" +
|
175
|
" TGTATCATTG GGGAAGGAAG GAGAATATTT TTTTGATAGA ATACAAGTAT" +
|
176
|
" GGATTATTGA AACTAATACG CCATGTATTT GGATATTTCC CTTGAACTGC" +
|
177
|
" ATAATATTCT TTATTTTCCA TGAATAGTGT AAGGGAATTT TTCGAAGAGA" +
|
178
|
" AAATGGATTA TGGGAGTGTG TGACTTGAGC TATTGATTGG TCTGTGCAGA" +
|
179
|
" TACGGGCTTT TATCTATCTG CCACATTGTA ATTCACAAAC CAATGTGTCT" +
|
180
|
" TTGTTCCAAC CATCGCGTAA GCCCCATACA GAAGATAGGC TGGTTCGCTT" +
|
181
|
" GAAGAGAATC TTTTCTATGA TCAGATCCGA ATTATGTCGT ACATGAGCAG" +
|
182
|
" GCTCCGTAAG ATCTAGTTGA CTTAAGTCAA ACTTCAATAG TATAAAAATG" +
|
183
|
" CACTCATTTC CTCTGCATTG ACACGAGCTA TGAGACTATC GGAGTGAAAG" +
|
184
|
" AAAGGGTCTA AAGAAGAAGA AAGCTTGGGC TAGATTAGTA ACAAGTAAAT" +
|
185
|
" CCTTTGTGTG TGTGTTTGTA ATTAGTAAAT GGGCTCTCAA TATTTTGGGG" +
|
186
|
" CTAATTACTG ATCCTAAGGT TTGAGACGAC CCAGAAAGCA CTTGATCATA" +
|
187
|
" TCACGATTGA CTTTGTAAGC CTACTTGGGT ATTGAGTATT TACTTGTAAG" +
|
188
|
" AACCGAATTC TTTGGGGGAT AGTTGCAAAA AGAATCCAGT CAATTGTTCT" +
|
189
|
" TACGTAAAAC CATTCATATC TCGTATATGG ATATGTCTAG ATAGGCTATC" +
|
190
|
" GATTTTCGAT GGATTCGTTT GGTTCTTTTG ATTATTGCTC GAGCTGGATG" +
|
191
|
" ATGAAAAATT ATCATGTCCG GTTCCTTCG",consensusSequence.getString());
|
192
|
// assertEquals((Integer)912, consensusSequence.getLength());
|
193
|
assertNotNull(sequence.getContigFile());
|
194
|
assertEquals(URI.create("http://ww2.biocase.org/websvn/filedetails.php?repname=campanula&path=%2FCAM385_Campa_drabifolia.pde"), MediaUtils.getFirstMediaRepresentationPart(sequence.getContigFile()).getUri());
|
195
|
assertEquals(1, sequence.getCitations().size());
|
196
|
Reference<?> reference = sequence.getCitations().iterator().next();
|
197
|
assertEquals("Gemeinholzer,B., Bachmann,K. (2005): Examining morphological "
|
198
|
+ "and molecular diagnostic character states in "
|
199
|
+ "Cichorium intybus L. (Asteraceae) and Cichorium spinosum L."
|
200
|
+ " Plant Systematics and Evolution 253 (1-3): 105-123.", reference.getTitle());
|
201
|
|
202
|
//single reads
|
203
|
Set<SingleRead> singleReads = sequence.getSingleReads();
|
204
|
assertNotNull(singleReads);
|
205
|
assertEquals(2, singleReads.size());
|
206
|
for (SingleRead singleRead : singleReads) {
|
207
|
if(singleRead.getDirection().equals(SequenceDirection.Forward)){
|
208
|
assertNotNull(singleRead.getPherogram());
|
209
|
assertEquals(URI.create("http://ww2.biocase.org/websvn/filedetails.php?repname=campanula&path=%2FCAM385_GM312-petD_F.ab1"), MediaUtils.getFirstMediaRepresentationPart(singleRead.getPherogram()).getUri());
|
210
|
}
|
211
|
else{
|
212
|
assertNotNull(singleRead.getPherogram());
|
213
|
assertEquals(URI.create("http://ww2.biocase.org/websvn/filedetails.php?repname=campanula&path=%2FCAM385_GM312-petD_R.ab1"), MediaUtils.getFirstMediaRepresentationPart(singleRead.getPherogram()).getUri());
|
214
|
}
|
215
|
}
|
216
|
assertNotNull(amplificationResult.getSingleReads());
|
217
|
assertEquals(amplificationResult.getSingleReads(), singleReads);
|
218
|
|
219
|
|
220
|
}
|
221
|
|
222
|
/**
|
223
|
* Tests import of DNA unit and attaching it to an existing specimen to which
|
224
|
* it has a UnitAssociation.
|
225
|
*/
|
226
|
@Test
|
227
|
@DataSet( value="AbcdGgbnImportTest.testAttachDnaSampleToDerivedUnit.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
228
|
public void testAttachDnaSampleToDerivedUnit(){
|
229
|
UUID derivedUnit1Uuid = UUID.fromString("eb40cb0f-efb2-4985-819e-a9168f6d61fe");
|
230
|
|
231
|
// DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
|
232
|
// derivedUnit.setAccessionNumber("B 10 0066577");
|
233
|
// derivedUnit.setTitleCache("testUnit1", true);
|
234
|
//
|
235
|
// derivedUnit.setUuid(derivedUnit1Uuid );
|
236
|
//
|
237
|
// occurrenceService.save(derivedUnit);
|
238
|
//
|
239
|
// commitAndStartNewTransaction(null);
|
240
|
//
|
241
|
// setComplete();
|
242
|
// endTransaction();
|
243
|
//
|
244
|
//
|
245
|
// try {
|
246
|
// writeDbUnitDataSetFile(new String[] {
|
247
|
// "SpecimenOrObservationBase",
|
248
|
// }, "testAttachDnaSampleToDerivedUnit");
|
249
|
// } catch (FileNotFoundException e) {
|
250
|
// e.printStackTrace();
|
251
|
// }
|
252
|
|
253
|
|
254
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/db6.xml";
|
255
|
URL url = this.getClass().getResource(inputFile);
|
256
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
257
|
|
258
|
Abcd206ImportConfigurator importConfigurator = null;
|
259
|
try {
|
260
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(url.toURI(), null,false);
|
261
|
} catch (URISyntaxException e) {
|
262
|
e.printStackTrace();
|
263
|
Assert.fail();
|
264
|
}
|
265
|
assertNotNull("Configurator could not be created", importConfigurator);
|
266
|
|
267
|
boolean result = defaultImport.invoke(importConfigurator);
|
268
|
assertTrue("Return value for import.invoke should be true", result);
|
269
|
assertEquals("Number of derived units is incorrect", 2, occurrenceService.count(DerivedUnit.class));
|
270
|
List<DerivedUnit> derivedUnits = occurrenceService.list(DerivedUnit.class, null, null, null, null);
|
271
|
assertEquals("Number of derived units is incorrect", 2, derivedUnits.size());
|
272
|
assertEquals("Number of field units is incorrect", 1, occurrenceService.count(FieldUnit.class));
|
273
|
assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
|
274
|
|
275
|
DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(derivedUnit1Uuid);
|
276
|
assertTrue(derivedUnits.contains(derivedUnit));
|
277
|
|
278
|
assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
|
279
|
DnaSample dnaSample = occurrenceService.list(DnaSample.class, null, null, null, null).get(0);
|
280
|
assertEquals("Wrong derivation type!", DerivationEventType.DNA_EXTRACTION(), dnaSample.getDerivedFrom().getType());
|
281
|
|
282
|
assertEquals("Wrong number of originals", 1, dnaSample.getDerivedFrom().getOriginals().size());
|
283
|
|
284
|
}
|
285
|
|
286
|
/**
|
287
|
* Tests importing of DNA unit without attaching it to an existing specimen.
|
288
|
* Creates a FieldUnit with an attached DnaSample.
|
289
|
*/
|
290
|
@Test
|
291
|
@DataSet( value="AbcdGgbnImportTest.testNoAttachDnaSampleToDerivedUnit.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
292
|
public void testNoAttachDnaSampleToDerivedUnit(){
|
293
|
UUID derivedUnit1Uuid = UUID.fromString("eb40cb0f-efb2-4985-819e-a9168f6d61fe");
|
294
|
|
295
|
// DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
|
296
|
// derivedUnit.setAccessionNumber("B 10 0066577");
|
297
|
// derivedUnit.setTitleCache("testUnit1", true);
|
298
|
//
|
299
|
// derivedUnit.setUuid(derivedUnit1Uuid );
|
300
|
//
|
301
|
// occurrenceService.save(derivedUnit);
|
302
|
//
|
303
|
// commitAndStartNewTransaction(null);
|
304
|
//
|
305
|
// setComplete();
|
306
|
// endTransaction();
|
307
|
//
|
308
|
//
|
309
|
// try {
|
310
|
// writeDbUnitDataSetFile(new String[] {
|
311
|
// "SpecimenOrObservationBase",
|
312
|
// }, "testAttachDnaSampleToDerivedUnit");
|
313
|
// } catch (FileNotFoundException e) {
|
314
|
// e.printStackTrace();
|
315
|
// }
|
316
|
|
317
|
|
318
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/db6.xml";
|
319
|
URL url = this.getClass().getResource(inputFile);
|
320
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
321
|
|
322
|
Abcd206ImportConfigurator importConfigurator = null;
|
323
|
try {
|
324
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(url.toURI(), null,false);
|
325
|
} catch (URISyntaxException e) {
|
326
|
e.printStackTrace();
|
327
|
Assert.fail();
|
328
|
}
|
329
|
assertNotNull("Configurator could not be created", importConfigurator);
|
330
|
|
331
|
assertEquals("Number of derived units is incorrect", 1, occurrenceService.count(DerivedUnit.class));
|
332
|
boolean result = defaultImport.invoke(importConfigurator);
|
333
|
assertTrue("Return value for import.invoke should be true", result);
|
334
|
assertEquals("Number of derived units is incorrect", 3, occurrenceService.count(DerivedUnit.class));
|
335
|
List<DerivedUnit> derivedUnits = occurrenceService.list(DerivedUnit.class, null, null, null, null);
|
336
|
assertEquals("Number of derived units is incorrect", 3, derivedUnits.size());
|
337
|
assertEquals("Number of field units is incorrect", 1, occurrenceService.count(FieldUnit.class));
|
338
|
assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
|
339
|
|
340
|
DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(derivedUnit1Uuid);
|
341
|
assertTrue(derivedUnits.contains(derivedUnit));
|
342
|
|
343
|
assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
|
344
|
DnaSample dnaSample = occurrenceService.list(DnaSample.class, null, null, null, null).get(0);
|
345
|
assertEquals("Wrong derivation type!", DerivationEventType.DNA_EXTRACTION(), dnaSample.getDerivedFrom().getType());
|
346
|
|
347
|
assertEquals("Wrong number of originals", 1, dnaSample.getDerivedFrom().getOriginals().size());
|
348
|
|
349
|
}
|
350
|
|
351
|
@Override
|
352
|
public void createTestDataSet() throws FileNotFoundException {
|
353
|
UUID derivedUnit1Uuid = UUID.fromString("eb40cb0f-efb2-4985-819e-a9168f6d61fe");
|
354
|
|
355
|
DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
|
356
|
derivedUnit.setAccessionNumber("B 10 0066577");
|
357
|
derivedUnit.setTitleCache("testUnit1", true);
|
358
|
|
359
|
derivedUnit.setUuid(derivedUnit1Uuid );
|
360
|
|
361
|
occurrenceService.save(derivedUnit);
|
362
|
|
363
|
commitAndStartNewTransaction(null);
|
364
|
|
365
|
setComplete();
|
366
|
endTransaction();
|
367
|
|
368
|
|
369
|
try {
|
370
|
writeDbUnitDataSetFile(new String[] {
|
371
|
"SpecimenOrObservationBase",
|
372
|
}, "testAttachDnaSampleToDerivedUnit");
|
373
|
} catch (FileNotFoundException e) {
|
374
|
e.printStackTrace();
|
375
|
}
|
376
|
}
|
377
|
|
378
|
}
|