Search in sources :

Example 11 with Sequence

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

the class SequenceServiceImpl method deleteSingleRead.

@Override
@Transactional(readOnly = false)
public DeleteResult deleteSingleRead(UUID singleReadUuid, UUID sequenceUuid) {
    SingleRead singleRead = null;
    Sequence sequence = CdmBase.deproxy(load(sequenceUuid), Sequence.class);
    for (SingleRead sr : sequence.getSingleReads()) {
        if (sr.getUuid().equals(singleReadUuid)) {
            singleRead = sr;
            break;
        }
    }
    return deleteSingleRead(singleRead, sequence);
}
Also used : SingleRead(eu.etaxonomy.cdm.model.molecular.SingleRead) Sequence(eu.etaxonomy.cdm.model.molecular.Sequence) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with Sequence

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

the class DnaSampleDefaultCacheStrategy method doGetTitleCache.

@Override
protected String doGetTitleCache(DnaSample dnaSample) {
    String result = getCollectionAndAccession(dnaSample);
    // sample designation
    if (isBlank(result)) {
        result = dnaSample.getIdentifierString(DefinedTerm.uuidSampleDesignation);
    }
    // any other identifier
    if (isBlank(result)) {
        if (!dnaSample.getIdentifiers().isEmpty()) {
            result = dnaSample.getIdentifiers().get(0).getIdentifier();
        }
    }
    if (isBlank(result)) {
        if (!dnaSample.getDefinition().isEmpty()) {
            Language key = dnaSample.getDefinition().keySet().iterator().next();
            result = truncate(dnaSample.getDefinition().get(key).getText(), 50);
        }
    }
    if (isBlank(result)) {
        if (!dnaSample.getSequences().isEmpty()) {
            Sequence seq = dnaSample.getSequences().iterator().next();
            if (seq != null) {
                result = seq.getSequenceString();
            }
        }
    }
    if (isBlank(result)) {
        if (!dnaSample.getSources().isEmpty()) {
            for (IdentifiableSource source : dnaSample.getSources()) {
                if (isNotBlank(source.getIdInSource())) {
                    result = CdmUtils.concat(":", source.getIdNamespace(), source.getIdInSource());
                }
            }
        }
    }
    return result;
}
Also used : Language(eu.etaxonomy.cdm.model.common.Language) Sequence(eu.etaxonomy.cdm.model.molecular.Sequence) IdentifiableSource(eu.etaxonomy.cdm.model.common.IdentifiableSource)

Example 13 with Sequence

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

the class AbcdGgbnParser method parseAmplificationSequencings.

private void parseAmplificationSequencings(Element sequencings, Amplification amplification, AmplificationResult amplificationResult, DnaSample dnaSample, Abcd206ImportState state) {
    NodeList sequencingList = sequencings.getElementsByTagName(prefix + "sequencing");
    for (int i = 0; i < sequencingList.getLength(); i++) {
        Sequence sequence = Sequence.NewInstance("");
        dnaSample.addSequence(sequence);
        sequence.setDnaMarker(amplification.getDnaMarker());
        if (sequencingList.item(i) instanceof Element) {
            Element sequencing = (Element) sequencingList.item(i);
            // singleSequencings
            NodeList singleSequencingsList = sequencing.getElementsByTagName(prefix + "SingleSequencings");
            parseSingleSequencings(singleSequencingsList, amplification, amplificationResult, sequence);
            // Consensus sequence
            NodeList consensusSequencesList = sequencing.getElementsByTagName(prefix + "consensusSequence");
            sequence.setConsensusSequence(SequenceString.NewInstance(AbcdParseUtility.parseFirstTextContent(consensusSequencesList)));
            // sequence length
            Double consensusSequenceLength = AbcdParseUtility.parseFirstDouble(sequencing.getElementsByTagName(prefix + "consensusSequenceLength"), report);
            if (sequence.getConsensusSequence() != null && consensusSequenceLength != null) {
                // TODO: this can be different from the actual length in ABCD but not in CDM!
                sequence.getConsensusSequence().setLength(consensusSequenceLength.intValue());
            }
            // contig file URL geneticAccessionNumberURI
            NodeList consensusSequenceChromatogramFileURIList = sequencing.getElementsByTagName(prefix + "consensusSequenceChromatogramFileURI");
            // NodeList consensusSequenceChromatogramFileURIList = sequencing.getElementsByTagName(prefix+"geneticAccessionNumberURI");
            URI uri = AbcdParseUtility.parseFirstUri(consensusSequenceChromatogramFileURIList, report);
            if (uri != null && uri.toString().endsWith("fasta")) {
                state.putSequenceDataStableIdentifier(uri);
                sequence.addAnnotation(Annotation.NewInstance(uri.toString(), Language.DEFAULT()));
            } else {
                Media contigFile = Media.NewInstance(uri, null, null, null);
                sequence.setContigFile(contigFile);
            }
            // genetic Accession
            NodeList geneticAccessionList = sequencing.getElementsByTagName(prefix + "geneticAccession");
            parseGeneticAccession(geneticAccessionList, sequence);
            // references
            NodeList referencesList = sequencing.getElementsByTagName(prefix + "References");
            if (referencesList.item(0) != null && referencesList.item(0) instanceof Element) {
                parseSequencingReferences((Element) referencesList.item(0), sequence);
            }
        }
    }
// if(nodeList.item(0)!=null && nodeList.item(0) instanceof Element){
// NodeList plasmidList = amplificationElement.getElementsByTagName(prefix+"plasmid");
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Media(eu.etaxonomy.cdm.model.media.Media) Sequence(eu.etaxonomy.cdm.model.molecular.Sequence) URI(eu.etaxonomy.cdm.common.URI)

Example 14 with Sequence

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

the class OccurrenceServiceImpl method getMediaInHierarchy.

@Override
public Pager<Media> getMediaInHierarchy(SpecimenOrObservationBase<?> rootOccurence, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
    List<Media> media = new ArrayList<>();
    // media specimens
    if (rootOccurence.isInstanceOf(MediaSpecimen.class)) {
        MediaSpecimen mediaSpecimen = HibernateProxyHelper.deproxy(rootOccurence, MediaSpecimen.class);
        media.add(mediaSpecimen.getMediaSpecimen());
    }
    // pherograms & gelPhotos
    if (rootOccurence.isInstanceOf(DnaSample.class)) {
        DnaSample dnaSample = CdmBase.deproxy(rootOccurence, DnaSample.class);
        Set<Sequence> sequences = dnaSample.getSequences();
        // we do show only those gelPhotos which lead to a consensus sequence
        for (Sequence sequence : sequences) {
            Set<Media> dnaRelatedMedia = new HashSet<>();
            for (SingleRead singleRead : sequence.getSingleReads()) {
                AmplificationResult amplification = singleRead.getAmplificationResult();
                dnaRelatedMedia.add(amplification.getGelPhoto());
                dnaRelatedMedia.add(singleRead.getPherogram());
                dnaRelatedMedia.remove(null);
            }
            media.addAll(dnaRelatedMedia);
        }
    }
    if (rootOccurence.isInstanceOf(DerivedUnit.class)) {
        DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(rootOccurence, DerivedUnit.class);
        for (DerivationEvent derivationEvent : derivedUnit.getDerivationEvents()) {
            for (DerivedUnit childDerivative : derivationEvent.getDerivatives()) {
                media.addAll(getMediaInHierarchy(childDerivative, pageSize, pageNumber, propertyPaths).getRecords());
            }
        }
    }
    return new DefaultPagerImpl<>(pageNumber, Long.valueOf(media.size()), pageSize, media);
}
Also used : DefaultPagerImpl(eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl) DerivationEvent(eu.etaxonomy.cdm.model.occurrence.DerivationEvent) Media(eu.etaxonomy.cdm.model.media.Media) ArrayList(java.util.ArrayList) Sequence(eu.etaxonomy.cdm.model.molecular.Sequence) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) DnaSample(eu.etaxonomy.cdm.model.molecular.DnaSample) MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) AmplificationResult(eu.etaxonomy.cdm.model.molecular.AmplificationResult) SingleRead(eu.etaxonomy.cdm.model.molecular.SingleRead) HashSet(java.util.HashSet)

Example 15 with Sequence

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

the class OccurrenceServiceDeepDeleteTest method testDeepDelete_SingleRead.

@Test
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "OccurrenceServiceDeepDeleteTest.testDeepDelete_SingleRead.xml")
public void testDeepDelete_SingleRead() {
    UUID sequenceA1Uuid = UUID.fromString("3db46d26-94ef-4759-aad8-42d0b9aea9b6");
    UUID sequenceA2Uuid = UUID.fromString("afa3771c-2b9d-46d7-82e0-8b9c050706e3");
    UUID sequenceB1Uuid = UUID.fromString("d7199db5-708e-470a-a573-9c760dd07cd1");
    UUID sequenceB2Uuid = UUID.fromString("1cb83575-38ea-4a8c-9418-d87163f425ce");
    UUID singleReadAUuid = UUID.fromString("82f538a1-2274-4d55-b27b-ed2f004ab5cd");
    UUID singleReadBUuid = UUID.fromString("fc74199a-89dc-40a0-9cbd-08cebebff4b5");
    // how the XML was generated
    // Sequence sequenceA1 = Sequence.NewInstance("A");
    // Sequence sequenceA2 = Sequence.NewInstance("T");
    // Sequence sequenceB1 = Sequence.NewInstance("C");
    // Sequence sequenceB2 = Sequence.NewInstance("G");
    // 
    // SingleRead singleReadA = SingleRead.NewInstance();
    // SingleRead singleReadB = SingleRead.NewInstance();
    // 
    // sequenceA1.setUuid(sequenceA1Uuid);
    // sequenceA2.setUuid(sequenceA2Uuid);
    // sequenceB1.setUuid(sequenceB1Uuid);
    // sequenceB1.setUuid(sequenceB2Uuid);
    // singleReadA.setUuid(singleReadAUuid);
    // singleReadB.setUuid(singleReadBUuid);
    // 
    // SingleReadAlignment.NewInstance(sequenceA1, singleReadA);
    // SingleReadAlignment.NewInstance(sequenceA2, singleReadA);
    // SingleReadAlignment.NewInstance(sequenceB1, singleReadB);
    // SingleReadAlignment.NewInstance(sequenceB2, singleReadB);
    // 
    // sequenceService.save(sequenceA1);
    // sequenceService.save(sequenceA2);
    // sequenceService.save(sequenceB1);
    // sequenceService.save(sequenceB2);
    // 
    // commitAndStartNewTransaction(null);
    // 
    // setComplete();
    // endTransaction();
    // 
    // try {
    // writeDbUnitDataSetFile(new String[] {
    // "SpecimenOrObservationBase",
    // "SpecimenOrObservationBase_DerivationEvent",
    // "DerivationEvent",
    // "Sequence",
    // "SingleRead",
    // "SingleReadAlignment",
    // "Amplification",
    // "AmplificationResult",
    // "DescriptionElementBase",
    // "DescriptionBase",
    // "TaxonBase",
    // "TypeDesignationBase",
    // "TaxonName",
    // "TaxonName_TypeDesignationBase",
    // "HomotypicalGroup"
    // }, "testDeepDelete_SingleRead");
    // } catch (FileNotFoundException e) {
    // e.printStackTrace();
    // }
    DeleteResult deleteResult = null;
    SpecimenDeleteConfigurator config = new SpecimenDeleteConfigurator();
    config.setDeleteMolecularData(true);
    config.setDeleteChildren(true);
    Sequence sequenceA1 = sequenceService.load(sequenceA1Uuid);
    Sequence sequenceA2 = sequenceService.load(sequenceA2Uuid);
    Sequence sequenceB1 = sequenceService.load(sequenceB1Uuid);
    Sequence sequenceB2 = sequenceService.load(sequenceB2Uuid);
    SingleRead singleReadA = singleReadDao.load(singleReadAUuid);
    SingleRead singleReadB = singleReadDao.load(singleReadBUuid);
    // check initial state
    assertNotNull(sequenceA1);
    assertNotNull(sequenceA2);
    assertNotNull(sequenceB1);
    assertNotNull(sequenceB2);
    assertNotNull(singleReadA);
    assertNotNull(singleReadB);
    assertEquals("number of sequences incorrect", 4, sequenceService.count(Sequence.class));
    assertEquals("incorrect number of single reads", 2, singleReadDao.count());
    // A: delete singleRead
    // delete singleReadA from sequenceA1 (singleReadA should NOT be deleted)
    deleteResult = sequenceService.deleteSingleRead(singleReadA, sequenceA1);
    assertTrue(deleteResult.toString(), deleteResult.isOk());
    assertEquals("incorrect number of single reads", 2, singleReadDao.count());
    assertEquals(0, sequenceA1.getSingleReadAlignments().size());
    assertNotNull(singleReadDao.load(singleReadAUuid));
    // delete singleReadA from sequenceA2 (singleReadA should be deleted)
    deleteResult = sequenceService.deleteSingleRead(singleReadA, sequenceA2);
    assertTrue(deleteResult.toString(), deleteResult.isOk());
    assertEquals("incorrect number of single reads", 1, singleReadDao.count());
    assertEquals(0, sequenceA2.getSingleReadAlignments().size());
    assertTrue(singleReadDao.load(singleReadAUuid) == null);
    // B: delete sequence
    // delete sequenceB1 (singleReadB should NOT be deleted)
    deleteResult = sequenceService.delete(sequenceB1Uuid);
    assertTrue(deleteResult.toString(), deleteResult.isOk());
    assertEquals("incorrect number of single reads", 1, singleReadDao.count());
    assertNotNull(singleReadDao.load(singleReadBUuid));
    // delete sequenceB1 (singleReadB should be deleted)
    deleteResult = sequenceService.delete(sequenceB2Uuid);
    assertTrue(deleteResult.toString(), deleteResult.isOk());
    assertEquals("incorrect number of single reads", 0, singleReadDao.count());
    assertTrue(singleReadDao.load(singleReadBUuid) == null);
}
Also used : SpecimenDeleteConfigurator(eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator) Sequence(eu.etaxonomy.cdm.model.molecular.Sequence) SingleRead(eu.etaxonomy.cdm.model.molecular.SingleRead) UUID(java.util.UUID) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Aggregations

Sequence (eu.etaxonomy.cdm.model.molecular.Sequence)21 SingleRead (eu.etaxonomy.cdm.model.molecular.SingleRead)11 DnaSample (eu.etaxonomy.cdm.model.molecular.DnaSample)9 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)7 Test (org.junit.Test)7 DerivedUnit (eu.etaxonomy.cdm.model.occurrence.DerivedUnit)6 DataSet (org.unitils.dbunit.annotation.DataSet)6 DefinedTerm (eu.etaxonomy.cdm.model.term.DefinedTerm)5 AmplificationResult (eu.etaxonomy.cdm.model.molecular.AmplificationResult)4 DerivationEvent (eu.etaxonomy.cdm.model.occurrence.DerivationEvent)4 Transactional (org.springframework.transaction.annotation.Transactional)4 SpecimenDeleteConfigurator (eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator)3 URI (eu.etaxonomy.cdm.common.URI)3 Media (eu.etaxonomy.cdm.model.media.Media)3 PhylogeneticTree (eu.etaxonomy.cdm.model.molecular.PhylogeneticTree)3 FieldUnit (eu.etaxonomy.cdm.model.occurrence.FieldUnit)3 SpecimenOrObservationBase (eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase)3 HashSet (java.util.HashSet)3 UUID (java.util.UUID)3 CdmBase (eu.etaxonomy.cdm.model.common.CdmBase)2