class App(object): def __init__(self, host, user, passwd, study_label, maker, model, release): self.kb = KB(driver='omero')(host, user, passwd) self.mset = self.kb.get_snp_markers_set(maker, model, release) self.logger = logging.getLogger() if not self.mset: raise ValueError('SNPMarkersSet[%s,%s,%s] has not been defined.' % (maker, model, release)) #-- alabel = 'load_genotypes-setup-%s' % time.time() self.asetup = self.kb.factory.create(self.kb.ActionSetup, {'label' : alabel, 'conf' : ''}).save() #-- dmaker, dmodel, drelease = 'CRS4', 'load_genotypes', '0.1' dlabel = '%s-%s-%s' % (dmaker, dmodel, drelease) device = self.kb.get_device(dlabel) if not device: device = self.kb.factory.create(self.kb.Device, {'label' : dlabel, 'maker' : dmaker, 'model' : dmodel, 'release' : drelease}).save() self.device = device #-- FIXME this will break if study is not defined. self.study = self.kb.get_study(study_label) def check_snp_markers_set(self, marker_types, marker_names): self.logger.info('start checking snp_markers_set') mdefs, msetc = self.kb.get_snp_markers_set_content(self.mset) rs_labels = mdefs['rs_label'] for t, n in it.izip(marker_types, marker_names): if t == 'M': if not n in rs_labels: msg = 'marker %s is not in the specified SNPMarkersSet' % n self.logger.critical(msg) raise ValueError(msg) self.logger.info('done checking snp_markers_set') def create_action(self, target): conf = {'setup' : self.asetup, 'device' : self.device, 'actionCategory' : self.kb.ActionCategory.MEASUREMENT, 'operator' : 'Alfred E. Neumann', 'context' : self.study, 'target' : target, } action = self.kb.factory.create(self.kb.ActionOnVessel, conf).save() return action def create_data_sample(self, action, label): conf = {'snpMarkersSet' : self.mset, 'label' : label, 'status' : self.kb.DataSampleStatus.USABLE, 'action' : action} return self.kb.factory.create(self.kb.GenotypeDataSample, conf).save() def load(self, pedfile, datfile, conf_value=1.0): pr = PedReader(pedfile, datfile, conf_value) self.check_snp_markers_set(pr.marker_types, pr.marker_names) #-- self.logger.info('start loading from pedfile %s' % pedfile.name) for x in pr: sample = self.kb.get_vessel(x['sample_label']) if not sample: self.logger.error('No sample with label %s in VL' % x['sample_label']) continue action = self.create_action(sample) avid = action.id action.unload() data_sample = self.create_data_sample(action, x['label']) data_object = self.kb.add_gdo_data_object(avid, data_sample, x['probs'], x['confs']) self.logger.info('-- loaded %s' % x['label']) self.logger.info('done loading from pedfile %s' % pedfile.name)
class App(object): def __init__(self, host, user, passwd, study_label, maker, model, release): self.kb = KB(driver='omero')(host, user, passwd) self.mset = self.kb.get_snp_markers_set(maker, model, release) self.logger = logging.getLogger() if not self.mset: raise ValueError('SNPMarkersSet[%s,%s,%s] has not been defined.' % (maker, model, release)) #-- alabel = 'load_genotypes-setup-%s' % time.time() self.asetup = self.kb.factory.create(self.kb.ActionSetup, { 'label': alabel, 'conf': '' }).save() #-- dmaker, dmodel, drelease = 'CRS4', 'load_genotypes', '0.1' dlabel = '%s-%s-%s' % (dmaker, dmodel, drelease) device = self.kb.get_device(dlabel) if not device: device = self.kb.factory.create( self.kb.Device, { 'label': dlabel, 'maker': dmaker, 'model': dmodel, 'release': drelease }).save() self.device = device #-- FIXME this will break if study is not defined. self.study = self.kb.get_study(study_label) def check_snp_markers_set(self, marker_types, marker_names): self.logger.info('start checking snp_markers_set') mdefs, msetc = self.kb.get_snp_markers_set_content(self.mset) rs_labels = mdefs['rs_label'] for t, n in it.izip(marker_types, marker_names): if t == 'M': if not n in rs_labels: msg = 'marker %s is not in the specified SNPMarkersSet' % n self.logger.critical(msg) raise ValueError(msg) self.logger.info('done checking snp_markers_set') def create_action(self, target): conf = { 'setup': self.asetup, 'device': self.device, 'actionCategory': self.kb.ActionCategory.MEASUREMENT, 'operator': 'Alfred E. Neumann', 'context': self.study, 'target': target, } action = self.kb.factory.create(self.kb.ActionOnVessel, conf).save() return action def create_data_sample(self, action, label): conf = { 'snpMarkersSet': self.mset, 'label': label, 'status': self.kb.DataSampleStatus.USABLE, 'action': action } return self.kb.factory.create(self.kb.GenotypeDataSample, conf).save() def load(self, pedfile, datfile, conf_value=1.0): pr = PedReader(pedfile, datfile, conf_value) self.check_snp_markers_set(pr.marker_types, pr.marker_names) #-- self.logger.info('start loading from pedfile %s' % pedfile.name) for x in pr: sample = self.kb.get_vessel(x['sample_label']) if not sample: self.logger.error('No sample with label %s in VL' % x['sample_label']) continue action = self.create_action(sample) avid = action.id action.unload() data_sample = self.create_data_sample(action, x['label']) data_object = self.kb.add_gdo_data_object(avid, data_sample, x['probs'], x['confs']) self.logger.info('-- loaded %s' % x['label']) self.logger.info('done loading from pedfile %s' % pedfile.name)