use of net.sourceforge.ondex.core.DataSource in project knetbuilder by Rothamsted.
the class GraphElementManipulation method oneToManyCollapse.
/**
* Creates a one-to-many collapsed concept by creating collapsed concept of
* a source to all targets. Source concept is NOT deleted by this method.
*
* @param graph
* @param source
* @param targets
*/
public static final Set<ONDEXConcept> oneToManyCollapse(ONDEXGraph graph, ONDEXConcept source, Collection<ONDEXConcept> targets) {
boolean createNewTarget = false;
Set<ONDEXConcept> result = new HashSet<ONDEXConcept>();
System.err.println("Targets number:" + targets.size());
for (ONDEXConcept target : targets) {
System.err.println(target.getOfType());
ConceptClass newClass = target.getOfType();
Set<ConceptClass> set = new HashSet<ConceptClass>();
set.add(newClass);
set.add(source.getOfType());
if (set.size() > 1) {
createNewTarget = true;
newClass = getCompoundConceptClass(graph, set);
}
DataSource newDataSource = target.getElementOf();
Set<DataSource> allDataSources = new HashSet<DataSource>();
allDataSources.add(newDataSource);
allDataSources.add(source.getElementOf());
if (allDataSources.size() > 1) {
createNewTarget = true;
newDataSource = getCompoundDataSource(graph, allDataSources);
}
ONDEXConcept realTarget = target;
if (createNewTarget) {
realTarget = copyConcept(graph, target, newClass, newDataSource);
copyRelations(graph, target, realTarget);
graph.deleteConcept(target.getId());
}
copyConceptData(graph, source, realTarget);
copyRelations(graph, source, realTarget);
result.add(realTarget);
}
return result;
}
use of net.sourceforge.ondex.core.DataSource in project knetbuilder by Rothamsted.
the class ONDEXGraphCloner method cloneConcept.
/**
* Clones a concept from the original graph to the new graph
*
* @param conceptToClone
* the concept to clone in the original graph
* @return the new Concept
*/
public ONDEXConcept cloneConcept(ONDEXConcept conceptToClone) {
if (!metaDataHasBeenCloned) {
cloneMetaData();
}
if (old2newConceptIds.containsKey(conceptToClone.getId())) {
// " already cloned returning previously cloned concept");
return newGraph.getConcept(old2newConceptIds.get(conceptToClone.getId()));
}
ONDEXGraphMetaData nomd = newGraph.getMetaData();
String pid = conceptToClone.getPID();
String desc = conceptToClone.getDescription();
String anno = conceptToClone.getAnnotation();
ArrayList<EvidenceType> ets = new ArrayList<EvidenceType>();
for (EvidenceType evidence : conceptToClone.getEvidence()) {
ets.add(nomd.getEvidenceType(evidence.getId()));
}
DataSource dataSource = conceptToClone.getElementOf();
DataSource newDataSource = nomd.getDataSource(dataSource.getId());
ConceptClass cc = conceptToClone.getOfType();
ConceptClass newCC = nomd.getConceptClass(cc.getId());
ONDEXConcept newConcept = newGraph.createConcept(pid, anno, desc, newDataSource, newCC, ets);
// required to prevent StackOverflow when adding itself as tag
old2newConceptIds.put(conceptToClone.getId(), newConcept.getId());
for (ONDEXConcept tag : conceptToClone.getTags()) {
ONDEXConcept newTag;
if (old2newConceptIds.containsKey(tag.getId())) {
// check if
// tag
// concept
// exists
int cid = old2newConceptIds.get(tag.getId());
newTag = newGraph.getConcept(cid);
} else {
// recursive
newTag = cloneConcept(tag);
}
newConcept.addTag(newTag);
}
for (Attribute attribute : conceptToClone.getAttributes()) {
AttributeName att = attribute.getOfType();
AttributeName newAtt = nomd.getAttributeName(att.getId());
newConcept.createAttribute(newAtt, attribute.getValue(), attribute.isDoIndex());
}
for (ConceptName name : conceptToClone.getConceptNames()) {
newConcept.createConceptName(name.getName(), name.isPreferred());
}
for (ConceptAccession acc : conceptToClone.getConceptAccessions()) {
dataSource = acc.getElementOf();
newDataSource = nomd.getDataSource(dataSource.getId());
newConcept.createConceptAccession(acc.getAccession(), newDataSource, acc.isAmbiguous());
}
return newConcept;
}
use of net.sourceforge.ondex.core.DataSource in project knetbuilder by Rothamsted.
the class DefaultAccessionMapper method map.
@Override
public ConceptAccession map(S src, ONDEXConcept concept, ONDEXGraph graph) {
String accession = this.getAccessionValueMapper().map(src, graph);
if (accession == null)
return null;
DataSource dataSrc = Optional.ofNullable(this.getDataSourceMapper()).map(m -> m.map(src, graph)).orElseThrow(() -> new NullPointerException(this.getClass().getName() + " needs a data source mapper"));
boolean isAmbiguous = Optional.ofNullable(this.getAmbiguityMapper()).map(m -> m.map(src, graph)).map(Boolean.TRUE::equals).orElseThrow(() -> new NullPointerException(this.getClass().getName() + " needs an ambiguity mapper"));
return CachedGraphWrapper.getInstance(graph).getAccession(accession, dataSrc, isAmbiguous, concept);
}
use of net.sourceforge.ondex.core.DataSource in project knetbuilder by Rothamsted.
the class AbstractONDEXGraphMetaDataTest method testGetDataSource.
/**
* Test method for
* {@link net.sourceforge.ondex.core.ONDEXGraphMetaData#getDataSource(java.lang.String)}
* .
*/
@Test
public void testGetDataSource() {
testCreateDataSource();
DataSource _dataSource = omd.getDataSource("dataSource");
assertEquals("not matching", _dataSource, dataSource);
assertEquals("wrong id", _dataSource.getId(), dataSource.getId());
assertEquals("wrong fullname", _dataSource.getFullname(), dataSource.getFullname());
assertEquals("wrong description", _dataSource.getDescription(), dataSource.getDescription());
DataSource _dataSource2 = omd.getDataSource("dataSource2");
assertEquals("not matching", _dataSource2, dataSource2);
assertEquals("wrong id", _dataSource2.getId(), dataSource2.getId());
assertEquals("wrong fullname", _dataSource2.getFullname(), dataSource2.getFullname());
assertEquals("wrong description", _dataSource2.getDescription(), dataSource2.getDescription());
DataSource _dataSource3 = omd.getDataSource("dataSource3");
assertEquals("not matching", _dataSource3, dataSource3);
assertEquals("wrong id", _dataSource3.getId(), dataSource3.getId());
assertEquals("wrong fullname", _dataSource3.getFullname(), dataSource3.getFullname());
assertEquals("wrong description", _dataSource3.getDescription(), dataSource3.getDescription());
}
use of net.sourceforge.ondex.core.DataSource in project knetbuilder by Rothamsted.
the class DefaultHandler method addPublicationXref.
/**
* For publications create a separate concept and relationship.
*
* @param c
* ONDEXConcept with publication
* @param pub
* publicationXref used
* @throws Exception
*/
private void addPublicationXref(ONDEXConcept c, publicationXref pub) throws Exception {
// publication gets default data source
DataSource elementOf = graph.getMetaData().getDataSource(Parser.cvToUse);
if (elementOf == null)
throw new DataSourceMissingException(Parser.cvToUse + " is missing.");
// reused for relation
EvidenceType evidence = graph.getMetaData().getEvidenceType(etIMPD);
if (evidence == null)
throw new EvidenceTypeMissingException(etIMPD + " is missing.");
// get corresponding concept
String rdfid = pub.getUri();
if (!rdf2Concept.containsKey(rdfid)) {
// create publication concept
ConceptClass ofType = graph.getMetaData().getConceptClass(ccPublication);
if (ofType == null)
throw new ConceptClassMissingException(ccPublication + " is missing.");
// add concept to global map
ONDEXConcept pubC = graph.getFactory().createConcept(rdfid, elementOf, ofType, evidence);
rdf2Concept.put(rdfid, pubC);
// PubMed id is non-ambiguous for a publication
if (pub.getID() != null)
pubC.createConceptAccession(pub.getID(), elementOf, false);
// add year of publication
if (pub.getYEAR() > 0) {
AttributeName yearAN = graph.getMetaData().getAttributeName(anYEAR);
if (yearAN == null)
throw new AttributeNameMissingException(anYEAR + " is missing.");
pubC.createAttribute(yearAN, pub.getYEAR(), false);
}
// add journal reference
AttributeName journalAN = graph.getMetaData().getAttributeName(anJOURNAL);
if (journalAN == null)
throw new AttributeNameMissingException(anJOURNAL + " is missing.");
StringBuffer source = new StringBuffer();
for (String s : pub.getSOURCE()) {
source.append(s);
source.append("\n");
}
if (source.length() > 0) {
pubC.createAttribute(journalAN, source.toString(), true);
pubC.createConceptName(source.toString(), true);
}
// add title of publication
if (pub.getTITLE() != null) {
AttributeName titleAN = graph.getMetaData().getAttributeName(anTITLE);
if (titleAN == null)
throw new AttributeNameMissingException(anTITLE + " is missing.");
pubC.createAttribute(titleAN, pub.getTITLE(), true);
pubC.createConceptName(pub.getTITLE(), false);
}
// add authors as list
AttributeName authorsAN = graph.getMetaData().getAttributeName(anAUTHORS);
if (authorsAN == null)
throw new AttributeNameMissingException(anAUTHORS + " is missing.");
StringBuffer authors = new StringBuffer();
for (String s : pub.getAUTHORS()) {
authors.append(s);
authors.append("; ");
}
if (authors.length() > 0)
pubC.createAttribute(authorsAN, authors.toString(), true);
// add possible URL of publication, only first one
if (pub.getURL() != null) {
AttributeName urlAN = graph.getMetaData().getAttributeName(anURL);
if (urlAN == null)
throw new AttributeNameMissingException(anURL + " is missing.");
Iterator<String> it = pub.getURL().iterator();
if (it.hasNext())
pubC.createAttribute(urlAN, it.next(), false);
}
}
// create relation between concept and publication
RelationType ofType = graph.getMetaData().getRelationType(rtPublishedIn);
ONDEXConcept pubC = rdf2Concept.get(rdfid);
graph.getFactory().createRelation(c, pubC, ofType, evidence);
}
Aggregations