Skip to content

Instantly share code, notes, and snippets.

@carleen
Created May 14, 2024 00:40
Show Gist options
  • Save carleen/3364a42472618f42ae025872b2a869ae to your computer and use it in GitHub Desktop.
Save carleen/3364a42472618f42ae025872b2a869ae to your computer and use it in GitHub Desktop.
import xml.etree.ElementTree as ET
import numpy as np
'''
XML file has tag called "reactivity". Take value from "reactivity"
and put it into a variable (list)
Set NaN values to 0
'''
filename = 'HCV_IRES_IVT_RNA_0mg_DMS1.xml'
tree = ET.parse(filename)
root = tree.getroot()
for reactivity_tag in root.iter('reactivity'):
# Get the text string from the xml file
reactivity_string = reactivity_tag.text
# Separate the string by commas
reactive_list = [i.strip()for i in reactivity_string.split(',')]
# Convert to numpy array
reactive_list = np.array(reactive_list)
reactive_list = reactive_list.astype(float)
reactive_list[np.isnan(reactive_list)] = 0
print(reactive_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment