Skip to content
Snippets Groups Projects
Commit 396a3d8c authored by pswain's avatar pswain
Browse files

change(ignorewells): takes a dict of exps

parent b9247712
No related branches found
No related tags found
No related merge requests found
......@@ -127,14 +127,7 @@ def showwells(
@clogger.log
def ignorewells(
self,
exclude=[],
experiments="all",
experimentincludes=False,
experimentexcludes=False,
clearall=False,
):
def ignorewells(self, exclude=None):
"""
Ignore the wells specified in any future processing.
......@@ -143,53 +136,40 @@ def ignorewells(
Parameters
---------
exclude: list of strings
List of labels of wells on the plate to be excluded.
experiments: string or list of strings
The experiments to include.
experimentincludes: string, optional
Selects only experiments that include the specified string in their
name.
experimentexcludes: string, optional
Ignores experiments that include the specified string in their
name.
exclude: list of strings or dict
If there is only a single experiment, exclude is a list of labels
of wells to be ignored.
If there are multiple experiments, exclude is a dict with experiment
names as keys and a list of wells as items.
Example
-------
>>> p.ignorewells(['A1', 'C2'])
>>> p.ignorewells({"exp1" : ["A1"], "exp2": ["C3", "C4"]})
"""
if gu.islistempty(exclude):
if exclude is None:
return
else:
# exclude should be a list of lists
if isinstance(exclude, str):
exclude = [gu.makelist(exclude)]
elif isinstance(exclude[0], str):
exclude = [exclude]
# check consistency
if len(self.allexperiments) == 1:
exps = self.allexperiments
if exps[0] == "combined":
pass
else:
exps = sunder.getset(
self,
experiments,
experimentincludes,
experimentexcludes,
"experiment",
nonull=True,
)
if len(exclude) != len(exps) and not clearall:
raise errors.IgnoreWells(
"Either a list of wells to exclude for a particular\n"
"experiment or a list of experiments must be given."
)
else:
if len(self.allexperiments) == 1 and not isinstance(exclude, dict):
# make exclude a dict
if isinstance(exclude, str):
exclude = {self.allexperiments[0]: gu.makelist(exclude)}
elif isinstance(exclude, list):
exclude = {self.allexperiments[0]: exclude}
else:
raise errors.IgnoreWells(f"{exclude} is in the wrong format.")
if isinstance(exclude, dict):
# make each value a list
exclude = {
key: [value] if isinstance(value, str) else value
for key, value in exclude.items()
}
# drop wells
for ex, exp in zip(exclude, exps):
for exp, wells in exclude.items():
# wells cannot be ignored twice
wex = list(set(ex) - set(self.progress["ignoredwells"][exp]))
wex = list(
set(wells) - set(self.progress["ignoredwells"][exp])
)
# drop data from ignored wells
df = self.r
filt = (df["experiment"] == exp) & df["well"].isin(wex)
......@@ -197,22 +177,12 @@ def ignorewells(
df = df.reset_index(drop=True)
self.r = df
# store ignoredwells
self.progress["ignoredwells"][exp] += ex
self.progress["ignoredwells"][exp] += wex
# remove any duplicates
self.progress["ignoredwells"][exp] = list(
set(self.progress["ignoredwells"][exp])
)
# give warning
anycorrections = np.count_nonzero(
self.sc[
[col for col in self.sc.columns if "correct" in col]
].values
)
if np.any(anycorrections):
print(
"Warning: you have ignored wells after correcting\n"
"the data. It is best to ignorewells first, before\n"
"running any analysis."
)
# remake summary data
admin.update_s(self)
# remake s data frame
admin.update_s(self)
else:
raise errors.IgnoreWells(f"{exclude} is in the wrong format.")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment