From 4b501b7efafd10997692ebe9ac25fbef142568bd Mon Sep 17 00:00:00 2001 From: sonyahanson Date: Tue, 3 Feb 2015 13:51:34 -0500 Subject: [PATCH] Added example of 5 singlet data collection for xml2png.py --- ...SMH_SrcBos_Extend_013015_mdfx_20150130.xml | 1655 +++++++++++++++++ examples/xml2png_5/xml2png_5.py | 143 ++ 2 files changed, 1798 insertions(+) create mode 100644 examples/xml2png_5/Extend_WIP_SMH_SrcBos_Extend_013015_mdfx_20150130.xml create mode 100644 examples/xml2png_5/xml2png_5.py diff --git a/examples/xml2png_5/Extend_WIP_SMH_SrcBos_Extend_013015_mdfx_20150130.xml b/examples/xml2png_5/Extend_WIP_SMH_SrcBos_Extend_013015_mdfx_20150130.xml new file mode 100644 index 0000000..22e5acf --- /dev/null +++ b/examples/xml2png_5/Extend_WIP_SMH_SrcBos_Extend_013015_mdfx_20150130.xml @@ -0,0 +1,1655 @@ + + + + + + + SrcBos + + +
+ + + + + + infinite M1000 PRO + 1311007572 + + + MEX, V 1.20 Safire2 MCR (V 1.20 Safire2 MCR ) + MEM, V 1.20 Safire2 MCR (V 1.20 Safire2 MCR ) + FPO, V_1.03_Safire2 FP (V_1.03_Safire2 FP ) + ABS, V 1.00 MCR Abs 4 Channel (V 1.00 MCR Abs 4 Channel) + LUM, V_1.04_11/2011_LUMINESCENCE (Nov 02 2011/17.53.34) + BCR, V_1.00_02/2008_S3FTCAN + INA, V_1.05_11/2011_S3LCE_ALPHA (Nov 3 2011/09.27.24) + INB, V_1.05_11/2011_S3LCE_ALPHA (Nov 3 2011/09.27.24) + TCAN, V_1.00_02/2008_S3FTCAN (Feb 21 2008/17.19.16) + + + + + + +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + 466 + + + 450 + + + 441 + + + 436 + + + 432 + + + 277 + + + 147 + + + 78 + + + 48 + + + 31 + + + 23 + + + 15 + + + 15 + + + 16 + + + 15 + + + 15 + + + 17 + + + 19 + + + 19 + + + 25 + + + 39 + + + 59 + + + 83 + + + 129 + + + 489 + + + 466 + + + 450 + + + 446 + + + 440 + + + 288 + + + 149 + + + 74 + + + 44 + + + 31 + + + 23 + + + 18 + + + 16 + + + 15 + + + 17 + + + 16 + + + 19 + + + 18 + + + 20 + + + 24 + + + 34 + + + 53 + + + 78 + + + 137 + + + 544 + + + 458 + + + 448 + + + 451 + + + 438 + + + 279 + + + 144 + + + 73 + + + 44 + + + 30 + + + 22 + + + 18 + + + 16 + + + 21 + + + 17 + + + 17 + + + 20 + + + 20 + + + 18 + + + 22 + + + 33 + + + 52 + + + 89 + + + 122 + + + 461 + + + 453 + + + 448 + + + 439 + + + 443 + + + 282 + + + 139 + + + 73 + + + 44 + + + 31 + + + 23 + + + 28 + + + 14 + + + 16 + + + 16 + + + 15 + + + 16 + + + 18 + + + 18 + + + 24 + + + 28 + + + 51 + + + 83 + + + 126 + + +
+ +
+ + + + + + + + + + + + + + + + + + 75 + + + 69 + + + 60 + + + 73 + + + 62 + + + 43 + + + 28 + + + 18 + + + 16 + + + 14 + + + 13 + + + 11 + + + 11 + + + 12 + + + 11 + + + 12 + + + 10 + + + 11 + + + 13 + + + 13 + + + 16 + + + 20 + + + 24 + + + 33 + + + 71 + + + 88 + + + 67 + + + 64 + + + 64 + + + 44 + + + 27 + + + 19 + + + 14 + + + 18 + + + 11 + + + 13 + + + 12 + + + 11 + + + 11 + + + 12 + + + 31 + + + 12 + + + 13 + + + 13 + + + 16 + + + 17 + + + 24 + + + 37 + + + 80 + + + 65 + + + 66 + + + 63 + + + 62 + + + 43 + + + 28 + + + 26 + + + 18 + + + 16 + + + 12 + + + 11 + + + 11 + + + 11 + + + 11 + + + 12 + + + 16 + + + 11 + + + 11 + + + 13 + + + 13 + + + 17 + + + 23 + + + 31 + + + 64 + + + 65 + + + 67 + + + 60 + + + 61 + + + 44 + + + 29 + + + 21 + + + 15 + + + 12 + + + 11 + + + 13 + + + 11 + + + 10 + + + 10 + + + 12 + + + 13 + + + 20 + + + 15 + + + 14 + + + 15 + + + 17 + + + 28 + + + 29 + + +
+ +
+ + + + + + + + + + 1.0359 + + + 1.0221 + + + 1.0336 + + + 1.0236 + + + 0.9906 + + + 0.9723 + + + 0.9845 + + + 0.9728 + + + 0.9625 + + + 0.9509 + + + 0.959 + + + 0.9512 + + + 0.9544 + + + 0.9425 + + + 0.9496 + + + 0.9429 + + + 0.9511 + + + 0.9369 + + + 0.9457 + + + 0.937 + + + 0.9492 + + + 0.9351 + + + 0.9427 + + + 0.9354 + + + 0.9489 + + + 0.9351 + + + 0.941 + + + 0.9382 + + + 0.9474 + + + 0.9357 + + + 0.94 + + + 0.9445 + + + 0.9473 + + + 0.936 + + + 0.9399 + + + 0.9346 + + + 0.9458 + + + 0.9358 + + + 0.9398 + + + 0.937 + + + 0.9464 + + + 0.9367 + + + 0.9413 + + + 0.9374 + + + 0.9451 + + + 0.9367 + + + 0.942 + + + 0.9372 + + + 0.9454 + + + 0.9366 + + + 0.9445 + + + 0.937 + + + 0.9457 + + + 0.9374 + + + 0.9436 + + + 0.9404 + + + 0.9439 + + + 0.9368 + + + 0.9436 + + + 0.9409 + + + 0.9475 + + + 0.9357 + + + 0.9447 + + + 0.9415 + + + 0.9455 + + + 0.9443 + + + 0.9449 + + + 0.9423 + + + 0.9472 + + + 0.9361 + + + 0.9441 + + + 0.944 + + + 0.9474 + + + 0.9363 + + + 0.9458 + + + 0.9431 + + + 0.9509 + + + 0.9381 + + + 0.9478 + + + 0.9441 + + + 0.9534 + + + 0.9422 + + + 0.9537 + + + 0.9469 + + + 0.9703 + + + 0.9525 + + + 0.9636 + + + 0.959 + + + 0.9861 + + + 0.9779 + + + 0.9843 + + + 0.9869 + + + 1.0412 + + + 1.0246 + + + 1.0382 + + + 1.03 + + +
+ +
+ + + + + + + + + + + + + + + + + + 136 + + + 128 + + + 107 + + + 128 + + + 106 + + + 79 + + + 59 + + + 45 + + + 39 + + + 37 + + + 36 + + + 32 + + + 37 + + + 34 + + + 38 + + + 37 + + + 37 + + + 66 + + + 39 + + + 41 + + + 46 + + + 50 + + + 62 + + + 75 + + + 139 + + + 143 + + + 114 + + + 111 + + + 108 + + + 85 + + + 59 + + + 47 + + + 40 + + + 41 + + + 37 + + + 42 + + + 42 + + + 36 + + + 39 + + + 38 + + + 123 + + + 39 + + + 41 + + + 41 + + + 44 + + + 50 + + + 58 + + + 81 + + + 158 + + + 117 + + + 118 + + + 112 + + + 107 + + + 85 + + + 57 + + + 53 + + + 44 + + + 45 + + + 36 + + + 37 + + + 36 + + + 43 + + + 38 + + + 37 + + + 48 + + + 43 + + + 38 + + + 40 + + + 43 + + + 51 + + + 62 + + + 71 + + + 125 + + + 120 + + + 117 + + + 111 + + + 107 + + + 94 + + + 59 + + + 51 + + + 44 + + + 36 + + + 35 + + + 52 + + + 35 + + + 36 + + + 33 + + + 36 + + + 39 + + + 46 + + + 43 + + + 43 + + + 44 + + + 55 + + + 79 + + + 69 + + +
+ +
+ + + + + + + + + + + + + + + + + + 86 + + + 75 + + + 63 + + + 80 + + + 57 + + + 44 + + + 32 + + + 23 + + + 20 + + + 18 + + + 18 + + + 17 + + + 17 + + + 18 + + + 21 + + + 19 + + + 18 + + + 39 + + + 19 + + + 22 + + + 27 + + + 35 + + + 40 + + + 54 + + + 91 + + + 89 + + + 64 + + + 62 + + + 63 + + + 47 + + + 33 + + + 25 + + + 22 + + + 23 + + + 17 + + + 23 + + + 29 + + + 17 + + + 18 + + + 18 + + + 75 + + + 20 + + + 20 + + + 21 + + + 26 + + + 31 + + + 41 + + + 56 + + + 101 + + + 69 + + + 68 + + + 63 + + + 61 + + + 46 + + + 32 + + + 29 + + + 24 + + + 26 + + + 19 + + + 16 + + + 16 + + + 32 + + + 21 + + + 18 + + + 25 + + + 23 + + + 20 + + + 21 + + + 24 + + + 33 + + + 49 + + + 53 + + + 79 + + + 69 + + + 74 + + + 63 + + + 59 + + + 50 + + + 34 + + + 27 + + + 22 + + + 18 + + + 17 + + + 21 + + + 18 + + + 16 + + + 16 + + + 17 + + + 24 + + + 27 + + + 21 + + + 20 + + + 21 + + + 34 + + + 51 + + + 50 + + +
+
\ No newline at end of file diff --git a/examples/xml2png_5/xml2png_5.py b/examples/xml2png_5/xml2png_5.py new file mode 100644 index 0000000..29f1ed3 --- /dev/null +++ b/examples/xml2png_5/xml2png_5.py @@ -0,0 +1,143 @@ +# This script takes xml data file output from the Tecan Infinite m1000 Pro plate reader +# and makes quick and dirty images of the raw data. + +# The same procedure can be used to make matrices suitable for analysis using +# matrix = dataframe.values + +# Made by Sonya Hanson with significant help from JH Prinz. +# Wednesday, May 7, 2014 + +# Usage: python xml2png.py *.xml + +################### +# To Do +# +# Set fixed Y axis. +# Define Wells for Legend. +# Define x and y axes. +# Figure out @Name='Mode' thing. +# +################### + +import numpy as np +import matplotlib.pyplot as plt +from lxml import etree +import pandas as pd +import sys +import os + +# Define xml files. + +xml_files = sys.argv[1:] + +so_many = len(xml_files) +print "****This script is about to make png files for %s xml files. ****" % so_many + +# Define extract function that extracts parameters + +def extract(taglist): + result = [] + for p in taglist: + print "Attempting to extract tag '%s'..." % p + try: + param = parameters.xpath("*[@Name='" + p + "']")[0] + result.append( p + '=' + param.attrib['Value']) + except: + # tag not found + result.append(None) + + return result + +# Define get_wells_from_section function that extracts the data from each Section. +# It is written sort of strangely to ensure data is connected to the correct well. + +def get_wells_from_section(path): + reads = path.xpath("*/Well") + wellIDs = [read.attrib['Pos'] for read in reads] + + data = [(float(s.text), r.attrib['Pos']) + for r in reads + for s in r] + + datalist = { + well : value + for (value, well) in data + } + + welllist = [ + [ + datalist[chr(64 + row) + str(col)] + if chr(64 + row) + str(col) in datalist else None + for row in range(1,17) + ] + for col in range(1,24) + ] + + return welllist + +for file in xml_files: + + # Parse XML file. + + root = etree.parse(file) + + # Remove extension from xml filename. + + file_name = os.path.splitext(file)[0] + + # Define Sections. + + Sections = root.xpath("/*/Section") + much = len(Sections) + print "****The xml file " + file + " has %s data sections:****" % much + for sect in Sections: + print sect.attrib['Name'] + + data = [] + + for i, sect in enumerate(Sections): + + # Extract Parameters for this section. + + path = "/*/Section[@Name='" + sect.attrib['Name'] + "']/Parameters" + parameters = root.xpath(path)[0] + + # Parameters are extracted slightly differently depending on Absorbance or Fluorescence read. + + if parameters[0].attrib['Value'] == "Absorbance": + result = extract(["Mode", "Wavelength", "Part of Plate"]) + title = '%s, %s, %s' % tuple(result) + + else: + result = extract(["Gain", "Excitation Wavelength", "Emission Wavelength", "Part of Plate", "Mode"]) + title = '%s, %s, %s, \n %s, %s' % tuple(result) + + print "****The %sth section has the parameters:****" %i + print title + + # Extract Reads for this section. + + Sections = root.xpath("/*/Section") + + welllist = get_wells_from_section(sect) + + data.append( + { + 'filename' : file_name, + 'title' : title, + 'dataframe' : pd.DataFrame(welllist) + } + ) + + # Make plot, complete with subfigure for each section. + + fig, axes = plt.subplots(nrows=1,ncols=len(Sections), figsize=(60,4.5)) + + for i, sect in enumerate(data): + sect['dataframe'].plot(title = sect['title'] , ax = axes[i] ) + + fig.tight_layout() + fig.subplots_adjust(top=0.8) + fig.suptitle("%s" % file_name, fontsize=18) + + plt.savefig('%s.png' % file_name)