def _get_top_level_agrlibval_steps(self): topLevel_AgrLibQC = {} for AgrLibQC_id, AgrLibQC_info in self.AgrLibQCs.items(): if AgrLibQC_info['samples'].has_key(self.name): topLevel_AgrLibQC[AgrLibQC_id] = [] inart, outart = AgrLibQC_info['samples'][ self.name].items()[0][1] history = gent.SampleHistory( sample_name=self.name, output_artifact=outart.id, input_artifact=inart.id, lims=self.lims, pro_per_art=self.processes_per_artifact) for inart in history.history_list: proc_info = history.history[inart] proc_info = filter( lambda p: (p['type'] in AGRLIBVAL.keys()), proc_info.values()) proc_ids = map(lambda p: p['id'], proc_info) topLevel_AgrLibQC[AgrLibQC_id] = topLevel_AgrLibQC[ AgrLibQC_id] + proc_ids for AgrLibQC, LibQC in topLevel_AgrLibQC.items(): LibQC = set(LibQC) if LibQC: for AgrLibQC_comp, LibQC_comp in topLevel_AgrLibQC.items(): if AgrLibQC_comp != AgrLibQC: LibQC_comp = set(LibQC_comp) if LibQC.issubset( LibQC_comp) and topLevel_AgrLibQC.has_key( AgrLibQC): topLevel_AgrLibQC.pop(AgrLibQC) return topLevel_AgrLibQC
def _get_preps_and_libval(self): """""" top_level_agrlibval_steps = self._get_top_level_agrlibval_steps() preps = {} very_last_libval_key = {} for AgrLibQC_id in top_level_agrlibval_steps.keys(): AgrLibQC_info = self.AgrLibQCs[AgrLibQC_id] if AgrLibQC_info['samples'].has_key(self.name): for inart in AgrLibQC_info['samples'][self.name].items(): inart, outart = inart[1] history = gent.SampleHistory( sample_name=self.name, output_artifact=outart.id, input_artifact=inart.id, lims=self.lims, pro_per_art=self.processes_per_artifact) steps = ProcessSpec(history.history, history.history_list, self.application) prep = Prep(self.name) prep.set_prep_info(steps, self.application) if not preps.has_key(prep.id2AB) and prep.id2AB: preps[prep.id2AB] = prep.prep_info if prep.pre_prep_library_validations and prep.id2AB: preps[ prep.id2AB]['pre_prep_library_validation'].update( prep.pre_prep_library_validations) if prep.library_validations and prep.id2AB: preps[prep.id2AB]['library_validation'].update( prep.library_validations) last_libval_key = max(prep.library_validations.keys()) last_libval = prep.library_validations[last_libval_key] in_last = very_last_libval_key.has_key(prep.id2AB) is_last = prep.id2AB in very_last_libval_key and ( last_libval_key > very_last_libval_key[prep.id2AB]) if is_last or not in_last: very_last_libval_key[prep.id2AB] = last_libval_key if last_libval.has_key('prep_status'): preps[prep.id2AB]['prep_status'] = last_libval[ 'prep_status'] preps[prep.id2AB][ 'reagent_label'] = self._pars_reagent_labels( steps, last_libval) if preps.has_key('Finished'): try: preps['Finished'][ 'reagent_label'] = self.lims_sample.artifact.reagent_labels[ 0] except IndexError: #P821 has nothing here logging.warn( "No reagent label for artifact {} in sample {}".format( self.lims_sample.artifact.id, self.name)) preps['Finished']['reagent_label'] = None preps['Finished'] = delete_Nones(preps['Finished']) return preps
def _get_initialqc_processes(self): outarts = self.lims.get_artifacts(sample_name = self.sample_name, process_type = AGRINITQC.values()) if outarts: outart = Artifact(self.lims, id = max(map(lambda a: a.id, outarts))) latestInitQc = outart.parent_process inart = latestInitQc.input_per_sample(self.sample_name)[0].id history = gent.SampleHistory(sample_name = self.sample_name, output_artifact = outart.id, input_artifact = inart, lims = self.lims, pro_per_art = self.processes_per_artifact) if history.history_list: self.steps = ProcessSpec(history.history, history.history_list, self.application)
def _get_sample_run_metrics(self, demux_info, preps): """Input: demux_info - instance of the ProcessInfo class with DEMULTIPLEX processes as argument For each SEQUENCING process run on the sample, this function steps bacward in the artifact history of the input artifact of the SEQUENCING process to find the folowing information: dillution_and_pooling_start_date date-run of DILSTART step sequencing_start_date date-run of SEQSTART step sequencing_run_QC_finished date-run of SEQUENCING step sequencing_finish_date udf ('Finish Date') of SEQUENCING step sample_run_metrics_id The sample database (statusdb) _id for the sample_run_metrics corresponding to the run, sample, lane in question. samp_run_met_id = lane_date_fcid_barcode date and fcid: from udf ('Run ID') of the SEQUENCING step. barcode: The reagent-lables of the input artifact of process type AGRLIBVAL lane: from the location of the input artifact to the SEQUENCING step preps are defined as the id of the PREPSTART step in the artifact history. If appllication== Finished library, prep is defined as "Finnished". These keys are used to connect the seqeuncing steps to the correct preps.""" sample_runs = {} for id, run in demux_info.items(): if run['samples'].has_key(self.name): for id, arts in run['samples'][self.name].items(): history = gent.SampleHistory( sample_name=self.name, output_artifact=arts[1].id, input_artifact=arts[0].id, lims=self.lims, pro_per_art=self.processes_per_artifact) steps = ProcessSpec(history.history, history.history_list, self.application) if self.application in ['Finished library', 'Amplicon']: key = 'Finished' elif steps.preprepstart: key = steps.preprepstart['id'] elif steps.prepstart: key = steps.prepstart['id'] else: key = None if key: lims_run = Process(lims, id=steps.lastseq['id']) run_dict = dict(lims_run.udf.items()) if preps[key].has_key( 'reagent_label') and run_dict.has_key( 'Finish Date'): dem_art = Artifact(lims, id=steps.latestdem['outart']) seq_art = Artifact(lims, id=steps.lastseq['inart']) lims_run = Process(lims, id=steps.lastseq['id']) samp_run_met_id = self._make_sample_run_id( seq_art, lims_run, preps[key], steps.lastseq['type']) if samp_run_met_id: srmi = find_sample_run_id_from_view( self.samp_db, samp_run_met_id) dpsd = steps.dilstart[ 'date'] if steps.dilstart else None ssd = steps.seqstart[ 'date'] if steps.seqstart else None sfd = lims_run.udf['Finish Date'].isoformat() d = { 'sample_run_metrics_id': srmi, 'dillution_and_pooling_start_date': dpsd, 'sequencing_start_date': ssd, 'sequencing_run_QC_finished': run['start_date'], 'sequencing_finish_date': sfd, 'dem_qc_flag': dem_art.qc_flag, 'seq_qc_flag': seq_art.qc_flag } d = delete_Nones(d) if not sample_runs.has_key(key): sample_runs[key] = {} sample_runs[key][samp_run_met_id] = d return sample_runs