object_file_postfixes.append(object_file_postfix) pdc = import_cp2_csv_results(cp2_csv_path, image_file_postfix, object_file_postfixes, csv_delimiter, csv_extension) Importer().set_pdc(pdc) utils.update_state(importer.__name__, 'imported') print 'Finished importing data from CellProfiler' return 'Finished importing data from CellProfiler' __dict__ = sys.modules[__name__].__dict__ utils.register_module(__name__, 'CellProfiler import', __dict__, utils.DEFAULT_STATE) utils.register_parameter(__name__, 'image_cp2_file', utils.PARAM_INPUT_FILE, 'Image CSV file from CellProfiler 2', optional=True) utils.set_parameter_hook(__name__, 'image_cp2_file', importer.filename_hook) utils.register_parameter(__name__, 'object_cp2_csv_files', utils.PARAM_INPUT_FILES, 'Object CSV files from CellProfiler 2', optional=True) utils.set_parameter_hook(__name__, 'object_cp2_csv_files', importer.filename_hook) utils.register_parameter(__name__, 'cp2_csv_path', utils.PARAM_PATH, 'Path to CellProfiler 2 CSV files', optional=True) utils.set_parameter_hook(__name__, 'cp2_csv_path', importer.filename_hook) utils.register_parameter(__name__, 'csv_delimiter', utils.PARAM_STR, 'Delimiter for the CSV files', ',') utils.register_parameter(__name__, 'csv_extension', utils.PARAM_STR, 'Extension for the CSV files', '.csv') utils.register_action(__name__, 'import_cp', 'Import data from CellProfiler CSV files', import_data_from_cp)
def connect_to_database(): from sqlalchemy import create_engine, MetaData, Table try: database_url except: raise utils.ParameterException( 'You need to specify the url of the database!') try: print 'Connecting to database: {}'.format(database_url) engine = create_engine(database_url) metadata = MetaData(bind=engine) metadata.create_all() images_table = Table('images', metadata, autoload=True, autoload_with=engine) objects_table = Table('objects', metadata, autoload=True, autoload_with=engine) DBConnection(engine, metadata, images_table, objects_table) utils.register_action(__name__, 'reload_db_schema', 'Reload database schema', reload_db_schema) utils.register_parameter( __name__, 'use_plate_filter', utils.PARAM_BOOL, 'Select plates to import?', False, hook=use_filter_hook) utils.register_parameter( __name__, 'use_well_filter', utils.PARAM_BOOL, 'Select wells to import?', False, hook=use_filter_hook) utils.register_parameter( __name__, 'use_replicate_filter', utils.PARAM_BOOL, 'Select replicates to import?', False, hook=use_filter_hook) utils.register_parameter( __name__, 'use_position_filter', utils.PARAM_BOOL, 'Select positions to import?', False, hook=use_filter_hook) utils.register_parameter( __name__, 'use_treatment_filter', utils.PARAM_BOOL, 'Filter treatments to import?', False, hook=use_filter_hook) utils.register_parameter( __name__, 'image_id_db_column', utils.PARAM_STR, 'Image id column in the image table', items=[]) utils.register_parameter( __name__, 'object_img_id_db_column', utils.PARAM_STR, 'Image id column in the object table', items=[]) utils.register_parameter( __name__, 'position_x_db_column', utils.PARAM_STR, 'Position X column in the image table', items=[]) utils.register_parameter( __name__, 'position_y_db_column', utils.PARAM_STR, 'Position Y column in the image table', items=[]) utils.register_parameter( __name__, 'plate_db_column', utils.PARAM_STR, 'Plate column in the image table', items=[], hook=db_column_hook) utils.register_parameter( __name__, 'well_db_column', utils.PARAM_STR, 'Well column in the image table', items=[], hook=db_column_hook) utils.register_parameter( __name__, 'replicate_db_column', utils.PARAM_STR, 'Replicate column in the image table', items=[], hook=db_column_hook) utils.register_parameter( __name__, 'position_db_column', utils.PARAM_STR, 'Position column in the image table', items=[], hook=db_column_hook) utils.register_parameter( __name__, 'treatment_db_column', utils.PARAM_STR, 'Treatment column in the image table', items=[]) utils.register_parameter( __name__, 'images_db_columns', utils.PARAM_STRS, 'Columns to extract from the image table', items=[]) utils.register_parameter( __name__, 'objects_db_columns', utils.PARAM_STRS, 'Columns to extract from the objects table', items=[]) utils.register_parameter( __name__, 'image_files_db_columns', utils.PARAM_STRS, 'File and Path columns in the image table', items=[]) utils.register_action(__name__, 'import_db', 'Import data from database', import_data_from_db) reload_db_schema() except: logger.error('Unable to connect to the database') raise return 'Successfully connected to database'
else: values = param_value for i, value in enumerate(values): if not os.path.isabs(value): values[i] = os.path.join(os.path.dirname(yaml_filename), value) if type(param_value) == str: return values[0] else: return values __dict__ = sys.modules[__name__].__dict__ utils.register_module(__name__, 'Data import', __dict__, utils.DEFAULT_STATE) utils.register_parameter(__name__, 'hdf5_input_file', utils.PARAM_INPUT_FILE, 'YACA HDF5 input file', optional=True) utils.set_parameter_hook(__name__, 'hdf5_input_file', filename_hook) utils.register_parameter(__name__, 'optional_hdf5_input_files', utils.PARAM_INPUT_FILES, 'Further YACA HDF5 input files', optional=True) utils.set_parameter_hook(__name__, 'optional_hdf5_input_files', filename_hook) utils.register_parameter(__name__, 'hdf5_output_file', utils.PARAM_OUTPUT_FILE, 'YACA HDF5 output file', optional=True) utils.set_parameter_hook(__name__, 'hdf5_output_file', filename_hook) utils.register_action(__name__, 'load_hdf5', 'Load data from a YACA HDF5 file', load_hdf5) utils.register_action(__name__, 'save_hdf5', 'Save data as YACA HDF5 file', save_hdf5) utils.register_action(__name__, 'normalize_intensities', 'Normalize intensity features to mean control cell intensity', normalize_intensities) utils.set_module_state_callback(__name__, set_state)
utils.update_state(importer.__name__, 'imported') print 'Finished importing data from database' return 'Finished importing data from database' __dict__ = sys.modules[__name__].__dict__ utils.register_module(__name__, 'Database import', __dict__, utils.DEFAULT_STATE) utils.register_parameter(__name__, 'database_url', utils.PARAM_STR, 'URL specifying a database', 'mysql://localhost/YACA') utils.register_action(__name__, 'connect_to_database', 'Connect to database', connect_to_database) utils.register_parameter( __name__, 'use_plate_filter', utils.PARAM_BOOL, 'Select plates to import?', False, hidden=True) utils.register_parameter( __name__, 'plate_filter', utils.PARAM_STRS, 'Plates to import from the database', optional=True, hidden=True, items=[]) utils.register_parameter( __name__, 'use_well_filter', utils.PARAM_BOOL, 'Select wells to import?', False, hidden=True) utils.register_parameter( __name__, 'well_filter', utils.PARAM_STRS, 'Wells to import from the database', optional=True, hidden=True, items=[])