def get_template_data_for_export(templateId): ''' generates data for template export to CSV file ''' template = PlannedExperiment.objects.get(pk=int(templateId)) name = "exported " + getPlanDisplayedName(template).strip() runType = RunType.objects.get(runType=template.runType) data = [ ( PlanCSVcolumns.TEMPLATE_NAME, name[:MAX_LENGTH_PLAN_NAME]), ( PlanCSVcolumns.FAVORITE, template.isFavorite ), ( PlanCSVcolumns.APPLICATION, template.applicationGroup.description if template.applicationGroup else '' ), ( PlanCSVcolumns.RUNTYPE, runType.alternate_name ), ( PlanCSVcolumns.SAMPLE_GROUP, template.sampleGrouping.displayedName if template.sampleGrouping else '' ), ( PlanCSVcolumns.BARCODE_SET, template.get_barcodeId() ), ( PlanCSVcolumns.COLUMN_CHIP_TYPE, _get_chip_type_description(template) ), ( PlanCSVcolumns.COLUMN_SAMPLE_PREP_KIT, _get_sample_prep_kit_description(template) ), ( PlanCSVcolumns.COLUMN_LIBRARY_KIT, _get_lib_kit_description(template) ), ( PlanCSVcolumns.LIBRARY_KEY, template.get_libraryKey() ), ( PlanCSVcolumns.TF_KEY, template.get_tfKey() ), ( PlanCSVcolumns.THREEPRIME_ADAPTER, template.get_forward3primeadapter() ), ( PlanCSVcolumns.FLOW_ORDER, template.experiment.flowsInOrder or "default" ), ( PlanCSVcolumns.COLUMN_TEMPLATING_KIT, _get_template_kit_description(template) ), ( PlanCSVcolumns.COLUMN_TEMPLATING_SIZE, _get_templating_size(template) ), ( PlanCSVcolumns.COLUMN_SEQ_KIT, _get_seq_kit_description(template) ), ( PlanCSVcolumns.COLUMN_CONTROL_SEQ_KIT, _get_control_seq_kit_description(template) ), ( PlanCSVcolumns.COLUMN_LIBRARY_READ_LENGTH, _get_library_read_length(template) ), ( PlanCSVcolumns.CALIBRATION_MODE, template.latestEAS.base_recalibration_mode ), ( PlanCSVcolumns.MARK_DUPLICATES, template.latestEAS.isDuplicateReads ), ( PlanCSVcolumns.REALIGN, template.latestEAS.realign ), ( PlanCSVcolumns.COLUMN_FLOW_COUNT, template.get_flows() ), ( PlanCSVcolumns.COLUMN_REF, _get_reference(template) ), ( PlanCSVcolumns.COLUMN_TARGET_BED, _get_target_regions_bed_file(template) ), ( PlanCSVcolumns.COLUMN_HOTSPOT_BED,_get_hotspot_regions_bed_file(template) ) ] # add fusions reference for DNA/Fusions application if runType.runType == 'AMPS_DNA_RNA': data.extend([ ( PlanCSVcolumns.FUSIONS_REF, template.get_mixedType_rna_library() ), ( PlanCSVcolumns.FUSIONS_TARGET_BED, _get_fusions_target_regions_bed_file(template) ) ]) data.extend([ ( PlanCSVcolumns.COLUMN_BEAD_LOAD_PCT, _get_bead_loading_qc(template) ), ( PlanCSVcolumns.COLUMN_KEY_SIGNAL_PCT, _get_key_signal_qc(template) ), ( PlanCSVcolumns.COLUMN_USABLE_SEQ_PCT, _get_usable_seq_qc(template) ), ( PlanCSVcolumns.COLUMN_PLUGINS, _get_plugins(template, TOKEN_DELIMITER) ), ( PlanCSVcolumns.COLUMN_PROJECTS, _get_projects(template, TOKEN_DELIMITER) ), ( PlanCSVcolumns.CATEGORIES, template.categories ), ( PlanCSVcolumns.COLUMN_NOTES, _get_notes(template) ), ( PlanCSVcolumns.COLUMN_LIMS_DATA, _get_LIMS_data(template) ), ]) # add custom analysis args if template.latestEAS.custom_args: args = template.latestEAS.get_cmdline_args() data.append((PlanCSVcolumns.CUSTOM_ARGS, True)) data.extend([(key, args[key]) for key in sorted(args)]) return zip(*data)
def get_template_data_for_export(templateId): ''' generates data for template export to CSV file ''' template = PlannedExperiment.objects.get(pk=int(templateId)) name = "exported " + getPlanDisplayedName(template).strip() runType = RunType.objects.get(runType=template.runType) data = [ ( PlanCSVcolumns.TEMPLATE_NAME, name[:MAX_LENGTH_PLAN_NAME]), ( PlanCSVcolumns.FAVORITE, template.isFavorite ), ( PlanCSVcolumns.APPLICATION, template.applicationGroup.description if template.applicationGroup else '' ), ( PlanCSVcolumns.RUNTYPE, runType.alternate_name ), ( PlanCSVcolumns.SAMPLE_GROUP, template.sampleGrouping.displayedName if template.sampleGrouping else '' ), ( PlanCSVcolumns.BARCODE_SET, template.get_barcodeId() ), ( PlanCSVcolumns.COLUMN_CHIP_TYPE, _get_chip_type_description(template) ), ( PlanCSVcolumns.COLUMN_SAMPLE_PREP_KIT, _get_sample_prep_kit_description(template) ), ( PlanCSVcolumns.COLUMN_LIBRARY_KIT, _get_lib_kit_description(template) ), ( PlanCSVcolumns.LIBRARY_KEY, template.get_libraryKey() ), ( PlanCSVcolumns.TF_KEY, template.get_tfKey() ), ( PlanCSVcolumns.THREEPRIME_ADAPTER, template.get_forward3primeadapter() ), ( PlanCSVcolumns.FLOW_ORDER, template.experiment.flowsInOrder or "default" ), ( PlanCSVcolumns.COLUMN_TEMPLATING_KIT, _get_template_kit_description(template) ), ( PlanCSVcolumns.COLUMN_TEMPLATING_SIZE, _get_templating_size(template) ), ( PlanCSVcolumns.COLUMN_SEQ_KIT, _get_seq_kit_description(template) ), ( PlanCSVcolumns.COLUMN_CONTROL_SEQ_KIT, _get_control_seq_kit_description(template) ), ( PlanCSVcolumns.COLUMN_LIBRARY_READ_LENGTH, _get_library_read_length(template) ), ( PlanCSVcolumns.CALIBRATION_MODE, template.latestEAS.base_recalibration_mode ), ( PlanCSVcolumns.MARK_DUPLICATES, template.latestEAS.isDuplicateReads ), ( PlanCSVcolumns.REALIGN, template.latestEAS.realign ), ( PlanCSVcolumns.COLUMN_FLOW_COUNT, template.get_flows() ), ( PlanCSVcolumns.COLUMN_REF, _get_reference(template) ), ( PlanCSVcolumns.COLUMN_TARGET_BED, _get_target_regions_bed_file(template) ), ( PlanCSVcolumns.COLUMN_HOTSPOT_BED,_get_hotspot_regions_bed_file(template) ) ] # add fusions reference for DNA/Fusions application if runType.runType == 'AMPS_DNA_RNA': data.extend([ ( PlanCSVcolumns.FUSIONS_REF, template.get_mixedType_rna_library() ), ( PlanCSVcolumns.FUSIONS_TARGET_BED, _get_fusions_target_regions_bed_file(template) ) ]) data.extend([ ( PlanCSVcolumns.COLUMN_BEAD_LOAD_PCT, _get_bead_loading_qc(template) ), ( PlanCSVcolumns.COLUMN_KEY_SIGNAL_PCT, _get_key_signal_qc(template) ), ( PlanCSVcolumns.COLUMN_USABLE_SEQ_PCT, _get_usable_seq_qc(template) ), ( PlanCSVcolumns.COLUMN_PLUGINS, _get_plugins(template, TOKEN_DELIMITER) ), ( PlanCSVcolumns.COLUMN_PROJECTS, _get_projects(template, TOKEN_DELIMITER) ), ( PlanCSVcolumns.CATEGORIES, template.categories ), ( PlanCSVcolumns.COLUMN_NOTES, _get_notes(template) ), ( PlanCSVcolumns.COLUMN_LIMS_DATA, _get_LIMS_data(template) ), ]) # add custom analysis args if template.latestEAS.custom_args: args = template.latestEAS.get_cmdline_args() data.append((PlanCSVcolumns.CUSTOM_ARGS, True)) data.extend([(key, args[key]) for key in sorted(args)]) return zip(*data)
def get_template_data_for_batch_planning(templateId, single_samples_file): try: template = PlannedExperiment.objects.get(pk=int(templateId)) logger.info("plan_csv_writer.get_template_data_for_batch_planning() template retrieved. id=%d;" % (int(templateId))) hdr = [PlanCSVcolumns.COLUMN_TEMPLATE_NAME, PlanCSVcolumns.COLUMN_PLAN_NAME ] hdr2 = [PlanCSVcolumns.COLUMN_SAMPLE_PREP_KIT, PlanCSVcolumns.COLUMN_LIBRARY_KIT, PlanCSVcolumns.COLUMN_TEMPLATING_KIT, PlanCSVcolumns.COLUMN_TEMPLATING_SIZE, PlanCSVcolumns.COLUMN_CONTROL_SEQ_KIT, PlanCSVcolumns.COLUMN_SEQ_KIT, PlanCSVcolumns.COLUMN_CHIP_TYPE, PlanCSVcolumns.COLUMN_LIBRARY_READ_LENGTH, PlanCSVcolumns.COLUMN_FLOW_COUNT, PlanCSVcolumns.COLUMN_SAMPLE_TUBE_LABEL, PlanCSVcolumns.COLUMN_BEAD_LOAD_PCT, PlanCSVcolumns.COLUMN_KEY_SIGNAL_PCT, PlanCSVcolumns.COLUMN_USABLE_SEQ_PCT, PlanCSVcolumns.COLUMN_REF, PlanCSVcolumns.COLUMN_TARGET_BED, PlanCSVcolumns.COLUMN_HOTSPOT_BED, PlanCSVcolumns.COLUMN_PLUGINS, PlanCSVcolumns.COLUMN_PROJECTS, PlanCSVcolumns.COLUMN_EXPORT, PlanCSVcolumns.COLUMN_NOTES, PlanCSVcolumns.COLUMN_LIMS_DATA, PlanCSVcolumns.COLUMN_CHIP_BARCODE ] body = [getPlanDisplayedName(template), "" ] body2 = [_get_sample_prep_kit_description(template), _get_lib_kit_description(template), _get_template_kit_description(template), _get_templating_size(template), _get_control_seq_kit_description(template), _get_seq_kit_description(template), _get_chip_type_description(template), _get_library_read_length(template), _get_flow_count(template), _get_sample_tube_label(template), _get_bead_loading_qc(template), _get_key_signal_qc(template), _get_usable_seq_qc(template), _get_reference(template), _get_target_regions_bed_file(template), _get_hotspot_regions_bed_file(template), _get_plugins(template, ";"), _get_projects(template, ";"), _get_export(template, ";"), _get_notes(template), _get_LIMS_data(template) ] # position of the fields below are based on the template selected and whether IR has been installed on the TS if _has_ir_v1_0(template): hdr2.append(PlanCSVcolumns.COLUMN_IR_V1_0_WORKFLOW) body2.append("") # has_ir_beyond_v1_0 = _has_ir_beyond_v1_0(template) if _is_barcoded(template): if single_samples_file: hdr.extend(_get_barcoded_sample_headers(template, PlanCSVcolumns.COLUMN_BC_SAMPLE_KEY)) body.extend(_get_barcoded_sample_names(template)) # if has_ir_beyond_v1_0: # hdr.extend(_get_barcoded_sample_IR_beyond_v1_0_headers(template, PlanCSVcolumns.COLUMN_BC_SAMPLE_KEY, )) # body.extend(_get_barcoded_sample_IR_beyond_v1_0_workflows(template)) else: hdr.append(PlanCSVcolumns.COLUMN_SAMPLE_FILE_HEADER) body.append("") else: hdr.append(PlanCSVcolumns.COLUMN_SAMPLE) body.append(_get_sample_name(template)) hdr.append(PlanCSVcolumns.COLUMN_SAMPLE_ID) body.append(_get_sample_id(template)) # if has_ir_beyond_v1_0: # hdr.append(PlanCSVcolumns.COLUMN_IR_V1_X_WORKFLOW) # body.append(_get_sample_IR_beyond_v1_0_workflows(template)) hdr.extend(hdr2) body.extend(body2) return hdr, body except: logger.exception(format_exc()) return [], [], []
def updateTemplateSpecificStepHelper(self, step_helper, planned_experiment): ''' Updates the template specific step helper with template specific info from the planned experiment. ''' save_template_step_data = step_helper.steps[StepNames.SAVE_TEMPLATE] planDisplayedName = getPlanDisplayedName(planned_experiment) if step_helper.sh_type == StepHelperType.COPY_TEMPLATE: save_template_step_data.savedFields['templateName'] = "Copy of " + planDisplayedName else: save_template_step_data.savedFields['templateName'] = planDisplayedName save_template_step_data.savedFields['setAsFavorite'] = planned_experiment.isFavorite
def getStepHelperForTemplatePlannedExperiment(self, pe_id, step_helper_type=StepHelperType.EDIT_TEMPLATE, sampleset_id=None): ''' Get a step helper from a template planned experiment. ''' step_helper = StepHelper(sh_type=step_helper_type, previous_template_id=pe_id) planned_experiment = PlannedExperiment.objects.get(pk=pe_id) if not planned_experiment.isReusable: raise ValueError("You must pass in a template id, not a plan id.") planDisplayedName = getPlanDisplayedName(planned_experiment) step_helper.parentName = planDisplayedName self.updateUniversalStepHelper(step_helper, planned_experiment) if step_helper.isPlan() and step_helper.isPlanBySample(): self.updatePlanBySampleSpecificStepHelper(step_helper, planned_experiment, sampleset_id) elif step_helper.isPlan(): self.updatePlanSpecificStepHelper(step_helper, planned_experiment, True) else: self.updateTemplateSpecificStepHelper(step_helper, planned_experiment) return step_helper
def getStepHelperForPlanPlannedExperiment(self, pe_id, step_helper_type=StepHelperType.EDIT_PLAN): ''' Get a plan step helper from a plan planned experiment. ''' step_helper = StepHelper(sh_type=step_helper_type, previous_plan_id=pe_id) planned_experiment = PlannedExperiment.objects.get(pk=pe_id) planDisplayedName = getPlanDisplayedName(planned_experiment) step_helper.parentName = planDisplayedName if planned_experiment.isReusable: raise ValueError("You must pass in a plan id, not a template id.") self.updateUniversalStepHelper(step_helper, planned_experiment) if step_helper.isPlan() and step_helper.isPlanBySample(): self.updatePlanBySampleSpecificStepHelper(step_helper, planned_experiment, planned_experiment.sampleSet.pk) elif step_helper.isPlan(): self.updatePlanSpecificStepHelper(step_helper, planned_experiment) else: raise ValueError("Can not create templates from plans.") return step_helper
def get_template_data_for_batch_planning(templateId): try: template = PlannedExperiment.objects.get(pk = int(templateId)) logger.info("plan_csv_writer.get_template_data_for_batch_planning() template retrieved. id=%d;" %(int(templateId))) hdr = [ COLUMN_TEMPLATE_NAME , COLUMN_PLAN_NAME ] hdr2 = [ COLUMN_SAMPLE_PREP_KIT , COLUMN_LIBRARY_KIT , COLUMN_TEMPLATING_KIT , COLUMN_TEMPLATING_SIZE , COLUMN_CONTROL_SEQ_KIT , COLUMN_SEQ_KIT , COLUMN_CHIP_TYPE , COLUMN_LIBRARY_READ_LENGTH , COLUMN_FLOW_COUNT , COLUMN_SAMPLE_TUBE_LABEL , COLUMN_BEAD_LOAD_PCT , COLUMN_KEY_SIGNAL_PCT , COLUMN_USABLE_SEQ_PCT , COLUMN_REF , COLUMN_TARGET_BED , COLUMN_HOTSPOT_BED , COLUMN_PLUGINS , COLUMN_PROJECTS , COLUMN_EXPORT , COLUMN_NOTES , COLUMN_LIMS_DATA ] body = [ getPlanDisplayedName(template) , "" ] body2 = [_get_sample_prep_kit_description(template) , _get_lib_kit_description(template) , _get_template_kit_description(template) , _get_templating_size(template) , _get_control_seq_kit_description(template) , _get_seq_kit_description(template) , _get_chip_type_description(template) , _get_library_read_length(template) , _get_flow_count(template) , _get_sample_tube_label(template) , _get_bead_loading_qc(template) , _get_key_signal_qc(template) , _get_usable_seq_qc(template) , _get_reference(template) , _get_target_regions_bed_file(template) , _get_hotspot_regions_bed_file(template) , _get_plugins(template, ";") , _get_projects(template, ";") , _get_export(template, ";") , _get_notes(template) , _get_LIMS_data(template) ] #position of the fields below are based on the template selected and whether IR has been installed on the TS if _has_ir_v1_0(template): hdr2.append(COLUMN_IR_V1_0_WORKFLOW) body2.append("") #has_ir_beyond_v1_0 = _has_ir_beyond_v1_0(template) if _is_barcoded(template): hdr.extend(_get_barcoded_sample_headers(template, COLUMN_BC_SAMPLE_KEY)) body.extend(_get_barcoded_sample_names(template)) #if has_ir_beyond_v1_0: # hdr.extend(_get_barcoded_sample_IR_beyond_v1_0_headers(template, COLUMN_BC_SAMPLE_KEY, )) # body.extend(_get_barcoded_sample_IR_beyond_v1_0_workflows(template)) else: hdr.append(COLUMN_SAMPLE) body.append(_get_sample_name(template)) hdr.append(COLUMN_SAMPLE_ID) body.append(_get_sample_id(template)) #if has_ir_beyond_v1_0: # hdr.append(COLUMN_IR_V1_X_WORKFLOW) # body.append(_get_sample_IR_beyond_v1_0_workflows(template)) hdr.extend(hdr2) body.extend(body2) return hdr, body except: logger.exception(format_exc()) return [], [], []
def updatePlanSpecificStepHelper(self, step_helper, planned_experiment, set_template_name=False): ''' Updates the plan specific step helper with plan specific info from the planned experiment. If the planned experiment is a template and you'd like the originating template name to show up in the save plan page pass in set_template_name=True ''' planDisplayedName = getPlanDisplayedName(planned_experiment) if set_template_name: step_helper.steps[StepNames.SAVE_TEMPLATE].savedFields['templateName'] = planDisplayedName save_plan_step_data = step_helper.steps[StepNames.SAVE_PLAN] kits_step_data = step_helper.steps[StepNames.KITS] #Add a "copy of" if we're copying. if step_helper.isCopy(): save_plan_step_data.savedFields['planName'] = "Copy of " + planDisplayedName else: save_plan_step_data.savedFields['planName'] = planDisplayedName save_plan_step_data.savedFields['note'] = planned_experiment.get_notes() if step_helper.isBarcoded(): save_plan_step_data.prepopulatedFields['prevBarcodeId'] = kits_step_data.savedFields['barcodeId'] save_plan_step_data.prepopulatedFields['barcodes'] = list(dnaBarcode.objects.filter(name=kits_step_data.savedFields['barcodeId']).order_by('name', 'index')) barcodeToIrValues = None #build a barcodeid to ir info dict for plugin_name, plugin_dict in planned_experiment.get_selectedPlugins().items(): if 'IonReporter' in plugin_name: try: plugin = Plugin.objects.filter(name=plugin_name, active=True)[0] except: continue barcodeToIrValues = {} save_plan_step_data.prepopulatedFields['selectedIr'] = plugin save_plan_step_data.prepopulatedFields['irConfigJson'] = json.dumps(plugin.userinputfields) if PluginFieldNames.USER_INPUT in plugin_dict: #Handle the old and the new style userinput in the plugin dictionary if isinstance(plugin_dict[PluginFieldNames.USER_INPUT], dict)\ and "userInputInfo" in plugin_dict[PluginFieldNames.USER_INPUT]\ and len(plugin_dict[PluginFieldNames.USER_INPUT]["userInputInfo"]) > 0: for valueDict in plugin_dict[PluginFieldNames.USER_INPUT]["userInputInfo"]: barcodeToIrValues[valueDict['barcodeId']] = valueDict save_plan_step_data.prepopulatedFields['setid_suffix'] = valueDict['setid'][valueDict['setid'].find('__'):] elif isinstance(plugin_dict[PluginFieldNames.USER_INPUT], list): for valueDict in plugin_dict[PluginFieldNames.USER_INPUT]: barcodeToIrValues[valueDict['barcodeId']] = valueDict #build a sample to barcode dict sample_to_barcode = planned_experiment.get_barcodedSamples() barcodeIdStrToSample = {} for sample, value in sample_to_barcode.items(): if 'barcodeSampleInfo' in value: barcodeSampleInfo = value['barcodeSampleInfo'] for barcode, sampleInfo in barcodeSampleInfo.items(): barcodeIdStrToSample[barcode] = {"sampleName": sample} barcodeIdStrToSample[barcode].update(sampleInfo) else: barcodeIdStrList = value['barcodes'] for barcodeIdStr in barcodeIdStrList: barcodeIdStrToSample[barcodeIdStr] = {"sampleName": sample, "externalId": None, "description": None} #for each barcode populate the sample and ir info for barcode in save_plan_step_data.prepopulatedFields['barcodes']: if barcode.id_str in barcodeIdStrToSample: save_plan_step_data.savedFields['barcodeSampleName%s' % str(barcode.pk)] = barcodeIdStrToSample[barcode.id_str]["sampleName"] save_plan_step_data.savedFields['barcodeSampleExternalId%s' % str(barcode.pk)] = barcodeIdStrToSample[barcode.id_str]["externalId"] save_plan_step_data.savedFields['barcodeSampleDescription%s' % str(barcode.pk)] = barcodeIdStrToSample[barcode.id_str]["description"] if barcodeToIrValues: save_plan_step_data.savedFields['irGender%s' % str(barcode.pk)] = barcodeToIrValues[barcode.id_str]['Gender'] save_plan_step_data.savedFields['irWorkflow%s' % str(barcode.pk)] = barcodeToIrValues[barcode.id_str]['Workflow'] #some older plans do not have "Relation" specified - could be due to work-in-progress development code save_plan_step_data.savedFields['irRelation%s' % str(barcode.pk)] = barcodeToIrValues[barcode.id_str].get('Relation', "") save_plan_step_data.savedFields['irRelationRole%s' % str(barcode.pk)] = barcodeToIrValues[barcode.id_str]['RelationRole'] save_plan_step_data.savedFields['irSetID%s' % str(barcode.pk)] = barcodeToIrValues[barcode.id_str]['setid'][0:barcodeToIrValues[barcode.id_str]['setid'].find('__')] if barcodeToIrValues[barcode.id_str]['setid'] else "" else: save_plan_step_data.savedFields['irGender%s' % str(barcode.pk)] = None save_plan_step_data.savedFields['irWorkflow%s' % str(barcode.pk)] = None save_plan_step_data.savedFields['irRelation%s' % str(barcode.pk)] = None save_plan_step_data.savedFields['irRelationRole%s' % str(barcode.pk)] = None save_plan_step_data.savedFields['irSetID%s' % str(barcode.pk)] = None else: save_plan_step_data.savedFields['barcodeSampleName%s' % str(barcode.pk)] = None save_plan_step_data.savedFields['barcodeSampleExternalId%s' % str(barcode.pk)] = None save_plan_step_data.savedFields['barcodeSampleDescription%s' % str(barcode.pk)] = None save_plan_step_data.savedFields['irGender%s' % str(barcode.pk)] = None save_plan_step_data.savedFields['irWorkflow%s' % str(barcode.pk)] = None save_plan_step_data.savedFields['irRelation%s' % str(barcode.pk)] = None save_plan_step_data.savedFields['irRelationRole%s' % str(barcode.pk)] = None save_plan_step_data.savedFields['irSetID%s' % str(barcode.pk)] = None #do not copy sampleTubeLabel since a sample tube is meant for 1 run only save_plan_step_data.savedFields['barcodeSampleTubeLabel'] = "" if step_helper.isCopy() else planned_experiment.sampleTubeLabel else: #when we load a non-barcoded run for editing/copying we know it will only have a single sample. save_plan_step_data.prepopulatedFields['prevBarcodeId'] = None save_plan_step_data.savedFields['sampleName1'] = planned_experiment.get_sampleDisplayedName() #do not copy sampleTubeLabel since a sample tube is meant for 1 run only save_plan_step_data.savedFields['tubeLabel1'] = "" if step_helper.isCopy() else planned_experiment.sampleTubeLabel save_plan_step_data.savedFields['sampleExternalId1'] = planned_experiment.get_sample_external_id() save_plan_step_data.savedFields['sampleDescription1'] = planned_experiment.get_sample_description() #if there was ir info we grab it for plugin_name, plugin_dict in planned_experiment.get_selectedPlugins().items(): if 'IonReporter' in plugin_name: try: plugin = Plugin.objects.filter(name=plugin_name, active=True)[0] except: continue save_plan_step_data.prepopulatedFields['selectedIr'] = plugin save_plan_step_data.prepopulatedFields['irConfigJson'] = json.dumps(plugin.userinputfields) sample_ir_values = None if PluginFieldNames.USER_INPUT in plugin_dict: #Handle the old and the new style userinput in the plugin dictionary if isinstance(plugin_dict[PluginFieldNames.USER_INPUT], dict)\ and "userInputInfo" in plugin_dict[PluginFieldNames.USER_INPUT]\ and len(plugin_dict[PluginFieldNames.USER_INPUT]["userInputInfo"])>0: sample_ir_values = plugin_dict[PluginFieldNames.USER_INPUT]["userInputInfo"][0] save_plan_step_data.prepopulatedFields['setid_suffix'] = plugin_dict[PluginFieldNames.USER_INPUT]["userInputInfo"][0]['setid'][plugin_dict[PluginFieldNames.USER_INPUT]["userInputInfo"][0]['setid'].find('__'):] elif isinstance(plugin_dict[PluginFieldNames.USER_INPUT], list)\ and len(plugin_dict[PluginFieldNames.USER_INPUT])>0: sample_ir_values = plugin_dict[PluginFieldNames.USER_INPUT][0] if sample_ir_values: save_plan_step_data.savedFields['irWorkflow1'] = sample_ir_values['Workflow'] save_plan_step_data.savedFields['irGender1'] = sample_ir_values['Gender'] save_plan_step_data.savedFields['irRelation1'] = sample_ir_values['Relation'] save_plan_step_data.savedFields['irRelationRole1'] = sample_ir_values['RelationRole'] save_plan_step_data.savedFields['irSetID1'] = str(sample_ir_values['setid'])[0:str(sample_ir_values['setid']).find('__')] save_plan_step_data.updateSavedObjectsFromSavedFields()
def updatePlanBySampleSpecificStepHelper(self, step_helper, planned_experiment, sampleset_id): """ """ barcoding_step = step_helper.steps[StepNames.BARCODE_BY_SAMPLE] save_plan_step = step_helper.steps[StepNames.SAVE_PLAN_BY_SAMPLE] planDisplayedName = getPlanDisplayedName(planned_experiment) step_helper.steps[StepNames.IONREPORTER].savedFields['irworkflow'] = planned_experiment.irworkflow if step_helper.isCopy(): save_plan_step.savedFields[SavePlanBySampleFieldNames.TEMPLATE_NAME] = "Copy of " + planDisplayedName else: save_plan_step.savedFields[SavePlanBySampleFieldNames.TEMPLATE_NAME] = planDisplayedName if sampleset_id: sampleset = SampleSet.objects.get(pk=sampleset_id) if sampleset.SampleGroupType_CV: step_helper.steps[StepNames.APPLICATION].savedFields['sampleGrouping'] = sampleset.SampleGroupType_CV.pk else: sampleset = planned_experiment.sampleSet save_plan_step.savedObjects[SavePlanBySampleFieldNames.SAMPLESET] = sampleset samplesetitems = list(sampleset.samples.all()) all_barcodes = dnaBarcode.objects.values('name', 'id_str', 'sequence') barcodekits = set(map(lambda x : x['name'], all_barcodes)) barcoding_step.prepopulatedFields['accountId'] = step_helper.steps[StepNames.IONREPORTER].savedFields['irAccountId'] barcoding_step.prepopulatedFields['all_barcodes'] = sorted(all_barcodes, key=lambda x : x['id_str']) barcoding_step.prepopulatedFields['irworkflow'] = planned_experiment.irworkflow barcoding_step.prepopulatedFields['pe_irworkflow'] = planned_experiment.irworkflow dnabarcodes_grouped = [ dict( name = barcodekit, barcodes = sorted([ dict( id_str = str(dnabarcode['id_str']), sequence = str(dnabarcode['sequence'])) \ for dnabarcode in all_barcodes if dnabarcode['name'] == barcodekit], key=lambda z: z['id_str'])) \ for barcodekit in barcodekits] if step_helper.isBarcoded(): # planned_dnabarcodes = dnaBarcode.objects.filter(name=planned_experiment.get_barcodeId()).values('id_str', 'sequence').order_by('id_str') planned_dnabarcodes = list(dnaBarcode.objects.filter(name=planned_experiment.get_barcodeId()).order_by('id_str')) else: planned_dnabarcodes = [None] barcoding_step.prepopulatedFields['samplesetitems'] = samplesetitems barcoding_step.prepopulatedFields[BarcodeBySampleFieldNames.PLANNED_DNABARCODES] = planned_dnabarcodes barcoding_step.prepopulatedFields['barcodekits'] = dnabarcodes_grouped barcoding_step.savedFields[BarcodeBySampleFieldNames.NUMBER_OF_CHIPS] = len(samplesetitems) barcoding_step.savedFields[BarcodeBySampleFieldNames.BARCODE_ID] = planned_experiment.get_barcodeId() selected_plugins = planned_experiment.get_selectedPlugins() if 'IonReporterUploader' in selected_plugins: try: user_input_info = selected_plugins['IonReporterUploader']['userInput']['userInputInfo'] except: user_input_info = selected_plugins['IonReporterUploader']['userInput'] else: user_input_info = [planned_experiment.get_barcodedSamples()] result = [] if len(user_input_info) > 0 and len(user_input_info[0].keys()) > 0: for i in range(len(samplesetitems)): result.append(self.get_ir_fields_dict_from_user_input_info(user_input_info, user_input_info[i].get('sample', "barcoded--Sample") if i < len(user_input_info) else user_input_info[0].get('sampleName', "barcoded--Sample"), i)) user_input_info = sorted(result, key=lambda d: d.get('barcodeId')) existing_plan = not planned_experiment.isReusable if (step_helper.isEdit() or step_helper.isCopy()) and len(user_input_info[0]) > 0: if user_input_info[0].get('setid'): barcoding_step.prepopulatedFields['setid_suffix'] = user_input_info[0].get('setid')[user_input_info[0].get('setid').find('__'):] for i in range(100): barcoding_step.savedFields['%s%d' % (BarcodeBySampleFieldNames.NUMBER_OF_CHIPS, i)] = i + 1 barcoding_step.savedFields['%s%d' % (BarcodeBySampleFieldNames.SAMPLE_NAME, i)] = None barcoding_step.savedFields['%s%d' % (BarcodeBySampleFieldNames.SAMPLE_EXTERNAL_ID, i)] = None barcoding_step.savedFields['%s%d' % (BarcodeBySampleFieldNames.SAMPLE_BARCODE, i)] = None barcoding_step.savedFields['%s%d' % (BarcodeBySampleFieldNames.WORKFLOW, i)] = None barcoding_step.savedFields['%s%d' % (BarcodeBySampleFieldNames.GENDER, i)] = None barcoding_step.savedFields['%s%d' % (BarcodeBySampleFieldNames.SAMPLE_DESCRIPTION, i)] = None barcoding_step.savedFields['%s%d' % (BarcodeBySampleFieldNames.RELATION_ROLE, i)] = None barcoding_step.savedFields['%s%d' % ('relation', i)] = None barcoding_step.savedFields['%s%d' % (BarcodeBySampleFieldNames.SET_ID, i)] = None if step_helper.isBarcoded(): for i in range(len(planned_dnabarcodes)): samplesetitem = samplesetitems[i] if i < len(samplesetitems) else None dnabarcode = planned_dnabarcodes[i] if i < len(planned_dnabarcodes) else None if existing_plan: if i < len(user_input_info): user_input_dict = self.get_ir_fields_dict_from_user_input_info(user_input_info, user_input_info[i].get('sample', "barcoded--Sample"), i) barcoding_step.savedObjects[BarcodeBySampleFieldNames.BARCODE_TO_SAMPLE]['%s%d' % (user_input_dict.get('barcodeId'), i)] = { BarcodeBySampleFieldNames.NUMBER_OF_CHIPS : i + 1, BarcodeBySampleFieldNames.SAMPLE_NAME : user_input_dict.get('sample'), BarcodeBySampleFieldNames.SAMPLE_DESCRIPTION : user_input_dict.get('sampleDescription'), BarcodeBySampleFieldNames.SAMPLE_EXTERNAL_ID : user_input_dict.get('sampleExternalId'), BarcodeBySampleFieldNames.GENDER : user_input_dict.get('Gender'), BarcodeBySampleFieldNames.RELATION_ROLE : user_input_dict.get('RelationRole'), BarcodeBySampleFieldNames.WORKFLOW : user_input_dict.get('Workflow'), BarcodeBySampleFieldNames.BARCODE_ID : user_input_dict.get('barcodeId'), BarcodeBySampleFieldNames.SET_ID : user_input_dict.get('setid')[0:user_input_dict['setid'].find('__')] if user_input_dict.get('setid') else "", 'relation' : '', } else: barcoding_step.savedObjects[BarcodeBySampleFieldNames.BARCODE_TO_SAMPLE]['%s%d' % (dnabarcode.id_str, i)] = { BarcodeBySampleFieldNames.NUMBER_OF_CHIPS : i + 1, BarcodeBySampleFieldNames.SAMPLE_NAME : '', BarcodeBySampleFieldNames.SAMPLE_DESCRIPTION : '', BarcodeBySampleFieldNames.SAMPLE_EXTERNAL_ID : '', BarcodeBySampleFieldNames.GENDER : '', BarcodeBySampleFieldNames.RELATION_ROLE : '', BarcodeBySampleFieldNames.WORKFLOW : '', BarcodeBySampleFieldNames.BARCODE_ID : dnabarcode.id_str, BarcodeBySampleFieldNames.SET_ID : 0, 'relation' : '', } else: if i < len(samplesetitems): #create the saved objects dictionary for the dnabarcode to control #the order of display of dnabarcode id_str's and sample item names and descriptions barcoding_step.savedObjects[BarcodeBySampleFieldNames.BARCODE_TO_SAMPLE]['%s%d' % (dnabarcode.id_str, i)] = { BarcodeBySampleFieldNames.NUMBER_OF_CHIPS : i + 1, BarcodeBySampleFieldNames.SAMPLE_NAME : samplesetitem.sample.displayedName, BarcodeBySampleFieldNames.SAMPLE_DESCRIPTION : samplesetitem.sample.description, BarcodeBySampleFieldNames.SAMPLE_EXTERNAL_ID : samplesetitem.sample.externalId, BarcodeBySampleFieldNames.GENDER : samplesetitem.gender, BarcodeBySampleFieldNames.RELATION_ROLE : samplesetitem.relationshipRole, BarcodeBySampleFieldNames.WORKFLOW : planned_experiment.irworkflow, BarcodeBySampleFieldNames.BARCODE_ID : dnabarcode.id_str, BarcodeBySampleFieldNames.SET_ID : samplesetitem.relationshipGroup, 'relation' : '', } else: barcoding_step.savedObjects[BarcodeBySampleFieldNames.BARCODE_TO_SAMPLE]['%s%d' % (dnabarcode.id_str, i)] = { BarcodeBySampleFieldNames.NUMBER_OF_CHIPS : i + 1, BarcodeBySampleFieldNames.SAMPLE_NAME : '', BarcodeBySampleFieldNames.SAMPLE_DESCRIPTION : '', BarcodeBySampleFieldNames.SAMPLE_EXTERNAL_ID : '', BarcodeBySampleFieldNames.GENDER : '', BarcodeBySampleFieldNames.RELATION_ROLE : '', BarcodeBySampleFieldNames.WORKFLOW : '', BarcodeBySampleFieldNames.BARCODE_ID : dnabarcode.id_str, BarcodeBySampleFieldNames.SET_ID : 0, 'relation' : '', } #create the saved objects dictionary for each sample set item which holds the dnabarcoding information #and will be used in the final save process if i < len(samplesetitems): barcoding_step.savedObjects[BarcodeBySampleFieldNames.SAMPLE_TO_BARCODE][samplesetitem.sample.displayedName] = { 'barcodeSampleInfo' : { dnabarcode.id_str : { 'externalId' : samplesetitem.sample.externalId, 'description' : samplesetitem.sample.description, } }, 'barcodes' : [dnabarcode.id_str] } else: for i in range(20): samplesetitem = samplesetitems[i] if i < len(samplesetitems) else None dnabarcode = planned_dnabarcodes[i] if i < len(planned_dnabarcodes) else None if existing_plan: if i == planned_experiment.sampleSet_planIndex: if step_helper.steps[StepNames.IONREPORTER].savedFields['irAccountId'] == '0': user_input_info = [dict()] barcoding_step.savedObjects[BarcodeBySampleFieldNames.CHIP_TO_SAMPLE][i] = { BarcodeBySampleFieldNames.NUMBER_OF_CHIPS : i + 1, BarcodeBySampleFieldNames.SAMPLE_NAME : planned_experiment.get_sampleDisplayedName(), BarcodeBySampleFieldNames.SAMPLE_DESCRIPTION : planned_experiment.get_sample_description(), BarcodeBySampleFieldNames.SAMPLE_EXTERNAL_ID : planned_experiment.get_sample_external_id(), BarcodeBySampleFieldNames.GENDER : user_input_info[0].get('Gender'), BarcodeBySampleFieldNames.RELATION_ROLE : user_input_info[0].get('RelationRole'), BarcodeBySampleFieldNames.WORKFLOW : user_input_info[0].get('Workflow'), BarcodeBySampleFieldNames.SET_ID : user_input_info[0].get('setid')[0:user_input_info[0]['setid'].find('__')] if user_input_info[0].get('setid') else "", 'relation' : '', } else: if i < len(samplesetitems): barcoding_step.savedObjects[BarcodeBySampleFieldNames.CHIP_TO_SAMPLE][i] = { BarcodeBySampleFieldNames.NUMBER_OF_CHIPS : i + 1, BarcodeBySampleFieldNames.SAMPLE_NAME : samplesetitem.sample.displayedName, BarcodeBySampleFieldNames.SAMPLE_DESCRIPTION : samplesetitem.sample.description, BarcodeBySampleFieldNames.SAMPLE_EXTERNAL_ID : samplesetitem.sample.externalId, BarcodeBySampleFieldNames.GENDER : samplesetitem.gender, BarcodeBySampleFieldNames.RELATION_ROLE : samplesetitem.relationshipRole, BarcodeBySampleFieldNames.WORKFLOW : planned_experiment.irworkflow, BarcodeBySampleFieldNames.SET_ID : samplesetitem.relationshipGroup, 'relation' : '', } elif step_helper.steps[StepNames.IONREPORTER].savedFields['irAccountId'] == '0': barcoding_step.savedObjects[BarcodeBySampleFieldNames.CHIP_TO_SAMPLE][i] = { BarcodeBySampleFieldNames.NUMBER_OF_CHIPS : i + 1, BarcodeBySampleFieldNames.SAMPLE_NAME : '', BarcodeBySampleFieldNames.SAMPLE_DESCRIPTION : '', BarcodeBySampleFieldNames.SAMPLE_EXTERNAL_ID : '', BarcodeBySampleFieldNames.GENDER : '', BarcodeBySampleFieldNames.RELATION_ROLE : '', BarcodeBySampleFieldNames.WORKFLOW : '', 'relation' : '', }