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);
}
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;
}
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");
}
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);
}
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);
}
Aggregations