Ejemplo n.º 1
0
                                            del_if_exists=True,
                                            include_imgstore_name=True)
        except ValueError:
            print('imgstore error')
            day_metadata = get_day_metadata(plate_metadata,
                                            manualmetadata_file,
                                            saveto=metadata_file,
                                            del_if_exists=True,
                                            include_imgstore_name=False)

        day_metadata = pd.merge(
            day_metadata,
            drug_plates,
            left_on=['source_plate_id', 'well_name'],
            right_on=['shuffled_plate_id', 'destination_well'],
            suffixes=('_day', '_robot'),
            how='outer')
        day_metadata.drop(
            day_metadata[day_metadata['imaging_plate_id'].isna()].index,
            inplace=True)

        files_to_check = day_metadata_check(day_metadata, day, plate_size=48)
        number_wells_per_plate(day_metadata, day)

        day_metadata.to_csv(metadata_file, index=False)

    # %%concatenate day metadata

    # combine all the metadata files
    concatenate_days_metadata(PROJECT_DIRECTORY, list_days=None, saveto=None)
Ejemplo n.º 2
0
def compile_day_metadata(aux_dir,
                         day,
                         n_wells=96,
                         from_source_plate=False,
                         from_robot_runlog=False):
    """ Compile experiment day metadata from wormsorter and hydra rig metadata for a given day in 
        'AuxiliaryFiles' directory 
        
        Parameters
        ----------
        aux_dir : str
            Path to "AuxiliaryFiles" containing metadata  
        day : str, None
            Experiment day folder in format 'YYYYMMDD'
        from_source_plate : bool
            Compile day metadata using source plate metadata ('source_plate.csv') and mapping for 
            each imaging plate ID ('source2imaging.csv')
        from_robot_runlog : bool
            Compile plate metadata from OpenTrons run log files (eg. for randomised plates)
            
        Returns
        -------
        day_metadata : pandas.DataFrame
            Compiled day metadata
    """
    from tierpsytools.hydra.compile_metadata import (
        populate_6WPs,
        populate_24WPs,
        populate_96WPs,
        get_day_metadata,
        get_source_metadata,
        merge_basic_and_source_meta,
        #merge_robot_metadata,
        #merge_robot_wormsorter,
        number_wells_per_plate,
        day_metadata_check)

    day_dir = Path(aux_dir) / str(day)

    wormsorter_meta = day_dir / (str(day) + '_wormsorter.csv')
    hydra_meta = day_dir / (str(day) + '_manual_metadata.csv')

    # Expand wormsorter metadata to have separate row for each well (96-well or 6-well plate format)
    if n_wells == 6:
        plate_metadata = populate_6WPs(wormsorter_meta)
    elif n_wells == 24:
        plate_metadata = populate_24WPs(wormsorter_meta)
    elif n_wells == 96:
        plate_metadata = populate_96WPs(wormsorter_meta)
    else:
        raise ValueError("Please choose n_wells from: [6, 24, 96]")

    from_source_plate = True if from_robot_runlog else from_source_plate

    if from_source_plate:
        source_plate_meta = day_dir / 'source_plates.csv'

        plate_mapping_meta = day_dir / 'source2plate.csv'

        source_metadata = get_source_metadata(
            sourceplates_file=source_plate_meta,
            imaging2source_file=plate_mapping_meta)

        plate_metadata = merge_basic_and_source_meta(
            plate_metadata,
            source_metadata,
            merge_on=['imaging_plate_id', 'well_name'],
            saveto=None,
            del_if_exists=False)


# =============================================================================
#     if from_robot_runlog:
#         robot_runlog_meta = day_dir / 'robot_runlog.csv'
#
#         drug_metadata = merge_robot_metadata(robot_runlog_meta,
#                                              randomized_by='column',
#                                              saveto=None,
#                                              drug_by_column=True,
#                                              compact_drug_plate=False,
#                                              del_if_exists=False)
#
#         plate_metadata = merge_robot_wormsorter(day_dir,
#                                                 drug_metadata,
#                                                 plate_metadata,
#                                                 bad_wells_csv=None,
#                                                 merge_on=['imaging_plate_id', 'well_name'],
#                                                 saveto=None,
#                                                 del_if_exists=False)
# =============================================================================

    day_metadata = get_day_metadata(complete_plate_metadata=plate_metadata,
                                    hydra_metadata_file=hydra_meta,
                                    merge_on=['imaging_plate_id'],
                                    n_wells=n_wells,
                                    run_number_regex='run\\d+_',
                                    saveto=None,
                                    del_if_exists=False,
                                    include_imgstore_name=True,
                                    raw_day_dir=None)

    day_metadata_check(day_metadata,
                       day_dir)  # check day metadata is correct dimension
    print(number_wells_per_plate(day_metadata, day_dir))

    return day_metadata