Skip to content

Commit de7e01b

Browse files
committed
Add option to select type of intensity to calculate RSD
1 parent be15b27 commit de7e01b

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

dimspy/process/replicate_processing.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def read_scans(fn, source, function_noise, min_scans=1, filter_scan_events=None)
119119
return scans
120120

121121

122-
def average_replicate_scans(name, pls, ppm=2.0, min_fraction=0.8, rsd_thres=30.0, block_size=5000, ncpus=None):
122+
def average_replicate_scans(name, pls, ppm=2.0, min_fraction=0.8, rsd_thres=30.0, rsd_on="intensity", block_size=5000, ncpus=None):
123123

124124
emlst = np.array(map(lambda x: x.size == 0, pls))
125125
if np.sum(emlst) > 0:
@@ -137,18 +137,26 @@ def average_replicate_scans(name, pls, ppm=2.0, min_fraction=0.8, rsd_thres=30.0
137137
if v is not None:
138138
pl_avg.metadata[k].append(v)
139139

140-
pl_avg.add_attribute("snr", pm.attr_mean_vector('snr'), on_index=2)
140+
if rsd_on != "intensity":
141+
pl_avg.add_attribute(rsd_on, pm.attr_mean_vector(rsd_on), on_index=2)
142+
rsd_label = "rsd_{}".format(rsd_on)
143+
shift = 1
144+
else:
145+
rsd_label = "rsd"
146+
shift = 0
147+
148+
pl_avg.add_attribute("snr", pm.attr_mean_vector('snr'), on_index=2+shift)
141149
pl_avg.add_attribute("snr_flag", np.ones(pl_avg.full_size), flagged_only=False, is_flag=True)
142150

143-
pl_avg.add_attribute("rsd", pm.rsd(flagged_only=False), on_index=5)
151+
pl_avg.add_attribute(rsd_label, pm.rsd(on_attr=rsd_on, flagged_only=False), on_index=5+shift)
144152

145153
if min_fraction is not None:
146154
pl_avg.add_attribute("fraction_flag", (pm.present / float(pm.shape[0])) >= min_fraction, flagged_only=False, is_flag=True)
147155
if rsd_thres is not None:
148156
if pm.shape[0] == 1:
149157
logging.warning('applying RSD filter on single scan, all peaks removed')
150-
rsd_flag = map(lambda x: not np.isnan(x) and x < rsd_thres, pl_avg.get_attribute("rsd", flagged_only=False))
151-
pl_avg.add_attribute("rsd_flag", rsd_flag, flagged_only=False, is_flag=True)
158+
rsd_flag = map(lambda x: not np.isnan(x) and x < rsd_thres, pl_avg.get_attribute(rsd_label, flagged_only=False))
159+
pl_avg.add_attribute("{}_flag".format(rsd_label), rsd_flag, flagged_only=False, is_flag=True)
152160
return pl_avg
153161

154162

0 commit comments

Comments
 (0)