Skip to content

Instantly share code, notes, and snippets.

@mwalzer
Last active April 19, 2024 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwalzer/270a44d7ed0437130ab9ba31e16be403 to your computer and use it in GitHub Desktop.
Save mwalzer/270a44d7ed0437130ab9ba31e16be403 to your computer and use it in GitHub Desktop.
lxml xpath for mzquantml
from lxml import etree
mzq = "file:///path/vis_fix.mzq"
doc = etree.parse(mzq)
header = doc.xpath('/x:MzQuantML/x:PeptideConsensusList/x:AssayQuantLayer/x:ColumnIndex',
namespaces={'x': "http://psidev.info/psi/pi/mzQuantML/1.0.0"})
col_names = ['object_ref'] + header[0].text.split(' ')
dm = doc.xpath('/x:MzQuantML/x:PeptideConsensusList/x:AssayQuantLayer/x:DataMatrix',
namespaces={'x': "http://psidev.info/psi/pi/mzQuantML/1.0.0"})
rows = [[row.get('object_ref')]+row.text.split(' ') for row in dm[0].getchildren()]
import pandas as pd
df = pd.DataFrame(rows,columns=col_names).astype({ct: 'float' for ct in col_names[1:]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment