ropensci / RNeXML

Implementing semantically rich NeXML I/O in R
https://docs.ropensci.org/RNeXML
Other
13 stars 9 forks source link

get_metadata() throws error for level "char" #134

Closed hlapp closed 8 years ago

hlapp commented 8 years ago

The following call results in an error since #133 has been merged:

> get_metadata(nex, level="char")
Error in slot(node, element) : 
  no slot of name "char" for this object of class "nexml"

Level "otu" appears to work fine:

> get_metadata(nex, level="otu")
Source: local data frame [10 x 6]

      id         rel                                       href     xsi.type         otu
   (lgl)       (chr)                                      (chr)        (chr)       (chr)
1     NA dwc:taxonID http://purl.obolibrary.org/obo/VTO_0036225 ResourceMeta VTO_0036225
2     NA      parent http://purl.obolibrary.org/obo/VTO_0036217 ResourceMeta VTO_0036225
3     NA dwc:taxonID http://purl.obolibrary.org/obo/VTO_0061498 ResourceMeta VTO_0061498
4     NA dwc:taxonID http://purl.obolibrary.org/obo/VTO_0061495 ResourceMeta VTO_0061495
5     NA dwc:taxonID http://purl.obolibrary.org/obo/VTO_0036221 ResourceMeta VTO_0036221
6     NA dwc:taxonID http://purl.obolibrary.org/obo/VTO_0036218 ResourceMeta VTO_0036218
7     NA dwc:taxonID http://purl.obolibrary.org/obo/VTO_0036223 ResourceMeta VTO_0036223
8     NA dwc:taxonID http://purl.obolibrary.org/obo/VTO_0036220 ResourceMeta VTO_0036220
9     NA dwc:taxonID http://purl.obolibrary.org/obo/VTO_0061497 ResourceMeta VTO_0061497
10    NA dwc:taxonID http://purl.obolibrary.org/obo/VTO_0061496 ResourceMeta VTO_0061496
Variables not shown: otus (chr)
cboettig commented 8 years ago

Thanks for testing out, sorry about that. I think you want: get_metadata(nexml, "characters"). The second argument should be the (full) name of a nexml element. To avoid ambiguity, the function actually expects you to give the full path to the element, e.g. get_metadata(nexml, "otus/otu"), but I mapped otu and tree separately for backwards-compatibility. Looks like I forgot to do that for char (if that was previously an option). This new approach should allow you to get metadata for arbitrary elements (including meta elements themselves, if they are nested).

The documentation could stand to be improved on this matter as well.

hlapp commented 8 years ago

We do want annotations for the char elements. If I spell out the path it doesn't work either:

> get_metadata(nex,level="characters/char")
Error in slot(node, element) : 
  no slot of name "char" for this object of class "characters"
> get_metadata(nex,level="characters/format/char")
Error in as.list.default(X) : 
  no method for coercing this S4 class to a vector

The second invocation is actually the correct path in the XML, so that the first doesn't work is I guess expected. But the second one should work.

Here are the annotations as an example for one <char/> element:

<char id="UBERON_2002002" label="anterior distal serration of pectoral fin spine" about="#UBERON_2002002" states="sa75ef9ac-e74e-4015-846d-27d793868951">
     <meta xsi:type="ResourceMeta" rel="obo:IAO_0000219" href="http://purl.obolibrary.org/obo/UBERON_2002002" />
</char>
cboettig commented 8 years ago

oh right, those char elements. That's a bug, I'll take a look. Can you link me to a complete NeXML file that has meta annotations on char elements just for my testing?

hlapp commented 8 years ago

Here's an example file: https://github.com/phenoscape/rphenoscape/blob/char-annots-example/inst/examples/ontotrace-result.xml

cboettig commented 8 years ago

okay, just pushed a fix, try now.