@@ -126,6 +126,22 @@ def prepare_columns(df, decoy_adjunct:str = 'REV_'):
126126 coverage_p2 = pl .lit (0.5 ),
127127 )
128128
129+
130+ # Fill in infinite scores
131+ max_score = df .filter (pl .col ('score' ) < np .inf )['score' ].max ()
132+ min_score = df .filter (pl .col ('score' ) > - np .inf )['score' ].min ()
133+ inf_margin = (max_score - min_score )* 0.1
134+ df = df .with_columns (pl .col ('score' ) - min_score + inf_margin )
135+ df = df .with_columns (
136+ score = pl .when (pl .col ('score' ) == np .inf ).then (
137+ pl .lit (max_score ) + 2 * pl .lit (inf_margin )
138+ ).when (pl .col ('score' ) == - np .inf ).then (
139+ pl .lit (0 )
140+ ).otherwise (
141+ pl .col ('score' )
142+ )
143+ )
144+
129145 coverage_p1_prop = pl .col ('coverage_p1' ) / (pl .col ('coverage_p1' ) + pl .col ('coverage_p2' ))
130146 coverage_p2_prop = pl .col ('coverage_p2' ) / (pl .col ('coverage_p1' ) + pl .col ('coverage_p2' ))
131147 df = df .with_columns (
@@ -204,21 +220,6 @@ def prepare_columns(df, decoy_adjunct:str = 'REV_'):
204220 DD = (pl .col ('decoy_class' )== 'DD' ),
205221 )
206222
207- # Fill in infinite scores
208- max_score = df .filter (pl .col ('score' ) < np .inf )['score' ].max ()
209- min_score = df .filter (pl .col ('score' ) > - np .inf )['score' ].min ()
210- inf_margin = (max_score - min_score )* 0.1
211- df = df .with_columns (pl .col ('score' ) - min_score + inf_margin )
212- df = df .with_columns (
213- score = pl .when (pl .col ('score' ) == np .inf ).then (
214- pl .lit (max_score ) + 2 * pl .lit (inf_margin )
215- ).when (pl .col ('score' ) == - np .inf ).then (
216- pl .lit (0 )
217- ).otherwise (
218- pl .col ('score' )
219- )
220- )
221-
222223 df = df .with_columns (
223224 pl .col (list_cols_1 ).replace ([], None ),
224225 pl .col (list_cols_2 ).replace ([], None ),
0 commit comments