Showing posts with label Grabbing NeXML data. Show all posts
Showing posts with label Grabbing NeXML data. Show all posts

Monday, June 13, 2011

Grabbing NeXML data: Part II

In this blog I will show how metadata can be extracted from an OTU element.


<otu id="otu9" label="Alligator_mississippiensis">
<meta content="835" datatype="xsd:long" id="meta82796" property="tb:identifier.taxon" xsi:type="nex:LiteralMeta"/>
<meta content="2038" datatype="xsd:long" id="meta82795" property="tb:identifier.taxonVariant" xsi:type="nex:LiteralMeta"/>
<meta content="Alligator mississippiensis" datatype="xsd:string" id="meta82794" property="skos:prefLabel" xsi:type="nex:LiteralMeta"/>
<meta href="http://purl.uniprot.org/taxonomy/8496" id="meta82793" rel="skos:closeMatch" xsi:type="nex:ResourceMeta"/>
<meta content="Alligator mississipiensis" datatype="xsd:string" id="meta82792" property="skos:altLabel" xsi:type="nex:LiteralMeta"/>
<meta href="http://www.ubio.org/authority/metadata.php?lsid=urn:lsid:ubio.org:namebank:2813218" id="meta82791" rel="skos:closeMatch" xsi:type="nex:ResourceMeta"/>
<meta href="http://purl.org/phylo/treebase/phylows/study/TB2:S2108" id="meta82790" rel="rdfs:isDefinedBy" xsi:type="nex:ResourceMeta"/>
</otu>

The above otu is attached to some node.
You can get the OTU attached to a node as

OTU otu= node.getOTU();

Then you can extract the set of annotations as follows.

Set<Annotation> s1= otu.getAnnotations("skos:closeMatch");
Set<Object> s2=otu.getAnnotationValues("tb:identifier.taxon");

The values are easy to extract after this. Since there are no NeXML files with geographic coordinates attached to nodes, and manually making changes in an NeXML files is a cumbersome process I am thinking of creating a utility which takes an NeXML file as input and a csv file which stores the lat/long and other metadata and the program should be able to attach the latitude/longitude metadata to the NeXML file. I still have to consult this with my mentor !!!

Grabbing NeXML data: Part I

NeXML is fundamentally a type of XML only; with some special schema. Viewing it in this light it should not be difficult to extract any information from it. Here is the explanation for code snippet which is used to grab the metadata attached to the nodes.
One short note before that, There are no trees that have geographic coordinates attached to their nodes in TreeBase. However there are trees with metadata but none with geographic coordinates?

Here is what was suggested by Rutger to attach and access DarwinCore predicates for lat/lon coordinates.

<!-- surrounded by rest of tree description --> <node id="uid1" label="Some taxon" about="#uid1"

<meta id="uid2" property="dwc:DecimalLongitude" content="45.65"
xsi:type="nex:LiteralMeta" datatype="xsd:double"/>
<meta id="uid2" property="dwc:DecimalLatitude" content="37.21"
xsi:type="nex:LiteralMeta" datatype="xsd:double"/> </node>
<!-- surrounded by rest of tree description -->



1) To attach a darwin core coordinate to a node, you would do:
          URI nameSpaceURI = URI.create("http://rs.tdwg.org/dwc/dwcore/");
          Annotation longitude = node.addAnnotationValue("dwc:DecimalLongitude", nameSpaceURI, new Double("45.65"));
          Annotation latitude = node.addAnnotationValue("dwc:DecimalLatitude",nameSpaceURI, new Double("37.21"));


2) Conversely, to read one:
  // a Set is returned because multiple annotations with the same predicate can exist, e.g.
  // for multiple authors on the same study Set<Object> longitudes = node.getAnnotationValues("dwc:      DecimalLongitude");
    
    Double longitude = (Double) longitudes.iterator().next(); Set<Object> latitudes = node.getAnnotationValues("dwc:DecimalLatitude");
   
    Double latitude = (Double) latitudes.iterator().next();"


Likewise information can be extracted from an OTU, I will show it in the next blog.