Mercurial > repos > jjohnson > spectrast
comparison spectrast_params.py @ 3:7f02fc51bddf draft
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/spectrast commit 379705f578f9a0465f497894c7d2b5f68b6a55e6-dirty
| author | jjohnson | 
|---|---|
| date | Wed, 25 Jul 2018 10:58:17 -0400 | 
| parents | e67b0cc10377 | 
| children | c9bfe6adb7cd | 
   comparison
  equal
  deleted
  inserted
  replaced
| 2:e67b0cc10377 | 3:7f02fc51bddf | 
|---|---|
| 3 from __future__ import print_function | 3 from __future__ import print_function | 
| 4 | 4 | 
| 5 import argparse | 5 import argparse | 
| 6 import re | 6 import re | 
| 7 import sys | 7 import sys | 
| 8 | |
| 9 create_opts = [ | |
| 10 'outputFileName', | |
| 11 'useProbTable', | |
| 12 'useProteinList', | |
| 13 'printMRMTable', | |
| 14 'remark', | |
| 15 'binaryFormat', | |
| 16 'writeDtaFiles', | |
| 17 'writeMgfFiles', | |
| 18 'removeDecoyProteins', | |
| 19 'plotSpectra', | |
| 20 'minimumProbabilityToInclude', | |
| 21 'maximumFDRToInclude', | |
| 22 'datasetName', | |
| 23 'setFragmentation', | |
| 24 'setDeamidatedNXST', | |
| 25 'addMzXMLFileToDatasetName', | |
| 26 'centroidPeaks', | |
| 27 'rawSpectraNoiseThreshold', | |
| 28 'rawSpectraMaxDynamicRange', | |
| 29 'minimumNumAAToInclude', | |
| 30 'minimumNumPeaksToInclude', | |
| 31 'skipRawAnnotation', | |
| 32 'minimumDeltaCnToInclude', | |
| 33 'maximumMassDiffToInclude', | |
| 34 'bracketSpectra', | |
| 35 'mergeBracket', | |
| 36 'filterCriteria', | |
| 37 'combineAction', | |
| 38 'buildAction', | |
| 39 'refreshDatabase', | |
| 40 'reduceSpectra', | |
| 41 'refreshDeleteUnmapped', | |
| 42 'refreshDeleteMultimapped', | |
| 43 'reannotatePeaks', | |
| 44 'minimumNumPeaksToInclude', | |
| 45 'minimumMRMQ3MZ', | |
| 46 'maximumMRMQ3MZ', | |
| 47 'minimumNumPeaksToInclude', | |
| 48 'refreshTrypticOnly', | |
| 49 'minimumNumReplicates', | |
| 50 'removeDissimilarReplicates', | |
| 51 'peakQuorum', | |
| 52 'maximumNumPeaksUsed', | |
| 53 'maximumNumReplicates', | |
| 54 'maximumNumPeaksKept', | |
| 55 'replicateWeight', | |
| 56 'recordRawSpectra', | |
| 57 'minimumNumReplicates', | |
| 58 'qualityLevelRemove,', | |
| 59 'qualityPenalizeSingletons', | |
| 60 'qualityImmuneProbThreshold', | |
| 61 'qualityImmuneMultipleEngines', | |
| 62 'useBayesianDenoiser', | |
| 63 'trainBayesianDenoiser', | |
| 64 'denoiserMinimumSignalProb', | |
| 65 'denoiserParamFile', | |
| 66 'decoyConcatenate', | |
| 67 'decoySizeRatio', | |
| 68 'decoyPrecursorSwap', | |
| 69 'normalizeRTWithLandmarks', | |
| 70 'normalizeRTLinearRegression', | |
| 71 'unidentifiedClusterIndividualRun', | |
| 72 'unidentifiedClusterMinimumDot', | |
| 73 'unidentifiedRemoveSinglyCharged', | |
| 74 'unidentifiedMinimumNumPeaksToInclude', | |
| 75 'unidentifiedSingletonXreaThreshold', | |
| 76 'allowableModTokens' | |
| 77 ] | |
| 78 | |
| 79 filter_opts = [ | |
| 80 'outputFileName', | |
| 81 'useProbTable', | |
| 82 'useProteinList', | |
| 83 'printMRMTable', | |
| 84 'remark', | |
| 85 'binaryFormat', | |
| 86 'writeDtaFiles', | |
| 87 'writeMgfFiles', | |
| 88 'removeDecoyProteins', | |
| 89 'plotSpectra', | |
| 90 'minimumProbabilityToInclude', | |
| 91 'maximumFDRToInclude', | |
| 92 'datasetName', | |
| 93 'setFragmentation', | |
| 94 'setDeamidatedNXST', | |
| 95 'addMzXMLFileToDatasetName', | |
| 96 'centroidPeaks', | |
| 97 'rawSpectraNoiseThreshold', | |
| 98 'rawSpectraMaxDynamicRange', | |
| 99 'minimumNumAAToInclude', | |
| 100 'minimumNumPeaksToInclude', | |
| 101 'skipRawAnnotation', | |
| 102 'minimumDeltaCnToInclude', | |
| 103 'maximumMassDiffToInclude', | |
| 104 'bracketSpectra', | |
| 105 'mergeBracket', | |
| 106 'filterCriteria', | |
| 107 'combineAction', | |
| 108 'buildAction', | |
| 109 'refreshDatabase', | |
| 110 'reduceSpectra', | |
| 111 'refreshDeleteUnmapped', | |
| 112 'refreshDeleteMultimapped', | |
| 113 'reannotatePeaks', | |
| 114 'minimumNumPeaksToInclude', | |
| 115 'minimumMRMQ3MZ', | |
| 116 'maximumMRMQ3MZ', | |
| 117 'minimumNumPeaksToInclude', | |
| 118 'refreshTrypticOnly', | |
| 119 'minimumNumReplicates', | |
| 120 'removeDissimilarReplicates', | |
| 121 'peakQuorum', | |
| 122 'maximumNumPeaksUsed', | |
| 123 'maximumNumReplicates', | |
| 124 'maximumNumPeaksKept', | |
| 125 'replicateWeight', | |
| 126 'recordRawSpectra', | |
| 127 'minimumNumReplicates', | |
| 128 'qualityLevelRemove,', | |
| 129 'qualityPenalizeSingletons', | |
| 130 'qualityImmuneProbThreshold', | |
| 131 'qualityImmuneMultipleEngines', | |
| 132 'useBayesianDenoiser', | |
| 133 'trainBayesianDenoiser', | |
| 134 'denoiserMinimumSignalProb', | |
| 135 'denoiserParamFile', | |
| 136 'decoyConcatenate', | |
| 137 'decoySizeRatio', | |
| 138 'decoyPrecursorSwap', | |
| 139 'normalizeRTWithLandmarks', | |
| 140 'normalizeRTLinearRegression', | |
| 141 'unidentifiedClusterIndividualRun', | |
| 142 'unidentifiedClusterMinimumDot', | |
| 143 'unidentifiedRemoveSinglyCharged', | |
| 144 'unidentifiedMinimumNumPeaksToInclude', | |
| 145 'unidentifiedSingletonXreaThreshold', | |
| 146 'allowableModTokens' | |
| 147 ] | |
| 8 | 148 | 
| 9 search_opts = [ | 149 search_opts = [ | 
| 10 'libraryFile', | 150 'libraryFile', | 
| 11 'databaseFile', | 151 'databaseFile', | 
| 12 'databaseType', | 152 'databaseType', | 
| 63 ' to create an updated search.params') | 203 ' to create an updated search.params') | 
| 64 parser.add_argument( | 204 parser.add_argument( | 
| 65 'param_files', nargs='*', | 205 'param_files', nargs='*', | 
| 66 help='A SpectraST search.params files') | 206 help='A SpectraST search.params files') | 
| 67 parser.add_argument( | 207 parser.add_argument( | 
| 208 '-m', '--mode', choices=['search','create','filter'], | |
| 209 help='') | |
| 210 parser.add_argument( | |
| 68 '-o', '--output', | 211 '-o', '--output', | 
| 69 help='Output file (-) for stdout') | 212 help='Output file (-) for stdout') | 
| 70 args = parser.parse_args() | 213 args = parser.parse_args() | 
| 71 | 214 | 
| 72 output_wtr = open(args.output, 'w')\ | 215 output_wtr = open(args.output, 'w')\ | 
| 73 if args.output and args.output != '-' else sys.stdout | 216 if args.output and args.output != '-' else sys.stdout | 
| 74 | 217 | 
| 75 optpat = re.compile('^([a-z]\w+)\s*[=:]\s*([^=]+)$') | 218 optpat = re.compile('^([a-z]\w+)\s*[=:]\s*([^=]+)$') | 
| 76 search_params = dict() | 219 | 
| 77 | 220 valid_opts = search_opts if args.mode == 'search' else create_opts if args.mode == 'create' else filter_opts | 
| 78 # Collect all search_params | 221 valid_params = dict() | 
| 79 def parse_params(param_file, fh): | 222 | 
| 223 # Collect all valid_params | |
| 224 def parse_params(param_file, fh, valid_opts): | |
| 80 for i, line in enumerate(fh): | 225 for i, line in enumerate(fh): | 
| 81 try: | 226 try: | 
| 82 m = optpat.match(line.rstrip()) | 227 m = optpat.match(line.rstrip()) | 
| 83 if m: | 228 if m: | 
| 84 k, v = m.groups() | 229 k, v = m.groups() | 
| 85 if k in search_opts: | 230 if k in valid_opts: | 
| 86 search_params[k] = v | 231 valid_params[k] = v | 
| 87 except Exception, e: | 232 except Exception, e: | 
| 88 print('%s(%d): %s %s' % (param_file, i, line, e), | 233 print('%s(%d): %s %s' % (param_file, i, line, e), | 
| 89 file=sys.stderr) | 234 file=sys.stderr) | 
| 90 | 235 | 
| 91 if args.param_files: | 236 if args.param_files: | 
| 92 for param_file in args.param_files: | 237 for param_file in args.param_files: | 
| 93 try: | 238 try: | 
| 94 with open(param_file, 'r') as fh: | 239 with open(param_file, 'r') as fh: | 
| 95 parse_params(param_file, fh) | 240 parse_params(param_file, fh, valid_opts) | 
| 96 except Exception, e: | 241 except Exception, e: | 
| 97 print('parse_params: %s' % e, file=sys.stderr) | 242 print('parse_params: %s' % e, file=sys.stderr) | 
| 98 else: | 243 else: | 
| 99 try: | 244 try: | 
| 100 parse_params('stdin', sys.stdin) | 245 parse_params('stdin', sys.stdin) | 
| 101 except Exception, e: | 246 except Exception, e: | 
| 102 print('parse_params: %s' % e, file=sys.stderr) | 247 print('parse_params: %s' % e, file=sys.stderr) | 
| 103 | 248 | 
| 104 # Write search_params | 249 # Write valid_params | 
| 105 for search_opt in search_opts: | 250 for valid_opt in valid_opts: | 
| 106 if search_opt in search_params: | 251 if valid_opt in valid_params: | 
| 107 print('%s = %s' % (search_opt, search_params[search_opt]), file=output_wtr) | 252 print('%s = %s' % (valid_opt, valid_params[valid_opt]), file=output_wtr) | 
| 108 | 253 | 
| 109 | 254 | 
| 110 if __name__ == "__main__": | 255 if __name__ == "__main__": | 
| 111 __main__() | 256 __main__() | 
| 257 | 
