Search in sources :

Example 1 with DnaSample

use of eu.etaxonomy.cdm.model.molecular.DnaSample in project cdmlib by cybertaxonomy.

the class Abcd206Import method handleSingleUnit.

@SuppressWarnings("rawtypes")
public void handleSingleUnit(Abcd206ImportState state, Object itemObject, boolean handleAssociatedUnits) {
    Element item = (Element) itemObject;
    Abcd206ImportConfigurator config = state.getConfig();
    if (logger.isDebugEnabled()) {
        logger.info("handleSingleUnit " + state.getRef());
    }
    try {
        ICdmRepository cdmAppController = state.getConfig().getCdmAppController();
        if (cdmAppController == null) {
            cdmAppController = this;
        }
        // check if unit already exists
        DerivedUnitFacade derivedUnitFacade = null;
        if (state.getConfig().isIgnoreImportOfExistingSpecimen() && state.getDataHolder().getUnitID() != null) {
            SpecimenOrObservationBase<?> existingSpecimen = findExistingSpecimen(state.getDataHolder().getUnitID(), state);
            if (existingSpecimen != null && existingSpecimen.isInstanceOf(DerivedUnit.class)) {
                DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(existingSpecimen, DerivedUnit.class);
                state.setDerivedUnitBase(derivedUnit);
                derivedUnitFacade = DerivedUnitFacade.NewInstance(state.getDerivedUnitBase());
                if (handleAssociatedUnits) {
                    importAssociatedUnits(state, item, derivedUnitFacade);
                }
                if (state.getConfig().getDnaSoure() != null) {
                    importAssociatedDna(state, item, derivedUnitFacade);
                }
                state.getReport().addAlreadyExistingSpecimen(SpecimenImportUtility.getUnitID(derivedUnit, config), derivedUnit);
                return;
            }
        } else {
            System.err.println("dataholder does not contain unit id");
        }
        // import DNA unit
        if (state.getDataHolder().getKindOfUnit() != null && state.getDataHolder().getKindOfUnit().equalsIgnoreCase("dna")) {
            AbcdDnaParser dnaParser = new AbcdDnaParser(state.getPrefix(), state.getReport(), state.getCdmRepository());
            DnaSample dnaSample = dnaParser.parse(item, state);
            // dnaSample.addSource(OriginalSourceType.Import, dnaSample.getAccessionNumber(), "", state.getImportReference(state.getActualAccessPoint()), "");
            save(dnaSample, state);
            // set dna as derived unit to avoid creating an extra specimen
            // for this dna sample (instead just the field unit will be
            // created)
            state.setDerivedUnitBase(dnaSample);
            derivedUnitFacade = DerivedUnitFacade.NewInstance(state.getDerivedUnitBase());
        } else {
            // create facade
            derivedUnitFacade = getFacade(state);
            state.setDerivedUnitBase(derivedUnitFacade.innerDerivedUnit());
        }
        /**
         * GATHERING EVENT
         */
        // look for existing fieldUnit
        FieldUnit fieldUnit = null;
        if (StringUtils.isNotBlank(state.getDataHolder().getFieldNumber())) {
            fieldUnit = state.getFieldUnit(state.getDataHolder().getFieldNumber());
            if (fieldUnit != null) {
                state.setLastFieldUnit(fieldUnit);
            }
        } else {
            fieldUnit = state.getLastFieldUnit();
        }
        if (fieldUnit == null) {
            fieldUnit = FieldUnit.NewInstance();
            fieldUnit.setFieldNumber(state.getDataHolder().getFieldNumber());
            state.setLastFieldUnit(fieldUnit);
        }
        // gathering event
        UnitsGatheringEvent unitsGatheringEvent = new UnitsGatheringEvent(cdmAppController.getTermService(), state.getDataHolder().locality, state.getDataHolder().languageIso, state.getDataHolder().longitude, state.getDataHolder().latitude, state.getDataHolder().getGatheringCoordinateErrorMethod(), state.getDataHolder().getGatheringElevationText(), state.getDataHolder().getGatheringElevationMin(), state.getDataHolder().getGatheringElevationMax(), state.getDataHolder().getGatheringElevationUnit(), state.getDataHolder().getGatheringDateText(), state.getDataHolder().getGatheringNotes(), state.getDataHolder().getGatheringMethod(), state.getTransformer().getReferenceSystemByKey(state.getDataHolder().getGatheringSpatialDatum()), state.getConfig());
        unitsGatheringEvent.setGatheringDepth(state.getDataHolder().getGatheringDepthText(), state.getDataHolder().getGatheringDepthMin(), state.getDataHolder().getGatheringDepthMax(), state.getDataHolder().getGatheringDepthUnit());
        // heightUnit);
        if (state.getDataHolder().gatheringAgentsList.isEmpty()) {
            TeamOrPersonBase team = state.getPersonStore().get(state.getDataHolder().gatheringAgentsText);
            if (team == null) {
                team = parseAuthorString(state.getDataHolder().gatheringAgentsText);
                if (team != null) {
                    state.getPersonStore().put(team.getTitleCache(), team);
                }
            }
            if (team != null) {
                unitsGatheringEvent.setCollector(team, config);
            }
        } else {
            TeamOrPersonBase team = state.getPersonStore().get(state.getDataHolder().gatheringAgentsList.toString());
            if (team == null) {
                team = parseAuthorString(state.getDataHolder().gatheringAgentsList.toString());
                if (team != null) {
                    state.getPersonStore().put(team.getTitleCache(), team);
                }
            }
            if (team != null) {
                unitsGatheringEvent.setCollector(team, config);
            }
        }
        // count
        UnitsGatheringArea unitsGatheringArea = new UnitsGatheringArea();
        // unitsGatheringArea.setConfig(state.getConfig(),getOccurrenceService(),
        // getTermService());
        unitsGatheringArea.setParams(state.getDataHolder().isocountry, state.getDataHolder().country, (state.getConfig()), cdmAppController.getTermService(), cdmAppController.getVocabularyService());
        DefinedTermBase<?> areaCountry = unitsGatheringArea.getCountry();
        // other areas
        unitsGatheringArea = new UnitsGatheringArea();
        // unitsGatheringArea.setConfig(state.getConfig(),getOccurrenceService(),getTermService());
        unitsGatheringArea.setAreas(state.getDataHolder().getNamedAreaList(), (state.getConfig()), cdmAppController.getTermService(), cdmAppController.getVocabularyService());
        ArrayList<DefinedTermBase> nas = unitsGatheringArea.getAreas();
        for (DefinedTermBase namedArea : nas) {
            unitsGatheringEvent.addArea(namedArea);
        }
        // copy gathering event to facade
        GatheringEvent gatheringEvent = unitsGatheringEvent.getGatheringEvent();
        if (fieldUnit != null) {
            derivedUnitFacade.setFieldUnit(fieldUnit);
            if (derivedUnitFacade.getGatheringPeriod() == null && gatheringEvent.getTimeperiod() != null) {
                derivedUnitFacade.setGatheringPeriod(gatheringEvent.getTimeperiod());
            }
            if (derivedUnitFacade.getLocality() == null && gatheringEvent.getLocality() != null) {
                derivedUnitFacade.setLocality(gatheringEvent.getLocality());
            }
            if (derivedUnitFacade.getExactLocation() == null && gatheringEvent.getExactLocation() != null) {
                derivedUnitFacade.setExactLocation(gatheringEvent.getExactLocation());
            }
            if (derivedUnitFacade.getCollector() == null && gatheringEvent.getCollector() != null) {
                derivedUnitFacade.setCollector(gatheringEvent.getCollector());
            }
            if (derivedUnitFacade.getCountry() == null && areaCountry != null) {
                derivedUnitFacade.setCountry((NamedArea) areaCountry);
            }
            if (StringUtils.isBlank(derivedUnitFacade.getAbsoluteElevationText()) && StringUtils.isNotBlank(gatheringEvent.getAbsoluteElevationText())) {
                derivedUnitFacade.setAbsoluteElevationText(gatheringEvent.getAbsoluteElevationText());
            }
            if (derivedUnitFacade.getAbsoluteElevation() == null && gatheringEvent.getAbsoluteElevation() != null) {
                derivedUnitFacade.setAbsoluteElevation(gatheringEvent.getAbsoluteElevation());
            }
            if (derivedUnitFacade.getAbsoluteElevationMaximum() == null && gatheringEvent.getAbsoluteElevationMax() != null) {
                derivedUnitFacade.setAbsoluteElevationMax(gatheringEvent.getAbsoluteElevationMax());
            }
            if (StringUtils.isBlank(derivedUnitFacade.getDistanceToGroundText()) && StringUtils.isNotBlank(gatheringEvent.getDistanceToGroundText())) {
                derivedUnitFacade.setDistanceToGroundText(gatheringEvent.getDistanceToGroundText());
            }
            if (derivedUnitFacade.getDistanceToGroundMax() == null && gatheringEvent.getDistanceToGroundMax() != null) {
                derivedUnitFacade.setDistanceToGroundMax(gatheringEvent.getDistanceToGroundMax());
            }
            if (derivedUnitFacade.getDistanceToGround() == null && gatheringEvent.getDistanceToGround() != null) {
                derivedUnitFacade.setDistanceToGround(gatheringEvent.getDistanceToGround());
            }
            if (StringUtils.isBlank(derivedUnitFacade.getDistanceToWaterSurfaceText()) && StringUtils.isNotBlank(gatheringEvent.getDistanceToWaterSurfaceText())) {
                derivedUnitFacade.setDistanceToWaterSurfaceText(gatheringEvent.getDistanceToWaterSurfaceText());
            }
            if (derivedUnitFacade.getDistanceToWaterSurfaceMax() == null && gatheringEvent.getDistanceToWaterSurfaceMax() != null) {
                derivedUnitFacade.setDistanceToWaterSurfaceMax(gatheringEvent.getDistanceToWaterSurfaceMax());
            }
            if (derivedUnitFacade.getDistanceToWaterSurface() == null && gatheringEvent.getDistanceToWaterSurface() != null) {
                derivedUnitFacade.setDistanceToWaterSurface(gatheringEvent.getDistanceToWaterSurface());
            }
            if (derivedUnitFacade.getGatheringPeriod() == null && gatheringEvent.getTimeperiod() != null) {
                derivedUnitFacade.setGatheringPeriod(gatheringEvent.getTimeperiod());
            }
            if (derivedUnitFacade.getCollectingMethod() == null && gatheringEvent.getCollectingMethod() != null) {
                derivedUnitFacade.setCollectingMethod(gatheringEvent.getCollectingMethod());
            }
            for (DefinedTermBase<?> area : unitsGatheringArea.getAreas()) {
                derivedUnitFacade.addCollectingArea((NamedArea) area);
            }
            // add unitNotes
            if (state.getDataHolder().getUnitNotes() != null) {
                derivedUnitFacade.addAnnotation(Annotation.NewDefaultLanguageInstance(NB(state.getDataHolder().getUnitNotes())));
            }
            if (gatheringEvent.getAnnotations() != null) {
                for (Annotation annotation : gatheringEvent.getAnnotations()) {
                    derivedUnitFacade.getGatheringEvent(true).addAnnotation(annotation);
                }
            }
        } else {
        // TODO??
        }
        // derivedUnitFacade.addCollectingAreas(unitsGatheringArea.getAreas());
        // TODO exsiccatum
        // add fieldNumber
        String fieldNumber = null;
        if (derivedUnitFacade.getFieldUnit(false) != null) {
            fieldNumber = derivedUnitFacade.getFieldUnit(false).getFieldNumber();
            if (fieldNumber == null) {
                derivedUnitFacade.setFieldNumber(NB(state.getDataHolder().getFieldNumber()));
            }
        }
        save(unitsGatheringEvent.getLocality(), state);
        // //add Multimedia URLs
        if (state.getDataHolder().getMultimediaObjects().size() != -1) {
            for (String multimediaObject : state.getDataHolder().getMultimediaObjects().keySet()) {
                Media media;
                try {
                    media = extractMedia(state, multimediaObject);
                    if (media == null) {
                        continue;
                    }
                    if (!state.getConfig().isAddMediaAsMediaSpecimen()) {
                        derivedUnitFacade.addDerivedUnitMedia(media);
                    } else {
                        // add media also as specimen scan
                        MediaSpecimen mediaSpecimen = MediaSpecimen.NewInstance(SpecimenOrObservationType.StillImage);
                        mediaSpecimen.setMediaSpecimen(media);
                        // do it only once!!
                        DefinedTermBase specimenScanTerm = getTermService().load(SPECIMEN_SCAN_TERM);
                        if (specimenScanTerm instanceof DefinedTerm) {
                            mediaSpecimen.setKindOfUnit((DefinedTerm) specimenScanTerm);
                        }
                        DerivationEvent derivationEvent = DerivationEvent.NewInstance(DerivationEventType.PREPARATION());
                        derivationEvent.addDerivative(mediaSpecimen);
                        derivedUnitFacade.innerDerivedUnit().addDerivationEvent(derivationEvent);
                    }
                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        // multimedia for fieldUnit
        if (state.getDataHolder().getGatheringMultimediaObjects().size() != -1) {
            for (String multimediaObject : state.getDataHolder().getGatheringMultimediaObjects().keySet()) {
                Media media;
                try {
                    media = extractMedia(state, multimediaObject);
                    if (media == null) {
                        continue;
                    }
                    derivedUnitFacade.addFieldObjectMedia(media);
                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        if (derivedUnitFacade.getFieldUnit(false) != null) {
            state.setFieldUnit(derivedUnitFacade.getFieldUnit(false));
        }
        // handle collection data
        setCollectionData(state, derivedUnitFacade);
        // Reference stuff
        SpecimenUserInteraction sui = config.getSpecimenUserInteraction();
        Map<String, OriginalSourceBase> sourceMap = new HashMap<>();
        state.getDataHolder().setDocSources(new ArrayList<>());
        IdentifiableSource sour = getIdentifiableSource(state.getImportReference(state.getActualAccessPoint()), null);
        String idInSource = derivedUnitFacade.getAccessionNumber() != null ? derivedUnitFacade.getAccessionNumber() : derivedUnitFacade.getCatalogNumber() != null ? derivedUnitFacade.getCatalogNumber() : derivedUnitFacade.getBarcode();
        // sour.getCitation().setUri(state.getActualAccessPoint());
        sour.setIdInSource(idInSource);
        try {
            if (sour.getCitation() != null) {
                if (StringUtils.isNotBlank(sour.getCitationMicroReference())) {
                    state.getDataHolder().getDocSources().add(sour.getCitation().getTitleCache() + "---" + sour.getCitationMicroReference());
                } else {
                    state.getDataHolder().getDocSources().add(sour.getCitation().getTitleCache());
                }
            }
        } catch (Exception e) {
            logger.warn("oups");
        }
        derivedUnitFacade.addSource(sour);
        save(state.getDerivedUnitBase(), state);
        if (logger.isDebugEnabled()) {
            logger.info("saved ABCD specimen ...");
        }
        // handle identifications
        handleIdentifications(state, derivedUnitFacade);
        // associatedUnits
        if (handleAssociatedUnits) {
            importAssociatedUnits(state, item, derivedUnitFacade);
        }
        if (state.getConfig().getDnaSoure() != null) {
            boolean uriCorrect = true;
            try {
                state.getConfig().getDnaSoure().toString();
            } catch (Exception e) {
                uriCorrect = false;
            }
            if (uriCorrect) {
                try {
                    importAssociatedDna(state, item, derivedUnitFacade);
                } catch (Exception e) {
                    String message = "Error when importing Dna! " + itemObject.toString();
                    state.getReport().addException(message, e);
                    state.setUnsuccessfull();
                }
            }
        }
        // siblings/ other children
        if (derivedUnitFacade.getType() != null && (derivedUnitFacade.getType().equals(SpecimenOrObservationType.LivingSpecimen) || derivedUnitFacade.getType().equals(SpecimenOrObservationType.TissueSample) || derivedUnitFacade.getType().equals(SpecimenOrObservationType.OtherSpecimen) || derivedUnitFacade.getType().equals(SpecimenOrObservationType.MaterialSample)) && state.getConfig().isGetSiblings()) {
            getSiblings(state, item, derivedUnitFacade);
        }
    } catch (Exception e) {
        String message = "Error when reading record! " + itemObject.toString();
        state.getReport().addException(message, e);
        state.setUnsuccessfull();
    }
    return;
}
Also used : DerivedUnitFacade(eu.etaxonomy.cdm.api.facade.DerivedUnitFacade) TeamOrPersonBase(eu.etaxonomy.cdm.model.agent.TeamOrPersonBase) MalformedURLException(java.net.MalformedURLException) OriginalSourceBase(eu.etaxonomy.cdm.model.reference.OriginalSourceBase) UnitsGatheringArea(eu.etaxonomy.cdm.io.specimen.UnitsGatheringArea) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) DefinedTermBase(eu.etaxonomy.cdm.model.term.DefinedTermBase) DnaSample(eu.etaxonomy.cdm.model.molecular.DnaSample) IdentifiableSource(eu.etaxonomy.cdm.model.common.IdentifiableSource) GatheringEvent(eu.etaxonomy.cdm.model.occurrence.GatheringEvent) UnitsGatheringEvent(eu.etaxonomy.cdm.io.specimen.UnitsGatheringEvent) FieldUnit(eu.etaxonomy.cdm.model.occurrence.FieldUnit) DerivationEvent(eu.etaxonomy.cdm.model.occurrence.DerivationEvent) Media(eu.etaxonomy.cdm.model.media.Media) ICdmRepository(eu.etaxonomy.cdm.api.application.ICdmRepository) UnitsGatheringEvent(eu.etaxonomy.cdm.io.specimen.UnitsGatheringEvent) SpecimenUserInteraction(eu.etaxonomy.cdm.io.specimen.SpecimenUserInteraction) Annotation(eu.etaxonomy.cdm.model.common.Annotation) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) AbcdDnaParser(eu.etaxonomy.cdm.io.specimen.abcd206.in.molecular.AbcdDnaParser) MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) DefinedTerm(eu.etaxonomy.cdm.model.term.DefinedTerm)

Example 2 with DnaSample

use of eu.etaxonomy.cdm.model.molecular.DnaSample in project cdmlib by cybertaxonomy.

the class AbcdGgbnImportTest method testImportGgbn.

/**
 * Tests import import of DNA unit and all its parameters
 * and sub derivatives (sequence, amplification, etc.)
 * @throws ParseException
 */
@Test
@DataSet(value = "/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy = CleanSweepInsertLoadStrategy.class)
public void testImportGgbn() throws ParseException {
    String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/db6_without_association.xml";
    URL url = this.getClass().getResource(inputFile);
    assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
    Abcd206ImportConfigurator importConfigurator = null;
    try {
        importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null, false);
    } catch (URISyntaxException e) {
        e.printStackTrace();
        Assert.fail();
    }
    assertNotNull("Configurator could not be created", importConfigurator);
    boolean result = defaultImport.invoke(importConfigurator).isSuccess();
    assertTrue("Return value for import.invoke should be true", result);
    assertEquals("Number of derived units is incorrect", 1, occurrenceService.count(DerivedUnit.class));
    assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
    assertEquals("Number of field units is incorrect", 1, occurrenceService.count(FieldUnit.class));
    // dna sample
    FindOccurrencesConfigurator dnaConfig = new FindOccurrencesConfigurator();
    dnaConfig.setSignificantIdentifier("DB 6");
    List<SpecimenOrObservationBase> dnaRecords = occurrenceService.findByTitle(dnaConfig).getRecords();
    assertEquals(1, dnaRecords.size());
    SpecimenOrObservationBase dnaSpecimen = dnaRecords.iterator().next();
    assertEquals(DnaSample.class, dnaSpecimen.getClass());
    DnaSample dnaSample = (DnaSample) dnaSpecimen;
    DerivationEvent derivedFrom = dnaSample.getDerivedFrom();
    assertNotNull(derivedFrom);
    assertEquals("Wrong derivation type!", DerivationEventType.DNA_EXTRACTION(), derivedFrom.getType());
    assertEquals("Wrong number of originals", 1, derivedFrom.getOriginals().size());
    assertTrue(derivedFrom.getOriginals().iterator().next() instanceof FieldUnit);
    assertEquals("DNA Bank", dnaSample.getCollection().getCode());
    assertEquals(SpecimenOrObservationType.DnaSample, dnaSample.getRecordBasis());
    // preservation/preparation
    assertNotNull(derivedFrom.getActor());
    assertEquals("Bansemer, Jana", derivedFrom.getActor().getTitleCache());
    assertNotNull(derivedFrom.getTimeperiod());
    assertEquals((Integer) 2002, derivedFrom.getTimeperiod().getStartYear());
    assertEquals((Integer) 8, derivedFrom.getTimeperiod().getStartMonth());
    assertEquals((Integer) 13, derivedFrom.getTimeperiod().getStartDay());
    assertNotNull(dnaSample.getPreservation());
    assertEquals("DNeasy Plant Mini Spin Kit Qiagen", derivedFrom.getDescription());
    // sample designation
    Set<String> identifiers = dnaSample.getIdentifierStrings((DefinedTerm) termService.find(DefinedTerm.uuidSampleDesignation));
    assertNotNull(identifiers);
    assertEquals(1, identifiers.size());
    assertEquals("CAM010", identifiers.iterator().next());
    // dna quality
    DnaQuality dnaQuality = dnaSample.getDnaQuality();
    assertNotNull("Dna quality is null", dnaQuality != null);
    assertEquals(new Double("0.77"), dnaQuality.getRatioOfAbsorbance260_230());
    assertEquals(new Double("1.38"), dnaQuality.getRatioOfAbsorbance260_280());
    assertEquals(new DateTime(2008, 4, 15, 0, 0), dnaQuality.getQualityCheckDate());
    // assertEquals(MeasurementUnit.NewInstance(, label, labelAbbrev)DateTime(2008, 4, 15, 0, 0),dnaQuality.getQualityCheckDate());
    // amplifications
    Set<AmplificationResult> amplificationResults = dnaSample.getAmplificationResults();
    assertNotNull(amplificationResults);
    assertEquals(1, amplificationResults.size());
    AmplificationResult amplificationResult = amplificationResults.iterator().next();
    Amplification amplification = amplificationResult.getAmplification();
    assertNotNull("Amplification is null", amplification);
    DefinedTerm dnaMarker = amplification.getDnaMarker();
    assertNotNull(dnaMarker);
    assertEquals("ITS (ITS1, 5.8S rRNA, ITS2)", dnaMarker.getLabel());
    // amplification primers
    Primer forwardPrimer = amplification.getForwardPrimer();
    assertNotNull(forwardPrimer);
    assertEquals("PIpetB1411F", forwardPrimer.getLabel());
    assertEquals("5´-GCCGTMTTTATGTTAATGC-3´", forwardPrimer.getSequence().getString());
    assertNotNull(forwardPrimer.getPublishedIn());
    assertEquals("Löhne & Borsch 2005", forwardPrimer.getPublishedIn().getTitle());
    Primer reversePrimer = amplification.getReversePrimer();
    assertNotNull(reversePrimer);
    assertEquals("PIpetD738R", reversePrimer.getLabel());
    assertEquals("5´-AATTTAGCYCTTAATACAGG-3´", reversePrimer.getSequence().getString());
    // sequencing
    Set<Sequence> sequences = dnaSample.getSequences();
    assertNotNull(sequences);
    assertEquals(1, sequences.size());
    Sequence sequence = sequences.iterator().next();
    SequenceString consensusSequence = sequence.getConsensusSequence();
    assertNotNull(consensusSequence);
    assertEquals("TTTCGGGTCC TTTATAGTGA AGATATAGCA TAGATAGTTG TAATCCATTA" + " TGTATCATTG GGGAAGGAAG GAGAATATTT TTTTGATAGA ATACAAGTAT" + " GGATTATTGA AACTAATACG CCATGTATTT GGATATTTCC CTTGAACTGC" + " ATAATATTCT TTATTTTCCA TGAATAGTGT AAGGGAATTT TTCGAAGAGA" + " AAATGGATTA TGGGAGTGTG TGACTTGAGC TATTGATTGG TCTGTGCAGA" + " TACGGGCTTT TATCTATCTG CCACATTGTA ATTCACAAAC CAATGTGTCT" + " TTGTTCCAAC CATCGCGTAA GCCCCATACA GAAGATAGGC TGGTTCGCTT" + " GAAGAGAATC TTTTCTATGA TCAGATCCGA ATTATGTCGT ACATGAGCAG" + " GCTCCGTAAG ATCTAGTTGA CTTAAGTCAA ACTTCAATAG TATAAAAATG" + " CACTCATTTC CTCTGCATTG ACACGAGCTA TGAGACTATC GGAGTGAAAG" + " AAAGGGTCTA AAGAAGAAGA AAGCTTGGGC TAGATTAGTA ACAAGTAAAT" + " CCTTTGTGTG TGTGTTTGTA ATTAGTAAAT GGGCTCTCAA TATTTTGGGG" + " CTAATTACTG ATCCTAAGGT TTGAGACGAC CCAGAAAGCA CTTGATCATA" + " TCACGATTGA CTTTGTAAGC CTACTTGGGT ATTGAGTATT TACTTGTAAG" + " AACCGAATTC TTTGGGGGAT AGTTGCAAAA AGAATCCAGT CAATTGTTCT" + " TACGTAAAAC CATTCATATC TCGTATATGG ATATGTCTAG ATAGGCTATC" + " GATTTTCGAT GGATTCGTTT GGTTCTTTTG ATTATTGCTC GAGCTGGATG" + " ATGAAAAATT ATCATGTCCG GTTCCTTCG", consensusSequence.getString());
    // assertEquals((Integer)912, consensusSequence.getLength());
    assertNotNull(sequence.getContigFile());
    assertEquals(URI.create("http://ww2.biocase.org/websvn/filedetails.php?repname=campanula&path=%2FCAM385_Campa_drabifolia.pde"), MediaUtils.getFirstMediaRepresentationPart(sequence.getContigFile()).getUri());
    assertEquals(1, sequence.getCitations().size());
    Reference reference = sequence.getCitations().iterator().next();
    assertEquals("Gemeinholzer,B., Bachmann,K. (2005): Examining morphological " + "and molecular diagnostic character states in " + "Cichorium intybus L. (Asteraceae) and Cichorium spinosum L." + " Plant Systematics and Evolution 253 (1-3): 105-123.", reference.getTitle());
    // single reads
    Set<SingleRead> singleReads = sequence.getSingleReads();
    assertNotNull(singleReads);
    assertEquals(2, singleReads.size());
    for (SingleRead singleRead : singleReads) {
        if (singleRead.getDirection().equals(SequenceDirection.Forward)) {
            assertNotNull(singleRead.getPherogram());
            assertEquals(URI.create("http://ww2.biocase.org/websvn/filedetails.php?repname=campanula&path=%2FCAM385_GM312-petD_F.ab1"), MediaUtils.getFirstMediaRepresentationPart(singleRead.getPherogram()).getUri());
        } else {
            assertNotNull(singleRead.getPherogram());
            assertEquals(URI.create("http://ww2.biocase.org/websvn/filedetails.php?repname=campanula&path=%2FCAM385_GM312-petD_R.ab1"), MediaUtils.getFirstMediaRepresentationPart(singleRead.getPherogram()).getUri());
        }
    }
    assertNotNull(amplificationResult.getSingleReads());
    assertEquals(amplificationResult.getSingleReads(), singleReads);
}
Also used : Primer(eu.etaxonomy.cdm.model.molecular.Primer) SequenceString(eu.etaxonomy.cdm.model.molecular.SequenceString) URISyntaxException(java.net.URISyntaxException) URI(eu.etaxonomy.cdm.common.URI) DnaQuality(eu.etaxonomy.cdm.model.molecular.DnaQuality) URL(java.net.URL) DateTime(org.joda.time.DateTime) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) DnaSample(eu.etaxonomy.cdm.model.molecular.DnaSample) AmplificationResult(eu.etaxonomy.cdm.model.molecular.AmplificationResult) SingleRead(eu.etaxonomy.cdm.model.molecular.SingleRead) SequenceString(eu.etaxonomy.cdm.model.molecular.SequenceString) FindOccurrencesConfigurator(eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator) FieldUnit(eu.etaxonomy.cdm.model.occurrence.FieldUnit) DerivationEvent(eu.etaxonomy.cdm.model.occurrence.DerivationEvent) Reference(eu.etaxonomy.cdm.model.reference.Reference) Sequence(eu.etaxonomy.cdm.model.molecular.Sequence) Amplification(eu.etaxonomy.cdm.model.molecular.Amplification) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) DefinedTerm(eu.etaxonomy.cdm.model.term.DefinedTerm) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 3 with DnaSample

use of eu.etaxonomy.cdm.model.molecular.DnaSample in project cdmlib by cybertaxonomy.

the class AbcdGgbnImportTest method testAttachDnaSampleToExistingDerivedUnit_sibling.

/**
 * Tests import of DNA unit and attaching it to an existing specimen to which
 * it has a sibling UnitAssociation. The derived unit should not be imported because it already exists in the data base.
 * The DnaSample should be attached to the existing FieldUnit of the DerivedUnit
 */
@Test
@DataSets({ @DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "/eu/etaxonomy/cdm/database/ClearDBDataSet.xml"), @DataSet(value = "AbcdGgbnImportTest.testAttachDnaSampleToDerivedUnit.xml", loadStrategy = CleanSweepInsertLoadStrategy.class) })
public void testAttachDnaSampleToExistingDerivedUnit_sibling() {
    UUID fieldUnit1Uuid = UUID.fromString("0f896630-48d6-4352-9c91-278be28ce19c");
    UUID derivedUnit1Uuid = UUID.fromString("eb40cb0f-efb2-4985-819e-a9168f6d61fe");
    String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/db6_parent_child_association.xml";
    URL url = this.getClass().getResource(inputFile);
    assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
    Abcd206ImportConfigurator importConfigurator = null;
    try {
        importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null, false);
    } catch (URISyntaxException e) {
        e.printStackTrace();
        Assert.fail();
    }
    assertNotNull("Configurator could not be created", importConfigurator);
    boolean result = defaultImport.invoke(importConfigurator).isSuccess();
    assertTrue("Return value for import.invoke should be true", result);
    List<DerivedUnit> derivedUnits = occurrenceService.list(DerivedUnit.class, null, null, null, null);
    for (DerivedUnit derivedUnit : derivedUnits) {
        System.out.println(derivedUnit.getTitleCache());
    }
    assertEquals("Number of derived units is incorrect", 2, occurrenceService.count(DerivedUnit.class));
    // List<DerivedUnit> derivedUnits = occurrenceService.list(DerivedUnit.class, null, null, null, null);
    List<FieldUnit> fieldUnitsTemp = occurrenceService.list(FieldUnit.class, null, null, null, null);
    assertEquals("Number of derived units is incorrect", 2, derivedUnits.size());
    assertEquals("Number of field units is incorrect", 1, occurrenceService.count(FieldUnit.class));
    assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
    DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(derivedUnit1Uuid);
    assertTrue(derivedUnits.contains(derivedUnit));
    assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
    DnaSample dnaSample = occurrenceService.list(DnaSample.class, null, null, null, null).get(0);
    assertEquals("Wrong derivation type!", DerivationEventType.DNA_EXTRACTION(), dnaSample.getDerivedFrom().getType());
    assertEquals("Wrong number of originals", 1, dnaSample.getDerivedFrom().getOriginals().size());
    FieldUnit specimenFieldUnit = (FieldUnit) occurrenceService.load(fieldUnit1Uuid);
    Collection<FieldUnit> fieldUnits = occurrenceService.findFieldUnits(dnaSample.getUuid(), null);
    assertEquals(1, fieldUnits.size());
    FieldUnit dnaSampleFieldUnit = fieldUnits.iterator().next();
    assertEquals(specimenFieldUnit, dnaSampleFieldUnit);
    assertEquals("fieldUnit1", dnaSampleFieldUnit.getTitleCache());
}
Also used : FieldUnit(eu.etaxonomy.cdm.model.occurrence.FieldUnit) SequenceString(eu.etaxonomy.cdm.model.molecular.SequenceString) URISyntaxException(java.net.URISyntaxException) URI(eu.etaxonomy.cdm.common.URI) URL(java.net.URL) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) DnaSample(eu.etaxonomy.cdm.model.molecular.DnaSample) UUID(java.util.UUID) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSets(org.unitils.dbunit.annotation.DataSets)

Example 4 with DnaSample

use of eu.etaxonomy.cdm.model.molecular.DnaSample in project cdmlib by cybertaxonomy.

the class AbcdGgbnImportTest method testNoAttachDnaSampleToDerivedUnit.

/**
 * Tests importing of DNA unit without attaching it to an existing specimen.
 * Creates a FieldUnit with an attached DnaSample.
 */
@Test
@DataSets({ @DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "/eu/etaxonomy/cdm/database/ClearDBDataSet.xml"), @DataSet(value = "AbcdGgbnImportTest.testNoAttachDnaSampleToDerivedUnit.xml", loadStrategy = CleanSweepInsertLoadStrategy.class) })
public void testNoAttachDnaSampleToDerivedUnit() {
    UUID derivedUnit1Uuid = UUID.fromString("eb40cb0f-efb2-4985-819e-a9168f6d61fe");
    UUID fieldUnit1Uuid = UUID.fromString("b5f58da5-4442-4001-9d13-33f41518b72a");
    // DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
    // derivedUnit.setAccessionNumber("B 10 0066577");
    // derivedUnit.setTitleCache("testUnit1", true);
    // 
    // derivedUnit.setUuid(derivedUnit1Uuid );
    // 
    // occurrenceService.save(derivedUnit);
    // 
    // commitAndStartNewTransaction(null);
    // 
    // setComplete();
    // endTransaction();
    // 
    // 
    // try {
    // writeDbUnitDataSetFile(new String[] {
    // "SpecimenOrObservationBase",
    // }, "testAttachDnaSampleToDerivedUnit");
    // } catch (FileNotFoundException e) {
    // e.printStackTrace();
    // }
    String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/db6_without_association.xml";
    URL url = this.getClass().getResource(inputFile);
    assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
    Abcd206ImportConfigurator importConfigurator = null;
    try {
        importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null, false);
    } catch (URISyntaxException e) {
        e.printStackTrace();
        Assert.fail();
    }
    assertNotNull("Configurator could not be created", importConfigurator);
    assertEquals("Number of derived units is incorrect", 1, occurrenceService.count(DerivedUnit.class));
    boolean result = defaultImport.invoke(importConfigurator).isSuccess();
    assertTrue("Return value for import.invoke should be true", result);
    assertEquals("Number of derived units is incorrect", 2, occurrenceService.count(DerivedUnit.class));
    List<DerivedUnit> derivedUnits = occurrenceService.list(DerivedUnit.class, null, null, null, null);
    assertEquals("Number of derived units is incorrect", 2, derivedUnits.size());
    assertEquals("Number of field units is incorrect", 2, occurrenceService.count(FieldUnit.class));
    assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
    DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(derivedUnit1Uuid);
    assertTrue(derivedUnits.contains(derivedUnit));
    DnaSample dnaSample = occurrenceService.list(DnaSample.class, null, null, null, null).get(0);
    assertEquals("Wrong derivation type!", DerivationEventType.DNA_EXTRACTION(), dnaSample.getDerivedFrom().getType());
    assertEquals("Wrong number of originals", 1, dnaSample.getDerivedFrom().getOriginals().size());
    FieldUnit specimenFieldUnit = (FieldUnit) occurrenceService.load(fieldUnit1Uuid);
    SpecimenOrObservationBase<?> dnaSampleFieldUnit = dnaSample.getDerivedFrom().getOriginals().iterator().next();
    assertTrue(!specimenFieldUnit.equals(dnaSampleFieldUnit));
}
Also used : DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) FieldUnit(eu.etaxonomy.cdm.model.occurrence.FieldUnit) DnaSample(eu.etaxonomy.cdm.model.molecular.DnaSample) SequenceString(eu.etaxonomy.cdm.model.molecular.SequenceString) URISyntaxException(java.net.URISyntaxException) UUID(java.util.UUID) URI(eu.etaxonomy.cdm.common.URI) URL(java.net.URL) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSets(org.unitils.dbunit.annotation.DataSets)

Example 5 with DnaSample

use of eu.etaxonomy.cdm.model.molecular.DnaSample in project cdmlib by cybertaxonomy.

the class AbcdGgbnImportTest method testImportAssociatedSpecimenSamePopulation.

/**
 * Tests import of DNA unit which is associated to a specimen being its sibling
 * by having the same field unit
 */
@Test
@DataSet(value = "/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy = CleanSweepInsertLoadStrategy.class)
public // @Ignore
void testImportAssociatedSpecimenSamePopulation() {
    String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/db6_sibling_association.xml";
    URL url = this.getClass().getResource(inputFile);
    assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
    Abcd206ImportConfigurator importConfigurator = null;
    try {
        importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null, false);
    } catch (URISyntaxException e) {
        e.printStackTrace();
        Assert.fail();
    }
    assertNotNull("Configurator could not be created", importConfigurator);
    boolean result = defaultImport.invoke(importConfigurator).isSuccess();
    assertTrue("Return value for import.invoke should be true", result);
    assertEquals("Number of derived units is incorrect", 2, occurrenceService.count(DerivedUnit.class));
    assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
    assertEquals("Number of field units is incorrect", 1, occurrenceService.count(FieldUnit.class));
    // associated specimen
    FindOccurrencesConfigurator config = new FindOccurrencesConfigurator();
    config.setSignificantIdentifier("B 10 0066577");
    List<SpecimenOrObservationBase> records = occurrenceService.findByTitle(config).getRecords();
    assertEquals(1, records.size());
    SpecimenOrObservationBase<?> derivedUnitSpecimen = records.iterator().next();
    assertEquals(DerivedUnit.class, derivedUnitSpecimen.getClass());
    DerivedUnit specimen = (DerivedUnit) derivedUnitSpecimen;
    assertEquals("Herbarium Berolinense", specimen.getCollection().getCode());
    assertTrue(SpecimenOrObservationType.DnaSample != specimen.getRecordBasis());
    // dna sample
    FindOccurrencesConfigurator dnaConfig = new FindOccurrencesConfigurator();
    dnaConfig.setSignificantIdentifier("DB 6");
    List<SpecimenOrObservationBase> dnaRecords = occurrenceService.findByTitle(dnaConfig).getRecords();
    assertEquals(1, dnaRecords.size());
    SpecimenOrObservationBase<?> dnaSpecimen = dnaRecords.iterator().next();
    assertEquals(DnaSample.class, dnaSpecimen.getClass());
    DnaSample dnaSample = (DnaSample) dnaSpecimen;
    DerivationEvent derivedFrom = dnaSample.getDerivedFrom();
    assertNotNull(derivedFrom);
    assertEquals("Wrong derivation type!", DerivationEventType.DNA_EXTRACTION(), derivedFrom.getType());
    assertEquals("Wrong number of originals", 1, derivedFrom.getOriginals().size());
    // TODO
    // assertTrue(derivedFrom.getOriginals().iterator().next() instanceof FieldUnit);
    assertEquals("DNA Bank", dnaSample.getCollection().getCode());
    assertEquals(SpecimenOrObservationType.DnaSample, dnaSample.getRecordBasis());
// TODO field unit
}
Also used : FindOccurrencesConfigurator(eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator) FieldUnit(eu.etaxonomy.cdm.model.occurrence.FieldUnit) DerivationEvent(eu.etaxonomy.cdm.model.occurrence.DerivationEvent) SequenceString(eu.etaxonomy.cdm.model.molecular.SequenceString) URISyntaxException(java.net.URISyntaxException) URI(eu.etaxonomy.cdm.common.URI) URL(java.net.URL) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) DnaSample(eu.etaxonomy.cdm.model.molecular.DnaSample) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Aggregations

DnaSample (eu.etaxonomy.cdm.model.molecular.DnaSample)31 DerivedUnit (eu.etaxonomy.cdm.model.occurrence.DerivedUnit)20 Test (org.junit.Test)20 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)19 FieldUnit (eu.etaxonomy.cdm.model.occurrence.FieldUnit)17 DataSet (org.unitils.dbunit.annotation.DataSet)16 Sequence (eu.etaxonomy.cdm.model.molecular.Sequence)12 DerivationEvent (eu.etaxonomy.cdm.model.occurrence.DerivationEvent)12 SpecimenOrObservationBase (eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase)12 UUID (java.util.UUID)10 SpecimenDeleteConfigurator (eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator)9 DefinedTerm (eu.etaxonomy.cdm.model.term.DefinedTerm)9 FindOccurrencesConfigurator (eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator)7 URI (eu.etaxonomy.cdm.common.URI)7 URISyntaxException (java.net.URISyntaxException)7 SequenceString (eu.etaxonomy.cdm.model.molecular.SequenceString)6 SingleRead (eu.etaxonomy.cdm.model.molecular.SingleRead)6 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)5 Institution (eu.etaxonomy.cdm.model.agent.Institution)4 SpecimenTypeDesignation (eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation)4