1818from copy import deepcopy
1919from sys import exit
2020import logging
21- < << << << HEAD
22- import math
23- == == == =
24- >> >> >> > repo - b2 / main
2521
2622
2723class AResult (pandas .DataFrame , metaclass = abc .ABCMeta ):
@@ -95,42 +91,25 @@ def filter_result(self, expressions, scoretype='Score'):
9591 """
9692 if isinstance (expressions , tuple ):
9793 expressions = [expressions ]
98- < << << << HEAD
99-
100- == == == =
10194
102- >> >> >> > repo - b2 / main
10395 df = deepcopy (self )
10496 methods = list (set (df .columns .get_level_values (1 )))
10597 scoretypes = list (set (df .columns .get_level_values (2 )))
10698 if scoretype not in scoretypes :
107- < << << << HEAD
108- raise ValueError (
109- "Specified ScoreType {} does not match ScoreTypes of data frame {}." .format (scoretype , scoretypes ))
110-
111- == == == =
11299 raise ValueError ("Specified ScoreType {} does not match ScoreTypes of data frame {}." .format (scoretype , scoretypes ))
113100
114- >> >> >> > repo - b2 / main
115101 for expr in expressions :
116102 method , comp , thr = expr
117103 if method not in methods :
118104 raise ValueError ("Specified method {} does not match methods of data frame {}." .format (method , methods ))
119105 else :
120- < << << << HEAD
121- filt = comp (df .xs (method , axis = 1 , level = 1 ).xs (scoretype , axis = 1 , level = 1 ), thr ).values
122- == == == =
123106 filt = comp (df .xs (method , axis = 1 , level = 1 ).xs (scoretype , axis = 1 , level = 1 ), thr ).values
124- >> >> >> > repo - b2 / main
125107 # Only keep rows which contain values fulfilling the comparators logic in the specified method
126108 keep_row = [bool .any () for bool in filt ]
127109 df = df .loc [keep_row ]
128110
129111 return EpitopePredictionResult (df )
130- < << << << HEAD
131- == == == =
132112
133- >> >> >> > repo - b2 / main
134113
135114 def merge_results (self , others ):
136115 """
@@ -145,23 +124,14 @@ def merge_results(self, others):
145124
146125 if type (others ) == type (self ):
147126 others = [others ]
148- < << << << HEAD
149-
150- == == == =
151127
152- >> >> >> > repo - b2 / main
153128 # Concatenates self and to be merged dataframe(s)
154129 for other in others :
155130 df = pandas .concat ([df , other ], axis = 1 )
156131
157132 # Merge result of multiple predictors in others per allele
158- < << << << HEAD
159- df_merged = pandas .concat ([group [1 ] for group in df .groupby (level = [0 , 1 ], axis = 1 )], axis = 1 )
160-
161- == == == =
162133 df_merged = pandas .concat ([group [1 ] for group in df .groupby (level = [0 ,1 ], axis = 1 )], axis = 1 )
163134
164- >> >> >> > repo - b2 / main
165135 return EpitopePredictionResult (df_merged )
166136
167137 def from_dict (d , peps , method ):
@@ -176,28 +146,17 @@ def from_dict(d, peps, method):
176146 """
177147 scoreType = numpy .asarray ([list (m .keys ()) for m in [metrics for a , metrics in d .items ()]]).flatten ()
178148 alleles = numpy .asarray ([numpy .repeat (a , len (set (scoreType ))) for a in d ]).flatten ()
179- < << << << HEAD
180-
181- meth = numpy .repeat (method , len (scoreType ))
182- multi_cols = pandas .MultiIndex .from_arrays ([alleles , meth , scoreType ], names = ["Allele" , "Method" , "ScoreType" ])
183- df = pandas .DataFrame (float (0 ), index = pandas .Index (peps ), columns = multi_cols )
184- == == == =
185149
186150 meth = numpy .repeat (method , len (scoreType ))
187151 multi_cols = pandas .MultiIndex .from_arrays ([alleles , meth , scoreType ], names = ["Allele" , "Method" , "ScoreType" ])
188152 df = pandas .DataFrame (float (0 ),index = pandas .Index (peps ), columns = multi_cols )
189- >> >> >> > repo - b2 / main
190153 df .index .name = 'Peptides'
191154 # Fill DataFrame
192155 for allele , metrics in d .items ():
193156 for metric , pep_scores in metrics .items ():
194157 for pep , score in pep_scores .items ():
195158 df [allele ][method ][metric ][pep ] = score
196- < << << << HEAD
197-
198- == == == =
199159
200- >> >> >> > repo - b2 / main
201160 return EpitopePredictionResult (df )
202161
203162
@@ -207,19 +166,11 @@ class Distance2SelfResult(AResult):
207166 """
208167
209168 def filter_result (self , expressions ):
210- < << << << HEAD
211- # TODO: has to be implemented
212- pass
213-
214- def merge_results (self , others ):
215- # TODO: has to be implemented
216- == == == =
217169 #TODO: has to be implemented
218170 pass
219171
220172 def merge_results (self , others ):
221173 #TODO: has to be implemented
222- >> >> >> > repo - b2 / main
223174 pass
224175
225176
@@ -261,22 +212,14 @@ def filter_result(self, expressions):
261212 if isinstance (expressions , tuple ):
262213 expressions = [expressions ]
263214
264- < << << << HEAD
265- # builde logical expression
266- == == == =
267215 #builde logical expression
268- >> >> >> > repo - b2 / main
269216 masks = [list (comp (self .loc [:, method ], thr )) for method , comp , thr in expressions ]
270217
271218 if len (masks ) > 1 :
272219 masks = numpy .logical_and (* masks )
273220 else :
274221 masks = masks [0 ]
275- < << << << HEAD
276- # apply to all rows
277- == == == =
278222 #apply to all rows
279- >> >> >> > repo - b2 / main
280223
281224 return CleavageSitePredictionResult (self .loc [masks , :])
282225
@@ -296,11 +239,7 @@ def merge_results(self, others):
296239
297240 for i in range (len (others )):
298241 o = others [i ]
299- < << << << HEAD
300- df1a , df2a = df .align (o , )
301- == == == =
302242 df1a , df2a = df .align (o ,)
303- >> >> >> > repo - b2 / main
304243
305244 o_diff = o .index .difference (df .index )
306245 d_diff = df .index .difference (o .index )
@@ -324,11 +263,7 @@ def merge_results(self, others):
324263 df1 = df1a .fillna (0 )
325264 df2 = df2a .fillna (0 )
326265
327- < << << << HEAD
328- df_merged = df1 + df2
329- == == == =
330266 df_merged = df1 + df2
331- >> >> >> > repo - b2 / main
332267 false_zero = df_merged == 0
333268 zero = true_zero & false_zero
334269
@@ -377,11 +312,7 @@ def filter_result(self, expressions):
377312 masks = numpy .logical_and (* masks )
378313 else :
379314 masks = masks [0 ]
380- < << << << HEAD
381- # apply to all rows
382- == == == =
383315 #apply to all rows
384- >> >> >> > repo - b2 / main
385316 return CleavageFragmentPredictionResult (self .loc [masks , :])
386317
387318 def merge_results (self , others ):
@@ -398,11 +329,7 @@ def merge_results(self, others):
398329 if type (others ) == type (self ):
399330 others = [others ]
400331
401- < << << << HEAD
402- return CleavageFragmentPredictionResult (pandas .concat ([self ] + others , axis = 1 ))
403- == == == =
404332 return CleavageFragmentPredictionResult (pandas .concat ([self ]+ others , axis = 1 ))
405- >> >> >> > repo - b2 / main
406333
407334
408335class TAPPredictionResult (AResult ):
@@ -442,11 +369,7 @@ def filter_result(self, expressions):
442369 masks = numpy .logical_and (* masks )
443370 else :
444371 masks = masks [0 ]
445- < << << << HEAD
446- # apply to all rows
447- == == == =
448372 #apply to all rows
449- >> >> >> > repo - b2 / main
450373
451374 return TAPPredictionResult (self .loc [masks , :])
452375
@@ -463,7 +386,6 @@ def merge_results(self, others):
463386 if type (others ) == type (self ):
464387 others = [others ]
465388
466- < << << << HEAD
467389 return TAPPredictionResult (pandas .concat ([self ] + others , axis = 1 ))
468390
469391
@@ -551,6 +473,3 @@ def merge_results(self, others):
551473 tcr .columns = pandas .MultiIndex .from_tuples (tuples )
552474 result = pandas .concat ([tcr , result ], axis = 1 )
553475 return result
554- == == == =
555- return TAPPredictionResult (pandas .concat ([self ]+ others , axis = 1 ))
556- >> >> >> > repo - b2 / main
0 commit comments