Wednesday, 9 April 2014

Data from XML page into arrays...

So I can do it for CD40, which means that I can do it for any accession number really.

Here's what I can do:
I can go to the XML page.
I can find the features.
I can put them into three arrays
I can find the starts
I can put them into an array.
I can find the ends
I can put them into an array.

All good so far.

So what to do next?
Can I use these array to draw in d3 directly?
Do I need to turn these into a JSON array?
I don't think I should have to do that but I haven't worked out another way.

Below is a cut and paste of the code (for back up)
File name (on Dropbox) is CD40featuresinarray20140409.html


CODE:

<!DOCTYPE html>
<html>
<body>
<h1>Getting the CD40 data</h1>


<script>

// this works and makes five arrays.
// it also does output a list of features, a list of starts and a list of ends.
// I can remove some of the output later

xmlhttp=new XMLHttpRequest();

xmlhttp.open("GET","http://www.uniprot.org/uniprot/P25942.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

// This works to get the accession number so I have uploaded the data - great.

x=xmlDoc.getElementsByTagName("accession")[0]
y=x.childNodes[0];
document.write(y.nodeValue);

document.write("<br>");
document.write("<br>");

// getting a list of features

// create variable names for the arrays
var type = []
var desc = []
var stat = []

x=xmlDoc.getElementsByTagName("feature")
for (i=0;i<x.length;i++)
{
document.write(x[i].getAttribute('type'));
type.push(x[i].getAttribute('type'));
document.write(" ");
document.write(x[i].getAttribute('description'));
desc.push(x[i].getAttribute('description'));
document.write(" ");
document.write(x[i].getAttribute('status'));
stat.push(x[i].getAttribute('status'));
document.write(" ");
document.write("<br>");
}
document.write("<br>");
document.write("<br>");

// output begin number

var start = []

x=xmlDoc.getElementsByTagName("begin")
for (i=0;i<x.length;i++)
{
document.write(x[i].getAttribute('position'));
start.push(x[i].getAttribute('position'));
document.write("<br>");
}
document.write("<br>");
document.write("<br>");

// output end number
var end = []
x=xmlDoc.getElementsByTagName("end")
for (i=0;i<x.length;i++)
{
document.write(x[i].getAttribute('position'));
end.push(x[i].getAttribute('position'));
document.write("<br>");
}
document.write("<br>");
document.write("<br>");

// so I have my data in 5 arrays, what next?


document.write("The End");



</script>

</body>
</html>

No comments:

Post a Comment