def test_yield_wells(): experiments, well = dummy_data({ 'FITC-A': [100], }) experiment_i, condition_i, well_i = next(fcmcmp.yield_wells(experiments)) assert experiment_i == experiments[0] assert condition_i == 'dummy' assert well_i.label == 'A1'
def get_channel_label(experiments, baseline=False): channels = set(x.channel for _, _, x in fcmcmp.yield_wells(experiments)) control_channels = set(x.control_channel for _, _, x in fcmcmp.yield_wells(experiments)) control_channels.discard(None) control_expts = set(x.control_expt for _, _, x in fcmcmp.yield_wells(experiments)) control_expts.discard(None) get_label = lambda x: x.split('-')[0] if len(channels) == 1: channel = next(iter(channels)) label = get_label(channel) elif channels.issubset(['GFP-A', 'RFP-A']): label = 'fluorescence' elif channels.issubset(['FSC-A', 'SSC-A']): label = 'size' else: raise ValueError("inconsistent channels: {}".format( ','.join(channels))) if len(control_channels) > 1 or len(control_expts) > 1: label = 'normalized {}'.format(label) else: if len(control_channels) == 1: control_channel = next(iter(control_channels)) label = '{} / {}'.format(label, get_label(control_channel)) if len(control_expts) == 1: control_expt = next(iter(control_expts)) label = '{} / {}'.format(label, control_expt) if baseline: label += f' / {"baseline" if baseline is True else baseline}' return label
def analyze_wells(experiments, **kwargs): control_expt_kwarg = kwargs.pop('control_expt', None) # Convert all the normal wells to "analyzed" wells. for i, experiment in enumerate(experiments): for condition in experiment['wells']: experiment['wells'][condition] = [ AnalyzedWell(experiments, i, condition, j, **kwargs) for j, _ in enumerate(experiment['wells'][condition]) ] # Normalize by the indicated control experiment(s). wells = [w for _, _, w in fcmcmp.yield_wells(experiments)] expt_map = {x['label']: x for x in experiments} control_locs = [] control_labels = [] for well in wells: control_label = pick_control_experiment(well.experiment, control_expt_kwarg) if not control_label: continue control_expt = expt_map[control_label] try: control_loc = np.mean([ control_expt['wells'][conc][well.index].linear_loc for conc in control_expt['wells'] ]) except IndexError: raise IndexError( "Make sure you have the same number of replicates for each experiment." ) control_locs.append(control_loc) control_labels.append(control_label) for well, label, loc in zip(wells, control_labels, control_locs): well.control_expt = label well.normalize(loc)
def check_wells(experiments, **expected_wells): for expriment, condition, well in fcmcmp.yield_wells(experiments): assert condition in expected_wells assert well.label in expected_wells[condition] assert isinstance(well.meta, dict) assert isinstance(well.data, pd.DataFrame)
def _yield_wells(self): yield from fcmcmp.yield_wells(self.experiments)
import docopt, fcmcmp, analysis_helpers import matplotlib.pyplot as plt from pprint import pprint args = docopt.docopt(__doc__) experiments = fcmcmp.load_experiments(args['<yml_path>']) shared_steps = analysis_helpers.SharedProcessingSteps() shared_steps.early_event_threshold = float(args['--time-gate']) shared_steps.small_cell_threshold = float(args['--size-gate']) shared_steps.low_fluorescence_threshold = float(args['--expression-gate']) shared_steps.process(experiments) table = [] for experiment, condition, well in fcmcmp.yield_wells(experiments, args['<keyword>']): well = analysis_helpers.AnalyzedWell(experiment, well, normalize_by=True) percent_on = sum(well.measurements < -0.3) / len(well.measurements) table.append((experiment['label'], condition, percent_on)) previous_label = None max_label_len = max_condition_len = 0 for label, condition, percent_on in table: max_label_len = max(len(label), max_label_len) max_condition_len = max(len(condition), max_condition_len) for label, condition, percent_on in table: print('{:{}s} {:{}s} {:.2f}%'.format(label, max_label_len, condition, max_condition_len, 100 * percent_on))