use of cbit.vcell.biomodel.meta.VCID in project vcell by virtualcell.
the class MiriamTreeModel method createTree.
private void createTree() {
if (!createTree) {
return;
}
MiriamManager miriamManager = vcMetaData.getMiriamManager();
TreeMap<Identifiable, Map<MiriamRefGroup, MIRIAMQualifier>> miriamDescrHeir = miriamManager.getMiriamTreeMap();
Map<Identifiable, Map<DateQualifier, Set<DublinCoreDate>>> dateMapMap = miriamManager.getDublinCoreDateMap();
Set<Identifiable> identifiables = vcMetaData.getIdentifiableProvider().getAllIdentifiables();
TreeSet<Identifiable> sortedIdentifiables = new TreeSet<Identifiable>(new IdentifiableComparator(vcMetaData.getIdentifiableProvider()));
sortedIdentifiables.addAll(identifiables);
((DefaultMutableTreeNode) getRoot()).removeAllChildren();
for (Identifiable identifiable : sortedIdentifiables) {
Map<MiriamRefGroup, MIRIAMQualifier> refGroupMap = miriamDescrHeir.get(identifiable);
Map<DateQualifier, Set<DublinCoreDate>> dateMap = dateMapMap.get(identifiable);
VCID vcid = vcMetaData.getIdentifiableProvider().getVCID(identifiable);
String modelComponentType = vcid.getClassName();
String modelComponentName = vcid.getLocalName();
IdentifiableNode modelComponentNode = new IdentifiableNode(identifiable, modelComponentType + " : " + modelComponentName);
String freeTextAnnotation = vcMetaData.getFreeTextAnnotation(identifiable);
if (freeTextAnnotation != null) {
modelComponentNode.add(new BioModelNode(new Annotation(freeTextAnnotation), false));
} else {
modelComponentNode.add(new BioModelNode(new Annotation(""), false));
}
if (refGroupMap != null) {
for (MiriamRefGroup refGroup : refGroupMap.keySet()) {
MIRIAMQualifier qualifier = refGroupMap.get(refGroup);
for (MiriamResource miriamResource : refGroup.getMiriamRefs()) {
LinkNode linkNode = new LinkNode(qualifier, miriamResource);
modelComponentNode.add(linkNode);
}
}
}
if (dateMap != null) {
for (DublinCoreQualifier.DateQualifier qualifier : dateMap.keySet()) {
Set<DublinCoreDate> dates = dateMap.get(qualifier);
for (DublinCoreDate date : dates) {
modelComponentNode.add(new DateNode(qualifier, date));
}
}
}
((DefaultMutableTreeNode) getRoot()).add(modelComponentNode);
}
}
use of cbit.vcell.biomodel.meta.VCID in project vcell by virtualcell.
the class MiriamTreeModel method createTree.
public void createTree(Identifiable identifiable) {
if (identifiable == null) {
((DefaultMutableTreeNode) getRoot()).removeAllChildren();
fireTreeStructureChanged(this, getPathToRoot(((DefaultMutableTreeNode) getRoot())), null, null);
return;
}
((DefaultMutableTreeNode) getRoot()).removeAllChildren();
MiriamManager miriamManager = vcMetaData.getMiriamManager();
TreeMap<Identifiable, Map<MiriamRefGroup, MIRIAMQualifier>> miriamDescrHeir = miriamManager.getMiriamTreeMap();
Map<MiriamRefGroup, MIRIAMQualifier> refGroupMap = miriamDescrHeir.get(identifiable);
VCID vcid = vcMetaData.getIdentifiableProvider().getVCID(identifiable);
// Map<Identifiable, Map<DateQualifier, Set<DublinCoreDate>>> dateMapMap = miriamManager.getDublinCoreDateMap();
// Map<DateQualifier, Set<DublinCoreDate>> dateMap = dateMapMap.get(identifiable);
List<LinkNode> nodeList = new ArrayList<>();
if (refGroupMap != null) {
for (MiriamRefGroup refGroup : refGroupMap.keySet()) {
MIRIAMQualifier qualifier = refGroupMap.get(refGroup);
for (MiriamResource miriamResource : refGroup.getMiriamRefs()) {
LinkNode ln = new LinkNode(qualifier, miriamResource);
nodeList.add(ln);
}
}
Collections.sort(nodeList);
for (LinkNode ln : nodeList) {
((DefaultMutableTreeNode) getRoot()).add(ln);
}
}
// if (dateMap!=null){
// for (DublinCoreQualifier.DateQualifier qualifier : dateMap.keySet()){
// Set<DublinCoreDate> dates = dateMap.get(qualifier);
// for (DublinCoreDate date : dates){
// ((DefaultMutableTreeNode)getRoot()).add(new DateNode(qualifier,date));
// }
// }
// }
fireTreeStructureChanged(this, getPathToRoot(((DefaultMutableTreeNode) getRoot())), null, null);
}
use of cbit.vcell.biomodel.meta.VCID in project vcell by virtualcell.
the class BioModel method getVCID.
public VCID getVCID(Identifiable identifiable) {
if (identifiable == null) {
return null;
}
String localName;
String className;
if (identifiable instanceof SpeciesContext) {
localName = ((SpeciesContext) identifiable).getName();
className = VCID.CLASS_SPECIES_CONTEXT;
} else if (identifiable instanceof Species) {
localName = ((Species) identifiable).getCommonName();
className = VCID.CLASS_SPECIES;
} else if (identifiable instanceof Structure) {
localName = ((Structure) identifiable).getName();
className = VCID.CLASS_STRUCTURE;
} else if (identifiable instanceof ReactionStep) {
localName = ((ReactionStep) identifiable).getName();
className = VCID.CLASS_REACTION_STEP;
} else if (identifiable instanceof BioModel) {
localName = ((BioModel) identifiable).getName();
className = VCID.CLASS_BIOMODEL;
} else if (identifiable instanceof BioPaxObject) {
localName = ((BioPaxObject) identifiable).getID();
className = VCID.CLASS_BIOPAX_OBJECT;
} else if (identifiable instanceof MolecularType) {
localName = ((MolecularType) identifiable).getName();
className = VCID.CLASS_MOLECULE;
} else if (identifiable instanceof ReactionRule) {
localName = ((ReactionRule) identifiable).getName();
className = VCID.CLASS_REACTION_RULE;
} else if (identifiable instanceof RbmObservable) {
localName = ((RbmObservable) identifiable).getName();
className = VCID.CLASS_OBSERVABLE;
} else if (identifiable instanceof Model.ModelParameter) {
localName = ((Model.ModelParameter) identifiable).getName();
className = VCID.CLASS_MODEL_PARAMETER;
} else if (identifiable instanceof SimulationContext) {
localName = ((SimulationContext) identifiable).getName();
className = VCID.CLASS_APPLICATION;
} else {
throw new RuntimeException("unsupported Identifiable class");
}
localName = TokenMangler.mangleVCId(localName);
VCID vcid;
try {
vcid = VCID.fromString(className + "(" + localName + ")");
} catch (VCID.InvalidVCIDException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
return vcid;
}
use of cbit.vcell.biomodel.meta.VCID in project vcell by virtualcell.
the class XMLMetaDataReader method readFromElement.
@SuppressWarnings("unchecked")
public static void readFromElement(VCMetaData metaData, IdentifiableProvider identifiableProvider, Element metadataElement) throws XmlParseException {
Element bindingElement = metadataElement.getChild(XMLMetaData.URI_BINDING_LIST_TAG, VCMetaData.nsVCML);
if (bindingElement != null) {
// read binding
List<Element> entryElements = bindingElement.getChildren(XMLMetaData.URI_BINDING_TAG, VCMetaData.nsVCML);
for (Iterator<Element> iterator = entryElements.iterator(); iterator.hasNext(); ) {
Element entryElement = iterator.next();
try {
String uri = entryElement.getAttributeValue(XMLMetaData.URI_ATTR_TAG);
String vcidString = entryElement.getAttributeValue(XMLMetaData.VCID_ATTR_TAG);
// make new entry based on URI
// create VCID
VCID vcid = VCID.fromString(vcidString);
// lookup Identifiable object using VCID ... add to entry.
metaData.getRegistry().newEntry(metaData.getRdfData(), identifiableProvider.getIdentifiableObject(vcid), uri);
} catch (VCID.InvalidVCIDException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
}
Element rdfElement = metadataElement.getChild(XMLRDF.tagRDF, XMLRDF.nsRDF);
if (rdfElement != null) {
// read RDF
try {
metaData.addToModelFromElement(rdfElement);
} catch (RDFParseException e) {
e.printStackTrace();
throw new XmlParseException(e.getMessage());
} catch (RDFHandlerException e) {
e.printStackTrace();
throw new XmlParseException(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
throw new XmlParseException(e.getMessage());
}
}
Element nonRDFAnnotationListElement = metadataElement.getChild(XMLMetaData.NONRDF_ANNOTATION_LIST_TAG, VCMetaData.nsVCML);
if (nonRDFAnnotationListElement != null) {
List<Element> nonRDFAnnotationElements = nonRDFAnnotationListElement.getChildren(XMLMetaData.NONRDF_ANNOTATION_TAG, VCMetaData.nsVCML);
for (Element nonRDFAnnotationElement : nonRDFAnnotationElements) {
String vcidString = nonRDFAnnotationElement.getAttributeValue(XMLMetaData.VCID_ATTR_TAG);
VCID vcid = null;
try {
vcid = VCID.fromString(vcidString);
} catch (InvalidVCIDException e) {
e.printStackTrace();
throw new XmlParseException(e.getMessage());
}
Identifiable identifiable = identifiableProvider.getIdentifiableObject(vcid);
if (identifiable != null) {
// populate the annotation
Element freeTextAnnotationElement = nonRDFAnnotationElement.getChild(XMLMetaData.FREETEXT_TAG, VCMetaData.nsVCML);
if (freeTextAnnotationElement != null) {
String freeText = freeTextAnnotationElement.getText();
metaData.setFreeTextAnnotation(identifiable, freeText);
}
Element xhtmlNotesElement = nonRDFAnnotationElement.getChild(XMLMetaData.NOTES_TAG, VCMetaData.nsVCML);
if (xhtmlNotesElement != null) {
metaData.setXhtmlNotes(identifiable, xhtmlNotesElement);
}
Element annotationListElement = nonRDFAnnotationElement.getChild(XMLMetaData.ANNOTATION_LIST_TAG, VCMetaData.nsVCML);
if (annotationListElement != null) {
List<?> annotationContents = annotationListElement.getContent();
List<Element> annotationElements = new ArrayList<Element>();
for (int i = 0; i < annotationContents.size(); i++) {
if (annotationContents.get(i) instanceof Element) {
annotationElements.add((Element) annotationContents.get(i));
}
}
metaData.setXmlAnnotations(identifiable, annotationElements.toArray(new Element[annotationElements.size()]));
}
} else {
System.err.println("Cannot find identifiable for vcid : " + vcidString);
}
}
}
}
use of cbit.vcell.biomodel.meta.VCID in project vcell by virtualcell.
the class XMLMetaDataWriter method getElement.
public static Element getElement(VCMetaData metaData, IdentifiableProvider identifiableProvider) {
Element element = new Element(XMLMetaData.VCMETADATA_TAG);
Element elementRDF = metaData.createElement();
// add RDF data
if (elementRDF != null) {
element.addContent(elementRDF);
}
Element elementNonRDFList = createNonRDFAnnotationElement(metaData, identifiableProvider);
element.addContent(elementNonRDFList);
// add resource binding table
Element bindingListElement = new Element(XMLMetaData.URI_BINDING_LIST_TAG);
Set<Registry.Entry> resources = metaData.getRegistry().getAllEntries();
for (Iterator<Registry.Entry> i = resources.iterator(); i.hasNext(); ) {
Registry.Entry entry = i.next();
if (entry.getIdentifiable() == null) {
System.err.println("Null identifiable for metadata registry entry");
i.remove();
continue;
}
VCID vcid = identifiableProvider.getVCID(entry.getIdentifiable());
if (vcid == null) {
throw new RuntimeException("Identifiable missing for " + entry.getResource());
}
Identifiable identifiable = identifiableProvider.getIdentifiableObject(vcid);
if (identifiable != null && entry.getResource() != null) {
Element entryElement = new Element(XMLMetaData.URI_BINDING_TAG);
Resource resource = entry.getResource();
if (resource != null) {
entryElement.setAttribute(XMLMetaData.URI_ATTR_TAG, resource.stringValue());
}
entryElement.setAttribute(XMLMetaData.VCID_ATTR_TAG, vcid.toASCIIString());
bindingListElement.addContent(entryElement);
}
}
element.addContent(bindingListElement);
return element;
}
Aggregations