Example program illustrating usage of ms_ms1quant_time_align.
1
2
15
16from __future__ import print_function
17
18import sys
19from datetime import datetime
20import msparser
21
22
23def checkErrorHandler(errs) :
24 for i in range(1, 1 + errs.getNumberOfErrors()) :
25 print("Error number: %s : %s" % (errs.getErrorNumber(i), errs.getErrorString(i)))
26
27
28
29
30if len(sys.argv) < 3:
31 print("Usage: %s <time_alignment.xml> <schema_directory>" % sys.argv[0])
32 sys.exit(1)
33
34timeAlignmentXmlFile = sys.argv[1]
35schemaDirectory = sys.argv[2]
36start_time = datetime.now()
37
38time_align = msparser.ms_ms1quant_time_align()
39if time_align.loadXmlFile(timeAlignmentXmlFile, schemaDirectory) :
40 elapsed = datetime.now() - start_time
41 print("File loaded: %s in %d seconds" % (timeAlignmentXmlFile, elapsed.seconds))
42 print("")
43
44 data = time_align.getFinalResults()
45 num_sub_projects = len(data)
46 fraction_numbers = time_align.getSubProjectToFractionMap()
47
48
49 print("Prj\tFractn\tmeanErrsRaw\tmeanErrsAlig\tstdevErrsRaw\tstdevErrsAlig\tpearsonRaw\tpearsonAlign")
50 for prj in range(num_sub_projects):
51 fraction = fraction_numbers[prj]
52 (success, meanErrorsRaw, meanErrorsAligned, stdevErrorsRaw, stdevErrorsAligned, pearsonCoefficientRaw, pearsonCoefficientAligned) = time_align.getEvaluation(1 + prj)
53 print("%d\t%d\t%f\t%f\t%f\t%f\t%f\t%f\t" % (1+prj, fraction, meanErrorsRaw, meanErrorsAligned, stdevErrorsRaw, stdevErrorsAligned, pearsonCoefficientRaw, pearsonCoefficientAligned))
54 print("")
55
56
57 print("Fract\tminimum m/z\tmaximum mz\tminimum rt\tmaximum rt\tminbin\tmaxbin\tminrt\tmaxrt\tnum q\t#q>thr\tprojects")
58 fraction_to_prj = time_align.getFractionToSubProjectMap()
59 for fraction,proj in fraction_to_prj.items():
60 sub_proj_str = ""
61 for x in proj:
62 if sub_proj_str:
63 sub_proj_str += ", "
64 sub_proj_str = sub_proj_str + str(1+x)
65 limits = time_align.getCombinedLimits(fraction)
66 print("%d\t%f\t%f\t%f\t%f\t%d\t%d\t%d\t%d\t%d\t%d\t%s" % (fraction, limits.getMinMZ(), limits.getMaxMZ(), limits.getMinRT(), limits.getMaxRT(),limits.getCombinedMinBinNum(), limits.getCombinedMaxBinNum(), limits.getCombinedMinRT(), limits.getCombinedMaxRT(), limits.getNumQueries(), limits.getNumQueriesAboveThreshold(), sub_proj_str))
67 print("")
68
69
70 showAllNonZero = 0
71 if (showAllNonZero) :
72 for prj in range(num_sub_projects):
73 fraction = fraction_numbers[prj]
74 limits = time_align.getCombinedLimits(fraction)
75 print("Sub project: %d, fraction: %d" % (prj, fraction))
76 num_bins = len(data[prj])
77 print(" Number of bins: %d" % (num_bins))
78 for bin_num in range(num_bins) :
79 print(" Bin: %d" % (bin_num))
80 num_rts = len(data[prj][bin_num])
81 print(" Num rts: %d" % (num_rts))
82 for rt in range(num_rts) :
83
84 if (data[prj][bin_num][rt] != 0) :
85 print("SubProj: %d, bin: %d, rt: %d, offset: %f" % (1+prj, bin_num + limits.getCombinedMinBinNum(), rt + limits.getCombinedMinRT(), data[prj][bin_num][rt]))
86 else :
87 mid_project = int(num_sub_projects /2) -1
88 mid_bin = int(len(data[mid_project]) /2)
89 num_rts = len(data[mid_project][mid_bin])
90 fraction = fraction_numbers[mid_project]
91 limits = time_align.getCombinedLimits(fraction)
92 numNonZero = 0
93 elapsed = datetime.now() - start_time
94 print("Calculated mid points for: %s, elapsed time: %d seconds" % (timeAlignmentXmlFile, elapsed.seconds))
95 print("Showing first 50 non zero deltas from sub project: %d, bin number: %d, Num rts: %d, Min rt: %d" % (1 + mid_project, mid_bin + limits.getCombinedMinBinNum(),num_rts, limits.getCombinedMinRT()))
96 for rt in range(num_rts) :
97 if (data[mid_project][mid_bin][rt] != 0) :
98 if (numNonZero < 50) :
99 numNonZero = 1 + numNonZero
100 print("SubProj: %d, bin: %d, rt: %d, offset: %f" % (1+mid_project, mid_bin + limits.getCombinedMinBinNum(), rt + limits.getCombinedMinRT(), data[mid_project][mid_bin][rt]))
101
102 print("")
103 print("Showing all the feature widths for sub project: %d, bin number: %d" % (1 + mid_project, mid_bin + limits.getCombinedMinBinNum()))
104 feature_widths = time_align.getFeatureWidths()
105 features = feature_widths[mid_project][mid_bin]
106 for rt, width in features.items() :
107 print("%f\t%f" % (rt, width))
108
109 print("Time: %s" % (str(datetime.now())))
110
111checkErrorHandler(time_align.getErrorHandler())
112