Last active
August 29, 2015 14:13
-
-
Save dansondergaard/5f17ab7296b8c9fffac2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import xml.etree.ElementTree as et | |
| import base64 | |
| import array | |
| def parse_file(filename_or_obj): | |
| tree = et.parse(filename_or_obj) | |
| for spectrum in tree.findall('.//spectrum'): | |
| mz_elm = spectrum.find('mzArrayBinary').find('data') | |
| intensity_elm = spectrum.find('intenArrayBinary').find('data') | |
| precursor_mz = float(spectrum.find('.//precursorList/precursor/ionSelection/cvParam[@name="selected ion m/z"]').attrib['value']) | |
| precursor_charge = float(spectrum.find('.//precursorList/precursor/ionSelection/cvParam[@name="charge state"]').attrib['value']) | |
| mz = array.array('d', base64.b64decode(mz_elm.text)) | |
| intensity = array.array('d', base64.b64decode(intensity_elm.text)) | |
| yield precursor_mz, precursor_charge, mz, intensity | |
| if __name__ == '__main__': | |
| import sys | |
| for precursor_mass, precursor_charge, mz, intensity in parse_file(sys.argv[1]): | |
| print "BEGIN IONS" | |
| print "PEPMASS={}".format(precursor_mass) | |
| print "CHARGE={}".format(precursor_charge) | |
| for x, y in zip(mz, intensity): | |
| print x, y | |
| print "END IONS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment