def create_document(row, test=False): # Creates and returns a Genotype document from the values in the row db_alias = TEST_DB_ALIAS if test else 'default' build_dic = {} for key in row: if 'date' == key[-4:] or key == 'dtt': # Assumes values ending in 'date' are for date fields build_dic[key] = datetime.strptime(row[key], "%Y-%m-%d %H:%M:%S.%f") # Searches through the other collections for the reference field values elif 'datasource' in key: with switch_db(DataSource, db_alias) as TestDat: datasource, created = fetch_or_save(TestDat, db_alias=db_alias, name=row[key]) build_dic['datasource'] = datasource elif 'study' in key: with switch_db(Experiment, db_alias) as TestEx: study, created = fetch_or_save(TestEx, db_alias=db_alias, name=row[key]) build_dic['study'] = study elif key == 'obs': # Extracts the dictionary from the obs field build_dic[key] = ast.literal_eval(row[key]) else: build_dic[key] = row[key] with switch_db(Genotype, db_alias) as TestGen: gen, created = fetch_or_save(TestGen, db_alias=db_alias, **build_dic) return gen
def create_document(row, test=False): # Creates and returns a Genotype document from the values in the row db_alias = TEST_DB_ALIAS if test else 'default' build_dic = {} for key in row: if 'date' == key[-4:] or key == 'dtt': # Assumes values ending in 'date' are for date fields build_dic[key] = datetime.strptime(row[key], "%Y-%m-%d %H:%M:%S.%f") # Searches through the other collections for the reference field values elif 'datasource' in key: with switch_db(DataSource, db_alias) as TestDat: datasource, created = fetch_or_save( TestDat, db_alias=db_alias, name=row[key] ) build_dic['datasource'] = datasource elif 'study' in key: with switch_db(Experiment, db_alias) as TestEx: study, created = fetch_or_save( TestEx, db_alias=db_alias, name=row[key] ) build_dic['study'] = study elif key == 'obs': # Extracts the dictionary from the obs field build_dic[key] = ast.literal_eval(row[key]) else: build_dic[key] = row[key] with switch_db(Genotype, db_alias) as TestGen: gen, created = fetch_or_save(TestGen, db_alias=db_alias, **build_dic) return gen
def init(fn): dt = datetime.datetime.now() ds, created = fetch_or_save( DataSource, name='Import Kiwifruit Ach', supplieddate=dt, supplier='John McCallum', typ="CSV", source=fn, ) st, created = fetch_or_save(Experiment, name='Kiwifruit Ach') Import.study = st Import.ds = ds
def init(fn): dt = datetime.datetime.now() ds, created = fetch_or_save( DataSource, name='Import Kiwifruit Ach', supplieddate=dt, supplier='John McCallum', typ="CSV", source=fn, ) st, created = fetch_or_save( Experiment, name='Kiwifruit Ach' ) Import.study = st Import.ds = ds
def init(fn): dt = datetime.datetime.now() ds, created = fetch_or_save( DataSource, name='Import Kiwifruit East12', supplieddate=dt, supplier='John McCallum', typ="CSV", source=fn, ) st, created = fetch_or_save(Experiment, name='Kiwifruit 12East') Import.study = st if ds is None: raise ValueError("None Type: " + fn + " created a None datasource") if not isinstance(ds, Document): raise TypeError("Wrong type of datasouce: " + str(type(ds))) Import.ds = ds
def init(fn, experi_name, supplier, fruit): dt = datetime.datetime.now() if fruit: name_used = fruit + ' ' + experi_name else: name_used = experi_name ds, created = fetch_or_save( DataSource, name='Import ' + name_used, supplieddate=dt, supplier=supplier, typ="CSV", source=fn, ) st, created = fetch_or_save(Experiment, name=name_used) Import.study = st Import.ds = ds
def init_file(file_path, build_dic): posix_path = file_path.as_posix() build_dic['source'] = posix_path with switch_db(DataSource, db_alias) as DatS: ds, created = fetch_or_save(DatS, db_alias=db_alias, **make_field_dic(DatS, build_dic)) if created: # add to record of docs saved to db by this run through created_doc_ids.append((DataSource, ds.id)) ds.supplier = build_dic["pi"] ds.group = build_dic["Experiment Code"] ds.save() return ds
def init(fn): dt = datetime.datetime.now() ds, created = fetch_or_save( DataSource, name='Import Kiwifruit East12', supplieddate=dt, supplier='John McCallum', typ="CSV", source=fn, ) st, created = fetch_or_save( Experiment, name='Kiwifruit 12East' ) Import.study = st if ds is None: raise ValueError("None Type: " + fn + " created a None datasource") if not isinstance(ds, Document): raise TypeError("Wrong type of datasouce: " + str(type(ds))) Import.ds = ds
def create_document(row, test=False): # Creates and returns an experiment document from the values in the row name = row['name'] pi = row['pi'] creator = row['createdby'] when = string_to_datetime(row['createddate']) descr = row['description'] db_alias = TEST_DB_ALIAS if test else 'default' with switch_db(Experiment, db_alias) as TestEx: experi, created = fetch_or_save( TestEx, db_alias=db_alias, name=name, createddate=when, pi=pi, createdby=creator, description=descr ) return experi
def create_document(row, test=False): # Creates and returns a Datasource document from the values in the row supplieddate = datetime.strptime(row['supplieddate'], "%Y-%m-%d").date() name = row['name'] typ = row['typ'] source = row['source'] supplier = row['supplier'] comment = row['comment'] is_active = row['is_active'] == 'True' db_alias = TEST_DB_ALIAS if test else 'default' with switch_db(DataSource, db_alias) as TestDs: ds, created = fetch_or_save( TestDs, db_alias=db_alias, name=name, source=source, supplieddate=supplieddate, typ=typ, supplier=supplier, comment=comment, is_active=is_active ) return ds
def create_document(row, test=False): # Creates and returns an experiment document from the values in the row name = row['name'] pi = row['pi'] creator = row['createdby'] when = string_to_datetime(row['createddate']) descr = row['description'] db_alias = TEST_DB_ALIAS if test else 'default' with switch_db(Experiment, db_alias) as TestEx: experi, created = fetch_or_save(TestEx, db_alias=db_alias, name=name, createddate=when, pi=pi, createdby=creator, description=descr) return experi
def init_for_all(path, config_dic): # Gets the name for the experiment and data_source documents from the directory name posix_path = path.as_posix() dir_list = posix_path.split("/") name = config_dic["Experiment Code"] # creates the dictionary to use for keyword args to fetch or save documents with build_dic = config_dic_to_build_dic(config_dic) build_dic['name'] = name build_dic['realm'] = build_dic['Realm'] with switch_db(Experiment, db_alias) as Exper: ex, created = fetch_or_save(Exper, db_alias=db_alias, **make_field_dic(Exper, build_dic)) if created: # add to record of docs saved to db by this run through created_doc_ids.append((Experiment, ex.id)) Logger.Error("Experiment: " + name + " loaded.") return build_dic, ex
def create_document(row, test=False): # Creates and returns a Datasource document from the values in the row supplieddate = datetime.strptime(row['supplieddate'], "%Y-%m-%d").date() name = row['name'] typ = row['typ'] source = row['source'] supplier = row['supplier'] comment = row['comment'] is_active = row['is_active'] == 'True' db_alias = TEST_DB_ALIAS if test else 'default' with switch_db(DataSource, db_alias) as TestDs: ds, created = fetch_or_save(TestDs, db_alias=db_alias, name=name, source=source, supplieddate=supplieddate, typ=typ, supplier=supplier, comment=comment, is_active=is_active) return ds