finding the byte offset of an element in an XML file (tell() and seek()?)

B

Ben Temperton

Hi there,

I am working with mass spectroscopy data in the mzXML format that looks like this:
<mzXML>
<msRun>
<scan num="1">...</scan>
<scan num="2">...</scan>
<scan num="3">...</scan>
<scan num="4">...</scan>
.....
</msRun>
<index>
<offset id="1">160409990</offset>
<offset id="2">160442725</offset>
<offset id="3">160474927</offset>
<offset id="4">160497386</offset>
....
</index>
</mzXML>

Where the offset element contains the byte offset of the scan element that shares the id. I am trying to write a python script to remove scan elementsand their respective offset, but I can't figure out how I re-calculate thebyte offset for each remaining element once the elements have been removed..

My plan was to write the file out, the read it back in again and search through the file for a particular string (e.g. '<scan num="1">') and then use the tell() method to return the current byte location in the file. However, I'm not sure how I would implement this.

Any ideas?

Many thanks,

Ben
 
E

Emile van Sebille

On 6/14/2012 12:27 PM Ben Temperton said...
Hi there,

I am working with mass spectroscopy data in the mzXML format that looks like this:
<mzXML>
<msRun>
<scan num="1">...</scan>
<scan num="2">...</scan>
<scan num="3">...</scan>
<scan num="4">...</scan>
.....
</msRun>
<index>
<offset id="1">160409990</offset>
<offset id="2">160442725</offset>
<offset id="3">160474927</offset>
<offset id="4">160497386</offset>
....
</index>
</mzXML>

Where the offset element contains the byte offset

byte offset to what in what?
of the scan element that shares the id. I am trying to write a python script to remove scan elements and their respective offset, but I can't figure out how I re-calculate the byte offset for each remaining element once the elements have been removed.

Removing the reference will render the location as inaccessible so you
may not need to recalculate the remaining offsets. I'm assuming these
are offset in some other file and that the lengths of the data contained
at that location is known or knowable. But, if you don't point to that
location you won't try to get the data at the offset.

If you're trying to minimize the size on disk you'll probably want to
write a new file and leave the original alone. Initialize a buffer,
then for each valid offset id add the content and bump the offset by the
content length (or whatever is appropriate)

Emile
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top