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
Branches
No related tags found
No related merge requests found
...@@ -127,14 +127,7 @@ def showwells( ...@@ -127,14 +127,7 @@ def showwells(
@clogger.log @clogger.log
def ignorewells( def ignorewells(self, exclude=None):
self,
exclude=[],
experiments="all",
experimentincludes=False,
experimentexcludes=False,
clearall=False,
):
""" """
Ignore the wells specified in any future processing. Ignore the wells specified in any future processing.
...@@ -143,53 +136,40 @@ def ignorewells( ...@@ -143,53 +136,40 @@ def ignorewells(
Parameters Parameters
--------- ---------
exclude: list of strings exclude: list of strings or dict
List of labels of wells on the plate to be excluded. If there is only a single experiment, exclude is a list of labels
experiments: string or list of strings of wells to be ignored.
The experiments to include. If there are multiple experiments, exclude is a dict with experiment
experimentincludes: string, optional names as keys and a list of wells as items.
Selects only experiments that include the specified string in their
name.
experimentexcludes: string, optional
Ignores experiments that include the specified string in their
name.
Example Example
------- -------
>>> p.ignorewells(['A1', 'C2']) >>> p.ignorewells(['A1', 'C2'])
>>> p.ignorewells({"exp1" : ["A1"], "exp2": ["C3", "C4"]})
""" """
if gu.islistempty(exclude): if exclude is None:
return return
else: else:
# exclude should be a list of lists if len(self.allexperiments) == 1 and not isinstance(exclude, dict):
# make exclude a dict
if isinstance(exclude, str): if isinstance(exclude, str):
exclude = [gu.makelist(exclude)] exclude = {self.allexperiments[0]: gu.makelist(exclude)}
elif isinstance(exclude[0], str): elif isinstance(exclude, list):
exclude = [exclude] exclude = {self.allexperiments[0]: 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: 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 # drop wells
for ex, exp in zip(exclude, exps): for exp, wells in exclude.items():
# wells cannot be ignored twice # 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 # drop data from ignored wells
df = self.r df = self.r
filt = (df["experiment"] == exp) & df["well"].isin(wex) filt = (df["experiment"] == exp) & df["well"].isin(wex)
...@@ -197,22 +177,12 @@ def ignorewells( ...@@ -197,22 +177,12 @@ def ignorewells(
df = df.reset_index(drop=True) df = df.reset_index(drop=True)
self.r = df self.r = df
# store ignoredwells # store ignoredwells
self.progress["ignoredwells"][exp] += ex self.progress["ignoredwells"][exp] += wex
# remove any duplicates # remove any duplicates
self.progress["ignoredwells"][exp] = list( self.progress["ignoredwells"][exp] = list(
set(self.progress["ignoredwells"][exp]) set(self.progress["ignoredwells"][exp])
) )
# give warning # remake s data frame
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) 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.
Please to comment