R imports XML from Graphpad Prism

I am trying to import raw data from Graphpad Prism.pzfx files, which are basically .xml files. I took out most of the specific items and left only the part that interests me.

<?xml version="1.0" encoding="UTF-8"?>
<GraphPadPrismFile xmlns="http://graphpad.com/prism/Prism.htm" PrismXMLVersion="5.00">
  <TableSequence Selected="1">
    <Ref ID="Table0" Selected="1"/>
  </TableSequence>
  <Table ID="Table0" XFormat="error" YFormat="replicates" Replicates="1" TableType="XY" EVFormat="AsteriskAfterNumber">
    <Title>Data 1</Title>
    <XColumn Width="162" Decimals="0" Subcolumns="1">
      <Title>X</Title>
      <Subcolumn>
        <d>1</d>
        <d>2</d>
        <d>3</d>
        <d>4</d>
        <d>5</d>
      </Subcolumn>
    </XColumn>
    <YColumn Width="81" Decimals="4" Subcolumns="1">
      <Title>ML</Title>
      <Subcolumn>
        <d>120</d>
        <d>100</d>
        <d>5</d>
        <d>0</d>
        <d>1.5</d>
      </Subcolumn>
    </YColumn>
    <YColumn Width="81" Decimals="4" Subcolumns="1">
      <Title>MH</Title>
      <Subcolumn>
        <d>10</d>
        <d>560</d>
        <d>665</d>
        <d>40</d>
        <d>31.5</d>
      </Subcolumn>
    </YColumn>
    <YColumn Width="81" Decimals="6" Subcolumns="1">
      <Title>MH2</Title>
      <Subcolumn>
        <d>1.20</d>
        <d>100</d>
        <d>5</d>
        <d>0</d>
        <d>1.5</d>
      </Subcolumn>
    </YColumn>
    <YColumn Width="81" Decimals="6" Subcolumns="1">
      <Title>MH1</Title>
      <Subcolumn>
        <d>120</d>
        <d>100</d>
        <d>5</d>
        <d>0</d>
        <d>1.5</d>
      </Subcolumn>
    </YColumn>
  </Table>
</GraphPadPrismFile>

      

As I understand it, I have a Node table that again has XColumn, YColumn nodes that have a Title and then have subcolumn nodes. They contain my raw data, which I would like to convert to R-data.frame.

So far I have managed to import one YColumn: (file is the path to the above)

xData <- xmlParse(file)
xData.rt <- xmlRoot(xData)
xmlToDataFrame(xData.rt[["Table"]][["YColumn"]][["Subcolumn"]])

      

This gives me the first YColumn as data.frame:

  text
1  120
2  100
3    5
4    0
5  1.5

      

Is there a way (maybe easier?) To import all X and Y Colums into one data.frame?

+3


source to share


1 answer


Here are some ideas ...

This finds all the nodes XColumn

and YColumn

:

columns = xpathSApply(xData,"//ns:XColumn|//ns:YColumn",
             namespaces=c(ns="http://graphpad.com/prism/Prism.htm"))

      

Then, given one of them, it gets the title and values:

> xpathSApply(columns[[2]],".//ns:Title",
    namespaces=c(ns="http://graphpad.com/prism/Prism.htm"),xmlValue)
[1] "ML"
> xpathSApply(columns[[2]],".//ns:d",
    namespaces=c(ns="http://graphpad.com/prism/Prism.htm"),xmlValue)
[1] "120" "100" "5"   "0"   "1.5"

      



You can find out if there is something XColumn

or YColumn

by checking it xmlName

:

> xmlName(columns[[1]])
[1] "XColumn"
> xmlName(columns[[2]])
[1] "YColumn"

      

This is probably enough building kit pieces. Loop over columns

and sum the values ​​using cbind

probably ...

Obviously character based numbers need conversion with as.numeric

, and I'm not entirely sure how you want to combine the values XColumn

and YColumn

given there a smaller value XColumn

...

0


source







All Articles