comparison mqparam.py @ 3:175e062b6a17 draft

"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/maxquant commit 74b5aa29e49deaaebe19ce2355a70d4f570f4951"
author galaxyp
date Thu, 15 Aug 2019 08:09:00 -0400
parents 8bac3cc5c5de
children dcd39bcc7481
comparison
equal deleted inserted replaced
2:666f3453a99d 3:175e062b6a17
62 True 62 True
63 """ 63 """
64 64
65 child = ET.SubElement(el, name, attrib=attrib if attrib else {}) 65 child = ET.SubElement(el, name, attrib=attrib if attrib else {})
66 child.text = str(text) 66 child.text = str(text)
67
68 @staticmethod
69 def _check_validity(design, len_infiles):
70 "Perform some checks on the exp. design template"
71 design_len = len(design['Name'])
72 match = len(list(filter(lambda x: bool(x), design['Name'])))
73 if match < len_infiles:
74 raise Exception("Error parsing experimental design template: " +
75 "Found only {} matching entries ".format(design_len) +
76 "for {} input files".format(len_infiles))
77 for i in range(0, design_len):
78 msg = "Error in line " + str(i + 2) + " of experimental design: "
79 if not (design['Name'][i] and design['Experiment'][i]):
80 raise Exception(msg + " Name or Experiment is empty.")
81 if design['PTM'][i].lower() not in ('true', 'false'):
82 raise Exception(msg + "Defines invalid PTM value, " +
83 "should be 'True' or 'False'.")
84 try:
85 int(design['Fraction'][i])
86 except ValueError as e:
87 raise Exception(msg + str(e))
67 88
68 def _make_exp_design(self, infiles): 89 def _make_exp_design(self, infiles):
69 """Create a dict representing an experimental design from 90 """Create a dict representing an experimental design from
70 an experimental design template and a list of input files. 91 an experimental design template and a list of input files.
71 If the experimental design template is None, create a default 92 If the experimental design template is None, create a default
78 >>> design['Name'] 99 >>> design['Name']
79 ['./test-data/BSA_min_21.mzXML', './test-data/BSA_min_22.mzXML'] 100 ['./test-data/BSA_min_21.mzXML', './test-data/BSA_min_22.mzXML']
80 >>> design['Fraction'] 101 >>> design['Fraction']
81 ['1', '2'] 102 ['1', '2']
82 """ 103 """
104
83 design = {s: [] for s in ("Name", "PTM", "Fraction", "Experiment")} 105 design = {s: [] for s in ("Name", "PTM", "Fraction", "Experiment")}
84 if not self.exp_design: 106 if not self.exp_design:
85 design["Name"] = infiles 107 design["Name"] = infiles
86 design["Fraction"] = ('32767',) * len(infiles) 108 design["Fraction"] = ('32767',) * len(infiles)
87 design["Experiment"] = [os.path.split(f)[1] for f in infiles] 109 design["Experiment"] = [os.path.split(f)[1] for f in infiles]
92 index = [] 114 index = []
93 for i in index_line.split('\t'): 115 for i in index_line.split('\t'):
94 if i in design: 116 if i in design:
95 index.append(i) 117 index.append(i)
96 else: 118 else:
97 raise Exception("Invalid comlumn index in experimental" 119 raise Exception("Invalid column index in experimental"
98 + " design template: {}".format(i)) 120 + " design template: {}".format(i))
121
99 for line in design_file: 122 for line in design_file:
100 row = line.strip().split('\t') 123 row = line.strip().split('\t')
101 for e, i in zip_longest(row, index): 124 for e, i in zip_longest(row, index):
125 if i == "Fraction" and e == '':
126 e = 32767
127 elif i == "PTM" and not e:
128 e = 'False'
102 design[i].append(e) 129 design[i].append(e)
103 130
104 # map infiles to names in exp. design template 131 # map infiles to names in exp. design template
105 names = [] 132 names = []
106 names_to_paths = {} 133 names_to_paths = {}
115 fname = re.sub(self.substitution_rx, '_', name) 142 fname = re.sub(self.substitution_rx, '_', name)
116 names.append(names_to_paths[fname] if fname in names_to_paths 143 names.append(names_to_paths[fname] if fname in names_to_paths
117 else None) 144 else None)
118 # replace orig. file names with matching links to galaxy datasets 145 # replace orig. file names with matching links to galaxy datasets
119 design['Name'] = names 146 design['Name'] = names
147 MQParam._check_validity(design, len(infiles))
120 148
121 return design 149 return design
122 150
123 def add_infiles(self, infiles, interactive): 151 def add_infiles(self, infiles, interactive):
124 """Add a list of raw/mzxml files to the mqpar.xml. 152 """Add a list of raw/mzxml files to the mqpar.xml.
221 fasta_node.clear() 249 fasta_node.clear()
222 fasta_node.tag = "fastaFiles" 250 fasta_node.tag = "fastaFiles"
223 251
224 for index in range(len(files)): 252 for index in range(len(files)):
225 filepath = '<fastaFilePath>' + files[index] 253 filepath = '<fastaFilePath>' + files[index]
254 identifier = identifier.replace('<', '&lt;')
255 description = description.replace('<', '&lt;')
226 fasta = self.fasta_template.replace('<fastaFilePath>', filepath) 256 fasta = self.fasta_template.replace('<fastaFilePath>', filepath)
227 fasta = fasta.replace('<identifierParseRule>', 257 fasta = fasta.replace('<identifierParseRule>',
228 '<identifierParseRule>' + identifier) 258 '<identifierParseRule>' + identifier)
229 fasta = fasta.replace('<descriptionParseRule>', 259 fasta = fasta.replace('<descriptionParseRule>',
230 '<descriptionParseRule>' + description) 260 '<descriptionParseRule>' + description)