def get_ampliseq_designs(user, password, pipeline, ctx): response, designs = _get_all_ampliseq_designs(user, password) if designs: ctx['unordered_solutions'] = [] ctx['ordered_solutions'] = [] unordered_tmpList = [] ordered_tmpList = [] for design in designs: for template in design.get('DesignSolutions', []): ampliSeq = AmpliSeqPanelImport(data=template) solution, meta = ampliSeq.handle_versioned_plans() solution_id = solution['id'] configurationChoices = solution['configuration_choices'] if match(solution, pipeline): if solution.get('ordered', False): ctx['ordered_solutions'].append((design, solution)) ordered_tmpList.append({ 'configuration_choices': configurationChoices, 'id': solution_id }) else: ctx['unordered_solutions'].append((design, solution)) unordered_tmpList.append({ 'configuration_choices': configurationChoices, 'id': solution_id }) unordered_tmpList = convert(unordered_tmpList) ordered_tmpList = convert(ordered_tmpList) ctx['unordered_solution'] = json.dumps(unordered_tmpList) ctx['ordered_solution'] = json.dumps(ordered_tmpList) return response, ctx else: return response, {}
def get_ampliseq_designs(user, password, pipeline, ctx): http = httplib2.Http(disable_ssl_certificate_validation=settings.DEBUG) http.add_credentials(user, password) url = urlparse.urljoin(settings.AMPLISEQ_URL, "ws/design/list") response, content = http.request(url) if response['status'] == '200': design_data = json.loads(content) designs = design_data.get('AssayDesigns', []) ctx['unordered_solutions'] = [] ctx['ordered_solutions'] = [] unordered_tmpList = [] ordered_tmpList = [] for design in designs: for template in design.get('DesignSolutions', []): ampliSeq = AmpliSeqPanelImport(data=template) solution, meta = ampliSeq.handle_versioned_plans() solution_id = solution['id'] configurationChoices = solution['configuration_choices'] if match(solution, pipeline): if solution.get('ordered', False): ctx['ordered_solutions'].append((design, solution)) ordered_tmpList.append({'configuration_choices': configurationChoices, 'id': solution_id}) else: ctx['unordered_solutions'].append((design, solution)) unordered_tmpList.append({'configuration_choices': configurationChoices, 'id': solution_id}) unordered_tmpList = convert(unordered_tmpList) ordered_tmpList = convert(ordered_tmpList) ctx['unordered_solution'] = json.dumps(unordered_tmpList) ctx['ordered_solution'] = json.dumps(ordered_tmpList) return response, ctx else: return response, {}
def get_ampliseq_designs(user, password, pipeline, ctx): response, designs = _get_all_ampliseq_designs(user, password) if designs: ctx['unordered_solutions'] = [] ctx['ordered_solutions'] = [] unordered_tmpList = [] ordered_tmpList = [] for design in designs: for template in design.get('DesignSolutions', []): ampliSeq = AmpliSeqPanelImport(data=template) solution, meta = ampliSeq.handle_versioned_plans() solution_id = solution['id'] configurationChoices = solution['configuration_choices'] if match(solution, pipeline): if solution.get('ordered', False): ctx['ordered_solutions'].append((design, solution)) ordered_tmpList.append({'configuration_choices': configurationChoices, 'id': solution_id}) else: ctx['unordered_solutions'].append((design, solution)) unordered_tmpList.append({'configuration_choices': configurationChoices, 'id': solution_id}) unordered_tmpList = convert(unordered_tmpList) ordered_tmpList = convert(ordered_tmpList) ctx['unordered_solution'] = json.dumps(unordered_tmpList) ctx['ordered_solution'] = json.dumps(ordered_tmpList) return response, ctx else: return response, {}
def validateStep(self): self.validationErrors.pop(SavePlanFieldNames.NO_BARCODE, None) self.validationErrors.pop(SavePlanFieldNames.BAD_BARCODES, None) samplesTable = json.loads( self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]) barcodeSet = self.savedFields[SavePlanFieldNames.BARCODE_SET] selectedBarcodes = [] endBarcodeSet = self.savedFields[SavePlanFieldNames.END_BARCODE_SET] selectedEndBarcodes = [] for row in samplesTable: sample_name = row.get(SavePlanFieldNames.SAMPLE_NAME, '').strip() if sample_name: if barcodeSet: selectedBarcodes.append( row.get(SavePlanFieldNames. BARCODE_SAMPLE_BARCODE_ID_UI_KEY)) if endBarcodeSet: endBarcode_id_value = row.get( SavePlanFieldNames. BARCODE_SAMPLE_END_BARCODE_ID_UI_KEY) if endBarcode_id_value: selectedEndBarcodes.append(endBarcode_id_value) if barcodeSet: errors = validate_barcode_sample_association( selectedBarcodes, barcodeSet) myErrors = convert(errors) if myErrors.get("MISSING_BARCODE", ""): self.validationErrors[ SavePlanFieldNames.NO_BARCODE] = myErrors.get( "MISSING_BARCODE", "") if myErrors.get("DUPLICATE_BARCODE", ""): self.validationErrors[ SavePlanFieldNames.BAD_BARCODES] = myErrors.get( "DUPLICATE_BARCODE", "") if selectedEndBarcodes: applProduct = self.savedObjects[SavePlanFieldNames.APPL_PRODUCT] if applProduct and applProduct.dualBarcodingRule == "no_reuse": errors = validate_barcode_sample_association( selectedEndBarcodes, endBarcodeSet, isEndBarcodeExists=True) myErrors = convert(errors) if myErrors.get("DUPLICATE_BARCODE", ""): self.validationErrors[ SavePlanFieldNames.BAD_BARCODES] = myErrors.get( "DUPLICATE_BARCODE", "") self.prepopulatedFields[SavePlanFieldNames.FIRE_VALIDATION] = "0"
def validateStep(self): self.validationErrors.pop(SavePlanFieldNames.NO_BARCODE,None) self.validationErrors.pop(SavePlanFieldNames.BAD_BARCODES,None) samplesTable = json.loads(self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]) barcodeSet = self.savedFields[SavePlanFieldNames.BARCODE_SET] selectedBarcodes = [] for row in samplesTable: sample_name = row.get(SavePlanFieldNames.SAMPLE_NAME,'').strip() if sample_name: if barcodeSet: selectedBarcodes.append(row.get('barcodeId')) if barcodeSet: errors = validate_barcode_sample_association(selectedBarcodes, barcodeSet) myErrors = convert(errors) if myErrors.get("MISSING_BARCODE", ""): self.validationErrors[SavePlanFieldNames.NO_BARCODE] = myErrors.get("MISSING_BARCODE", "") if myErrors.get("DUPLICATE_BARCODE", ""): self.validationErrors[SavePlanFieldNames.BAD_BARCODES] = myErrors.get("DUPLICATE_BARCODE", "") self.prepopulatedFields[SavePlanFieldNames.FIRE_VALIDATION] = "0"
def validateStep(self): self.validationErrors.pop(SavePlanFieldNames.NO_BARCODE, None) self.validationErrors.pop(SavePlanFieldNames.BAD_BARCODES, None) samplesTable = json.loads(self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]) barcodeSet = self.savedFields[SavePlanFieldNames.BARCODE_SET] selectedBarcodes = [] for row in samplesTable: sample_name = row.get(SavePlanFieldNames.SAMPLE_NAME, '').strip() if sample_name: if barcodeSet: selectedBarcodes.append(row.get('barcodeId')) if barcodeSet: errors = validate_barcode_sample_association(selectedBarcodes, barcodeSet) myErrors = convert(errors) if myErrors.get("MISSING_BARCODE", ""): self.validationErrors[SavePlanFieldNames.NO_BARCODE] = myErrors.get("MISSING_BARCODE", "") if myErrors.get("DUPLICATE_BARCODE", ""): self.validationErrors[SavePlanFieldNames.BAD_BARCODES] = myErrors.get("DUPLICATE_BARCODE", "") self.prepopulatedFields[SavePlanFieldNames.FIRE_VALIDATION] = "0"
def validateStep(self): self.validationErrors.pop(SavePlanFieldNames.NO_BARCODE, None) self.validationErrors.pop(SavePlanFieldNames.BAD_BARCODES, None) samplesTable = json.loads(self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]) barcodeSet = self.savedFields[SavePlanFieldNames.BARCODE_SET] selectedBarcodes = [] endBarcodeSet = self.savedFields[SavePlanFieldNames.END_BARCODE_SET] selectedEndBarcodes = [] for row in samplesTable: sample_name = row.get(SavePlanFieldNames.SAMPLE_NAME, '').strip() if sample_name: if barcodeSet: selectedBarcodes.append(row.get(SavePlanFieldNames.BARCODE_SAMPLE_BARCODE_ID_UI_KEY)) if endBarcodeSet: endBarcode_id_value = row.get(SavePlanFieldNames.BARCODE_SAMPLE_END_BARCODE_ID_UI_KEY) if endBarcode_id_value: selectedEndBarcodes.append(endBarcode_id_value) if barcodeSet: errors = validate_barcode_sample_association(selectedBarcodes, barcodeSet) myErrors = convert(errors) if myErrors.get("MISSING_BARCODE", ""): self.validationErrors[SavePlanFieldNames.NO_BARCODE] = myErrors.get("MISSING_BARCODE", "") if myErrors.get("DUPLICATE_BARCODE", ""): self.validationErrors[SavePlanFieldNames.BAD_BARCODES] = myErrors.get("DUPLICATE_BARCODE", "") if selectedEndBarcodes: applProduct = self.savedObjects[SavePlanFieldNames.APPL_PRODUCT] if applProduct and applProduct.dualBarcodingRule == "no_reuse": errors = validate_barcode_sample_association(selectedEndBarcodes, endBarcodeSet, isEndBarcodeExists = True) myErrors = convert(errors) if myErrors.get("DUPLICATE_BARCODE", ""): self.validationErrors[SavePlanFieldNames.BAD_BARCODES] = myErrors.get("DUPLICATE_BARCODE", "") self.prepopulatedFields[SavePlanFieldNames.FIRE_VALIDATION] = "0"
def get_ampliseq_designs(user, password, pipeline, ctx): http = httplib2.Http(disable_ssl_certificate_validation=settings.DEBUG) http.add_credentials(user, password) url = urlparse.urljoin(settings.AMPLISEQ_URL, "ws/design/list") response, content = http.request(url) if response['status'] == '200': design_data = json.loads(content) designs = design_data.get('AssayDesigns', []) ctx['unordered_solutions'] = [] ctx['ordered_solutions'] = [] unordered_tmpList = [] ordered_tmpList = [] for design in designs: for template in design.get('DesignSolutions', []): ampliSeq = AmpliSeqPanelImport(data=template) solution, meta = ampliSeq.handle_versioned_plans() solution_id = solution['id'] configurationChoices = solution['configuration_choices'] if match(solution, pipeline): if solution.get('ordered', False): ctx['ordered_solutions'].append((design, solution)) ordered_tmpList.append({ 'configuration_choices': configurationChoices, 'id': solution_id }) else: ctx['unordered_solutions'].append((design, solution)) unordered_tmpList.append({ 'configuration_choices': configurationChoices, 'id': solution_id }) unordered_tmpList = convert(unordered_tmpList) ordered_tmpList = convert(ordered_tmpList) ctx['unordered_solution'] = json.dumps(unordered_tmpList) ctx['ordered_solution'] = json.dumps(ordered_tmpList) return response, ctx else: return response, {}
def get_fixed_designs_list(fixed_design_data, pipeline): # creates fixed_solutions: a list of dictionaries with : # Design id : Ready-to-Use ampliseq panel ID # configuration_choices : the instrument/chip types supported by the corresponding panel. # Type : Community or Fixed Panel - used to to link to Ampliseq website # Genome : Supported genome by the specific panel. # final_fixed_soln_data : #Lists all the design panels available for the specific pipeline # fixed_ids_choices : This is used to compare the parametized files available and show the warnings fixed = [] fixedDesigns = fixed_design_data.get('TemplateDesigns', []) for template in fixedDesigns: ampliSeq = AmpliSeqPanelImport(data=template) data, meta = ampliSeq.handle_versioned_plans() fixed.append(data) if fixed: ordered_solutions = [] tmpList = [] tmpFixedsolLists = [] fixed_solutions = filter( lambda x: x['status'] == "ORDERABLE" and match(x, pipeline), fixed) for design in fixed_solutions: designID = design['id'] configurationChoices = design['configuration_choices'] tmpDict = { 'id': designID, 'configuration_choices': configurationChoices } tmpFixedSolDict = { 'id': designID, 'genome': design['genome'], "name": design["name"], "type": design["type"], } tmpList.append(tmpDict) tmpFixedsolLists.append(tmpFixedSolDict) #This is used to compare the parametized files available and show the warnings fixed_ids_choices = json.dumps(convert(tmpList)) #Lists all the design panels available for the specific pipeline final_fixed_soln_data = tmpFixedsolLists return final_fixed_soln_data, ordered_solutions, fixed_ids_choices
def get_fixed_designs_list(fixed_design_data, pipeline): # creates fixed_solutions: a list of dictionaries with : # Design id : Ready-to-Use ampliseq panel ID # configuration_choices : the instrument/chip types supported by the corresponding panel. # Type : Community or Fixed Panel - used to to link to Ampliseq website # Genome : Supported genome by the specific panel. # final_fixed_soln_data : #Lists all the design panels available for the specific pipeline # fixed_ids_choices : This is used to compare the parametized files available and show the warnings fixed = [] fixedDesigns = fixed_design_data.get('TemplateDesigns', []) for template in fixedDesigns: ampliSeq = AmpliSeqPanelImport(data=template) data, meta = ampliSeq.handle_versioned_plans() fixed.append(data) if fixed: ordered_solutions = [] tmpList = [] tmpFixedsolLists = [] fixed_solutions = filter(lambda x: x['status'] == "ORDERABLE" and match(x, pipeline), fixed) for design in fixed_solutions: designID = design['id'] configurationChoices = design['configuration_choices'] tmpDict = {'id': designID, 'configuration_choices': configurationChoices} tmpFixedSolDict = {'id': designID, 'genome': design['genome'], "name" : design["name"], "type" : design["type"], } tmpList.append(tmpDict) tmpFixedsolLists.append(tmpFixedSolDict) #This is used to compare the parametized files available and show the warnings fixed_ids_choices = json.dumps(convert(tmpList)) #Lists all the design panels available for the specific pipeline final_fixed_soln_data = tmpFixedsolLists return final_fixed_soln_data, ordered_solutions, fixed_ids_choices
def updateSavedFieldsForSamples_retired(self): #logger.debug("ENTER barcode_by_sample_step_data.updateSavedFieldsForSamples() self.savedFields[SavePlanFieldNames.BARCODE_SET]=%s" %(self.savedFields[SavePlanFieldNames.BARCODE_SET])) #convert tuple to string planReference = str(self.prepopulatedFields[SavePlanFieldNames.PLAN_REFERENCE]) planHotSpotRegionBedFile = str(self.prepopulatedFields[SavePlanFieldNames.PLAN_HOTSPOT_REGION_BED_FILE]) planTargetRegionBedFile = str(self.prepopulatedFields[SavePlanFieldNames.PLAN_TARGET_REGION_BED_FILE]) #logger.debug("barcode_by_sample_step_data.updateSavedFieldsForSamples() type(self.prepopulatedFields[SavePlanFieldNames.PLAN_REFERENCE])=%s; self.prepopulatedFields[SavePlanFieldNames.PLAN_REFERENCE]=%s" %(type(self.prepopulatedFields[SavePlanFieldNames.PLAN_REFERENCE]), self.prepopulatedFields[SavePlanFieldNames.PLAN_REFERENCE])) hasAnyChanges = False myTable = json.loads(self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]) #convert unicode to str myTable = convert(myTable) for index, row in enumerate(myTable): #logger.debug("barcode_by_sample_step_data.updateSavedFieldsForSamples() B4 CHANGES... BARCODE_SET LOOP row=%s" %(row)) sample_name = row.get(SavePlanFieldNames.SAMPLE_NAME,'').strip() if sample_name: sample_nucleotideType = row.get(SavePlanFieldNames.BARCODE_SAMPLE_NUCLEOTIDE_TYPE, "") sampleReference = row.get(SavePlanFieldNames.BARCODE_SAMPLE_REFERENCE, "") sampleHotSpotRegionBedFile = row.get(SavePlanFieldNames.BARCODE_SAMPLE_HOTSPOT_REGION_BED_FILE, "") sampleTargetRegionBedFile = row.get(SavePlanFieldNames.BARCODE_SAMPLE_TARGET_REGION_BED_FILE, "") runType = self.prepopulatedFields[SavePlanFieldNames.RUN_TYPE] if runType == "AMPS_DNA_RNA" and sample_nucleotideType == "RNA": newSampleReference = sampleReference newSampleHotSpotRegionBedFile = sampleHotSpotRegionBedFile newSampleTargetRegionBedFile = sampleTargetRegionBedFile else: newSampleReference = planReference newSampleHotSpotRegionBedFile = planHotSpotRegionBedFile newSampleTargetRegionBedFile = planTargetRegionBedFile #logger.debug("barcode_by_sample_step_data.updateSavedFieldsForSamples() BARCODE_SET LOOP planReference=%s; type(newSampleReference)=%s; newSampleReference=%s;" %(planReference, type(newSampleReference), newSampleReference)) #cascade the reference and BED file info to sample if none specified at the sample level if runType != "AMPS_DNA_RNA": if not sampleReference: newSampleReference = planReference newSampleHotSpotRegionBedFile = planHotSpotRegionBedFile newSampleTargetRegionBedFile = planTargetRegionBedFile hasChanged = False if newSampleReference != sampleReference: row[SavePlanFieldNames.BARCODE_SAMPLE_REFERENCE] = newSampleReference hasChanged = True if newSampleHotSpotRegionBedFile != sampleHotSpotRegionBedFile: row[SavePlanFieldNames.BARCODE_SAMPLE_HOTSPOT_REGION_BED_FILE] = newSampleHotSpotRegionBedFile hasChanged = True if newSampleTargetRegionBedFile != sampleTargetRegionBedFile: row[SavePlanFieldNames.BARCODE_SAMPLE_TARGET_REGION_BED_FILE] = newSampleTargetRegionBedFile hasChanged = True #logger.debug("barcode_by_sample_step_data.updateSavedFieldsForSamples() hasChanged=%s; row=%s" %(hasChanged, row)) if hasChanged: myTable[index] = row #logger.debug("barcode_by_sample_step_data.updateSavedFieldsForSamples() AFTER CHANGES BARCODE_SET LOOP myTable[index]=%s" %(myTable[index])) hasAnyChanges = True if hasAnyChanges: #logger.debug("barcode_by_sample_step_data.updateSavedFieldsForSamples() hasAnyChanges AFTER CHANGES... type=%s; myTable=%s" %(type(myTable), myTable)) #convert list with single quotes to str with double quotes. Then convert it to be unicode self.savedFields[SavePlanFieldNames.SAMPLES_TABLE] = unicode(json.dumps(myTable)) #logger.debug("barcode_by_sample_step_data.updateSavedFieldsForSamples() hasAnyChanges AFTER unicode(json.dumps)... type=%s; self.savedFields[samplesTable]=%s" %(type(self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]), self.savedFields[SavePlanFieldNames.SAMPLES_TABLE])) self.savedObjects[SavePlanFieldNames.SAMPLES_TABLE_LIST] = json.loads(self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]) self.updateSavedObjectsFromSavedFields()
def updateSavedFieldsForSamples_retired(self): # logger.debug("ENTER barcode_by_sample_step_data.updateSavedFieldsForSamples() self.savedFields[SavePlanFieldNames.BARCODE_SET]=%s" %(self.savedFields[SavePlanFieldNames.BARCODE_SET])) # convert tuple to string planReference = str(self.prepopulatedFields[SavePlanFieldNames.PLAN_REFERENCE]) planHotSpotRegionBedFile = str(self.prepopulatedFields[SavePlanFieldNames.PLAN_HOTSPOT_REGION_BED_FILE]) planTargetRegionBedFile = str(self.prepopulatedFields[SavePlanFieldNames.PLAN_TARGET_REGION_BED_FILE]) # logger.debug("barcode_by_sample_step_data.updateSavedFieldsForSamples() type(self.prepopulatedFields[SavePlanFieldNames.PLAN_REFERENCE])=%s; self.prepopulatedFields[SavePlanFieldNames.PLAN_REFERENCE]=%s" %(type(self.prepopulatedFields[SavePlanFieldNames.PLAN_REFERENCE]), self.prepopulatedFields[SavePlanFieldNames.PLAN_REFERENCE])) hasAnyChanges = False myTable = json.loads(self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]) # convert unicode to str myTable = convert(myTable) for index, row in enumerate(myTable): # logger.debug("barcode_by_sample_step_data.updateSavedFieldsForSamples() B4 CHANGES... BARCODE_SET LOOP row=%s" %(row)) sample_name = row.get(SavePlanFieldNames.SAMPLE_NAME, '').strip() if sample_name: sample_nucleotideType = row.get(SavePlanFieldNames.BARCODE_SAMPLE_NUCLEOTIDE_TYPE, "") sampleReference = row.get(SavePlanFieldNames.BARCODE_SAMPLE_REFERENCE, "") sampleHotSpotRegionBedFile = row.get(SavePlanFieldNames.BARCODE_SAMPLE_HOTSPOT_REGION_BED_FILE, "") sampleTargetRegionBedFile = row.get(SavePlanFieldNames.BARCODE_SAMPLE_TARGET_REGION_BED_FILE, "") runType = self.prepopulatedFields[SavePlanFieldNames.RUN_TYPE] if runType == "AMPS_DNA_RNA" and sample_nucleotideType == "RNA": newSampleReference = sampleReference newSampleHotSpotRegionBedFile = sampleHotSpotRegionBedFile newSampleTargetRegionBedFile = sampleTargetRegionBedFile else: newSampleReference = planReference newSampleHotSpotRegionBedFile = planHotSpotRegionBedFile newSampleTargetRegionBedFile = planTargetRegionBedFile # logger.debug("barcode_by_sample_step_data.updateSavedFieldsForSamples() BARCODE_SET LOOP planReference=%s; type(newSampleReference)=%s; newSampleReference=%s;" %(planReference, type(newSampleReference), newSampleReference)) # cascade the reference and BED file info to sample if none specified at the sample level if runType != "AMPS_DNA_RNA": if not sampleReference: newSampleReference = planReference newSampleHotSpotRegionBedFile = planHotSpotRegionBedFile newSampleTargetRegionBedFile = planTargetRegionBedFile hasChanged = False if newSampleReference != sampleReference: row[SavePlanFieldNames.BARCODE_SAMPLE_REFERENCE] = newSampleReference hasChanged = True if newSampleHotSpotRegionBedFile != sampleHotSpotRegionBedFile: row[SavePlanFieldNames.BARCODE_SAMPLE_HOTSPOT_REGION_BED_FILE] = newSampleHotSpotRegionBedFile hasChanged = True if newSampleTargetRegionBedFile != sampleTargetRegionBedFile: row[SavePlanFieldNames.BARCODE_SAMPLE_TARGET_REGION_BED_FILE] = newSampleTargetRegionBedFile hasChanged = True # logger.debug("barcode_by_sample_step_data.updateSavedFieldsForSamples() hasChanged=%s; row=%s" %(hasChanged, row)) if hasChanged: myTable[index] = row # logger.debug("barcode_by_sample_step_data.updateSavedFieldsForSamples() AFTER CHANGES BARCODE_SET LOOP myTable[index]=%s" %(myTable[index])) hasAnyChanges = True if hasAnyChanges: # logger.debug("barcode_by_sample_step_data.updateSavedFieldsForSamples() hasAnyChanges AFTER CHANGES... type=%s; myTable=%s" %(type(myTable), myTable)) # convert list with single quotes to str with double quotes. Then convert it to be unicode self.savedFields[SavePlanFieldNames.SAMPLES_TABLE] = unicode(json.dumps(myTable)) # logger.debug("barcode_by_sample_step_data.updateSavedFieldsForSamples() hasAnyChanges AFTER unicode(json.dumps)... type=%s; self.savedFields[samplesTable]=%s" %(type(self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]), self.savedFields[SavePlanFieldNames.SAMPLES_TABLE])) self.savedObjects[SavePlanFieldNames.SAMPLES_TABLE_LIST] = json.loads(self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]) self.updateSavedObjectsFromSavedFields()
def updateSavedFieldsForSamples_may_no_longer_needed(self): # logger.debug("ENTER save_plan_step_data.updateSavedFieldsForSamples() B4 type=%s; self.savedFields[samplesTable]=%s" %(type(self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]), self.savedFields[SavePlanFieldNames.SAMPLES_TABLE])) # logger.debug("ENTER save_plan_step_data.updateSavedFieldsForSamples() B4 type=%s; self.savedObjects[samplesTableList]=%s" %(type(self.savedObjects[SavePlanFieldNames.SAMPLES_TABLE_LIST]), self.savedObjects[SavePlanFieldNames.SAMPLES_TABLE_LIST])) # convert tuple to string planReference = str(self.prepopulatedFields[SavePlanFieldNames.PLAN_REFERENCE]) planHotSptRegionBedFile = str(self.prepopulatedFields[SavePlanFieldNames.PLAN_HOTSPOT_REGION_BED_FILE]) planTargetRegionBedFile = str(self.prepopulatedFields[SavePlanFieldNames.PLAN_TARGET_REGION_BED_FILE]) # logger.debug("save_plan_step_data.updateSavedFieldsForSamples() type(planReference)=%s; planReference=%s" %(type(planReference), planReference)) # logger.debug("save_plan_step_data.updateSavedFieldsForSamples() type(self.prepopulatedFields[SavePlanFieldNames.PLAN_REFERENCE])=%s; self.prepopulatedFields[SavePlanFieldNames.PLAN_REFERENCE]=%s" %(type(self.prepopulatedFields[SavePlanFieldNames.PLAN_REFERENCE]), self.prepopulatedFields[SavePlanFieldNames.PLAN_REFERENCE])) hasAnyChanges = False myTable = json.loads(self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]) # convert unicode to str myTable = convert(myTable) isCreate = self.sh_type in [StepHelperType.CREATE_NEW_PLAN, StepHelperType.CREATE_NEW_TEMPLATE] # logger.debug("save_plan_step_data.updateSavedFieldsForSamples() isCreate()=%s" %(isCreate)) for index, row in enumerate(myTable): # logger.debug("save_plan_step_data.updateSavedFieldsForSamples() B4 CHANGES... BARCODE_SET LOOP row=%s" %(row)) sample_name = row.get(SavePlanFieldNames.SAMPLE_NAME, '').strip() if sample_name: sample_nucleotideType = row.get(SavePlanFieldNames.BARCODE_SAMPLE_NUCLEOTIDE_TYPE, "") sampleReference = row.get(SavePlanFieldNames.BARCODE_SAMPLE_REFERENCE, "") sampleHotSpotRegionBedFile = row.get(SavePlanFieldNames.BARCODE_SAMPLE_HOTSPOT_REGION_BED_FILE, "") sampleTargetRegionBedFile = row.get(SavePlanFieldNames.BARCODE_SAMPLE_TARGET_REGION_BED_FILE, "") runType = self.prepopulatedFields[SavePlanFieldNames.RUN_TYPE] if runType == "AMPS_DNA_RNA" and sample_nucleotideType == "RNA": newSampleReference = sampleReference newSampleHotspotRegionBedFile = sampleHotSpotRegionBedFile newSampleTargetRegionBedFile = sampleTargetRegionBedFile else: if not sampleReference and self.savedObjects[SavePlanFieldNames.APPL_PRODUCT] and not self.savedObjects[SavePlanFieldNames.APPL_PRODUCT].isReferenceBySampleSupported and isCreate: logger.debug("save_plan_step_data.updateSavedFieldsForSamples() GOING to set sampleReference to planReference... planReference=%s" % (planReference)) sampleReference = planReference sampleHotSpotRegionBedFile = planHotSptRegionBedFile sampleTargetRegionBedFile = planTargetRegionBedFile # else: # logger.debug("save_plan_step_data.updateSavedFieldsForSamples() SKIP SETTING sampleReference to planReference... isCreate=%s" %(isCreate)) newSampleReference = planReference newSampleHotspotRegionBedFile = planHotSptRegionBedFile newSampleTargetRegionBedFile = planTargetRegionBedFile hasChanged = False if newSampleReference != sampleReference: row[SavePlanFieldNames.BARCODE_SAMPLE_REFERENCE] = newSampleReference hasChanged = True if newSampleHotspotRegionBedFile != sampleHotSpotRegionBedFile: row[SavePlanFieldNames.BARCODE_SAMPLE_HOTSPOT_REGION_BED_FILE] = newSampleHotspotRegionBedFile hasChanged = True if newSampleTargetRegionBedFile != sampleTargetRegionBedFile: row[SavePlanFieldNames.BARCODE_SAMPLE_TARGET_REGION_BED_FILE] = newSampleTargetRegionBedFile hasChanged = True if hasChanged: myTable[index] = row # logger.debug("save_plan_step_data.updateSavedFieldsForSamples() AFTER CHANGES BARCODE_SET LOOP myTable[index]=%s" %(myTable[index])) hasAnyChanges = True if hasAnyChanges: logger.debug("save_plan_step_data.updateSavedFieldsForSamples() hasAnyChanges AFTER CHANGES... type=%s; myTable=%s" % (type(myTable), myTable)) # convert list with single quotes to str with double quotes. Then convert it to be unicode self.savedFields[SavePlanFieldNames.SAMPLES_TABLE] = unicode(json.dumps(myTable)) # logger.debug("save_plan_step_data.updateSavedFieldsForSamples() hasAnyChanges AFTER unicode(json.dumps)... type=%s; self.savedFields[samplesTable]=%s" %(type(self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]), self.savedFields[SavePlanFieldNames.SAMPLES_TABLE])) self.savedObjects[SavePlanFieldNames.SAMPLES_TABLE_LIST] = json.loads(self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]) logger.debug("save_plan_step_data.updateSavedFieldsForSamples() hasAnyChanges AFTER json.loads... type=%s; self.savedObjects[samplesTableList]=%s" % (type(self.savedObjects[SavePlanFieldNames.SAMPLES_TABLE_LIST]), self.savedObjects[SavePlanFieldNames.SAMPLES_TABLE_LIST]))
def validateStep(self): any_samples = False self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_NAME] = [] self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID] = [] self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION] = [] self.validationErrors[SavePlanFieldNames.BAD_TUBE_LABEL] = [] self.validationErrors[SavePlanFieldNames.BAD_CHIP_BARCODE] = [] self.validationErrors[SavePlanFieldNames.BAD_IR_SET_ID] = [] self.validationErrors.pop(SavePlanFieldNames.NO_BARCODE, None) self.validationErrors.pop(SavePlanFieldNames.BAD_BARCODES, None) barcodeSet = self.savedFields[SavePlanFieldNames.BARCODE_SET] selectedBarcodes = [] endBarcodeSet = self.savedFields[SavePlanFieldNames.END_BARCODE_SET] selectedEndBarcodes = [] samplesTable = json.loads(self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]) # logger.debug("save_plan_step_data - anySamples? samplesTable=%s" %(samplesTable)) for row in samplesTable: sample_name = row.get(SavePlanFieldNames.SAMPLE_NAME, '').strip() # logger.debug("save_plan_step_data - anySamples? sampleName=%s" %(sample_name)) if sample_name: any_samples = True if validate_sample_name(sample_name): self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_NAME].append(sample_name) external_id = row.get(SavePlanFieldNames.SAMPLE_EXTERNAL_ID, '') if external_id: self.validate_field(external_id, self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID]) description = row.get(SavePlanFieldNames.SAMPLE_DESCRIPTION, '') if description: self.validate_field(description, self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION], False, MAX_LENGTH_SAMPLE_DESCRIPTION) ir_set_id = row.get('irSetId', '') if ir_set_id and not (str(ir_set_id).isdigit()): self.validationErrors[SavePlanFieldNames.BAD_IR_SET_ID].append(ir_set_id) tube_label = row.get('tubeLabel', '') if validate_sample_tube_label(tube_label): self.validationErrors[SavePlanFieldNames.BAD_TUBE_LABEL].append(tube_label) chip_barcode = row.get('chipBarcode', '') if validate_chipBarcode(chip_barcode): self.validationErrors[SavePlanFieldNames.BAD_CHIP_BARCODE].append(chip_barcode) if barcodeSet: selectedBarcodes.append(row.get(SavePlanFieldNames.BARCODE_SAMPLE_BARCODE_ID_UI_KEY)) if endBarcodeSet: endBarcode_id_value = row.get(SavePlanFieldNames.BARCODE_SAMPLE_END_BARCODE_ID_UI_KEY) if endBarcode_id_value: selectedEndBarcodes.append(endBarcode_id_value) if any_samples: self.validationErrors.pop(SavePlanFieldNames.NO_SAMPLES, None) else: self.validationErrors[SavePlanFieldNames.NO_SAMPLES] = "You must enter at least one sample" if not self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_NAME]: self.validationErrors.pop(SavePlanFieldNames.BAD_SAMPLE_NAME, None) if not self.validationErrors[SavePlanFieldNames.BAD_TUBE_LABEL]: self.validationErrors.pop(SavePlanFieldNames.BAD_TUBE_LABEL, None) if not self.validationErrors[SavePlanFieldNames.BAD_CHIP_BARCODE]: self.validationErrors.pop(SavePlanFieldNames.BAD_CHIP_BARCODE, None) if not self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID]: self.validationErrors.pop(SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID, None) if not self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION]: self.validationErrors.pop(SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION, None) if not self.validationErrors[SavePlanFieldNames.BAD_IR_SET_ID]: self.validationErrors.pop(SavePlanFieldNames.BAD_IR_SET_ID, None) #20170928-TODO-WIP if barcodeSet: errors = validate_barcode_sample_association(selectedBarcodes, barcodeSet) myErrors = convert(errors) if myErrors.get("MISSING_BARCODE", ""): self.validationErrors[SavePlanFieldNames.NO_BARCODE] = myErrors.get("MISSING_BARCODE", "") if myErrors.get("DUPLICATE_BARCODE", ""): self.validationErrors[SavePlanFieldNames.BAD_BARCODES] = myErrors.get("DUPLICATE_BARCODE", "") if selectedEndBarcodes: applProduct = self.savedObjects[SavePlanFieldNames.APPL_PRODUCT] if applProduct and applProduct.dualBarcodingRule == "no_reuse": errors = validate_barcode_sample_association(selectedEndBarcodes, endBarcodeSet, isEndBarcodeExists = True) myErrors = convert(errors) if myErrors.get("DUPLICATE_BARCODE", ""): self.validationErrors[SavePlanFieldNames.BAD_BARCODES] = myErrors.get("DUPLICATE_BARCODE", "")
def validateStep(self): any_samples = False self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_NAME] = [] self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID] = [] self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION] = [] self.validationErrors[SavePlanFieldNames.BAD_TUBE_LABEL] = [] self.validationErrors[SavePlanFieldNames.BAD_IR_SET_ID] = [] self.validationErrors.pop(SavePlanFieldNames.NO_BARCODE, None) self.validationErrors.pop(SavePlanFieldNames.BAD_BARCODES, None) barcodeSet = self.savedFields[SavePlanFieldNames.BARCODE_SET] selectedBarcodes = [] samplesTable = json.loads(self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]) # logger.debug("save_plan_step_data - anySamples? samplesTable=%s" %(samplesTable)) for row in samplesTable: sample_name = row.get(SavePlanFieldNames.SAMPLE_NAME, "").strip() # logger.debug("save_plan_step_data - anySamples? sampleName=%s" %(sample_name)) if sample_name: any_samples = True if validate_sample_name(sample_name): self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_NAME].append(sample_name) external_id = row.get(SavePlanFieldNames.SAMPLE_EXTERNAL_ID, "") if external_id: self.validate_field(external_id, self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID]) description = row.get(SavePlanFieldNames.SAMPLE_DESCRIPTION, "") if description: self.validate_field( description, self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION], False, MAX_LENGTH_SAMPLE_DESCRIPTION, ) ir_set_id = row.get("irSetId", "") if ir_set_id and not (str(ir_set_id).isdigit()): self.validationErrors[SavePlanFieldNames.BAD_IR_SET_ID].append(ir_set_id) tube_label = row.get("tubeLabel", "") if validate_sample_tube_label(tube_label): self.validationErrors[SavePlanFieldNames.BAD_TUBE_LABEL].append(tube_label) if barcodeSet: selectedBarcodes.append(row.get("barcodeId")) if any_samples: self.validationErrors.pop(SavePlanFieldNames.NO_SAMPLES, None) else: self.validationErrors[SavePlanFieldNames.NO_SAMPLES] = "You must enter at least one sample" if not self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_NAME]: self.validationErrors.pop(SavePlanFieldNames.BAD_SAMPLE_NAME, None) if not self.validationErrors[SavePlanFieldNames.BAD_TUBE_LABEL]: self.validationErrors.pop(SavePlanFieldNames.BAD_TUBE_LABEL, None) if not self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID]: self.validationErrors.pop(SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID, None) if not self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION]: self.validationErrors.pop(SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION, None) if not self.validationErrors[SavePlanFieldNames.BAD_IR_SET_ID]: self.validationErrors.pop(SavePlanFieldNames.BAD_IR_SET_ID, None) if barcodeSet: errors = validate_barcode_sample_association(selectedBarcodes, barcodeSet) myErrors = convert(errors) if myErrors.get("MISSING_BARCODE", ""): self.validationErrors[SavePlanFieldNames.NO_BARCODE] = myErrors.get("MISSING_BARCODE", "") if myErrors.get("DUPLICATE_BARCODE", ""): self.validationErrors[SavePlanFieldNames.BAD_BARCODES] = myErrors.get("DUPLICATE_BARCODE", "")
def get_fixed_designs_list(fixed_design_data): # creates fixed_solutions: a list of dictionaries with : # Design id : Ready-to-Use ampliseq panel ID # Type : Community or Fixed Panel - used to to link to Ampliseq website # Genome : Supported genome by the specific panel. # ChemistryType : Ampliseq or AmpliseqHD # final_fixed_soln_data : #Lists all the design panels available for all the pipeline # fixed_ids_choices : This is used to compare the parametized files available and show the warnings fixed = [] chemistryType = "ampliseq" ampliseq_url = settings.AMPLISEQ_URL fixedDesigns = fixed_design_data.get("TemplateDesigns", []) for template in fixedDesigns: ampliSeq = AmpliSeqPanelImport(data=template) data, meta = ampliSeq.handle_versioned_plans() fixed.append(data) if fixed: ordered_solutions = [] tmpList = [] tmpFixedsolLists = [] fixed_solutions = filter(lambda x: x["status"] == "ORDERABLE", fixed) for design in fixed_solutions: designID = design["id"] sourceUrl = design["resultsUri"] configurationChoices = design["configuration_choices"] uploadHistoryLink = None status = None downloadObj = getASPanelImportStatus("fixed", designID, sourceUrl=sourceUrl) if downloadObj: uploadHistoryLink = "/rundb/uploadstatus/{0}/".format(downloadObj.id) status = downloadObj.status tmpDict = {"id": designID, "configuration_choices": configurationChoices} description = design["description"] rec_app = None if description: desc = re.sub(r"\r\n", "", description.strip()) pattern = ( "<td>\s+<strong>Recommended Application</strong>\s+(.*?)\s+</td>" ) rec_app = re.search(pattern, desc) if rec_app: rec_app = rec_app.group(1) else: description = ( "No description available for this panel from Ampliseq.com" ) panelType = design.get("panelType") or "ready-to-use" tmpFixedSolDict = { "id": designID, "design_id": designID, "displayedID": designID, "solution_id": "", "genome": design["genome"], "name": design["name"], "type": design["type"], "pipeline": design["pipeline"], "ampliseq_url": ampliseq_url, "chemistryType": chemistryType, "panelType": panelType, "status": status, "uploadHistory": uploadHistoryLink, "description": description, "recommended_application": rec_app, } tmpList.append(tmpDict) tmpFixedsolLists.append(tmpFixedSolDict) # This is used to compare the parametized files available and show the warnings fixed_ids_choices = json.dumps(convert(tmpList)) # Lists all the design panels available for the specific pipeline final_fixed_soln_data = tmpFixedsolLists return final_fixed_soln_data, ordered_solutions, fixed_ids_choices
def validateStep(self): any_samples = False self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_NAME] = [] self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID] = [] self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION] = [] self.validationErrors[SavePlanFieldNames.BAD_TUBE_LABEL] = [] self.validationErrors[SavePlanFieldNames.BAD_IR_SET_ID] = [] self.validationErrors.pop(SavePlanFieldNames.NO_BARCODE, None) self.validationErrors.pop(SavePlanFieldNames.BAD_BARCODES, None) barcodeSet = self.savedFields[SavePlanFieldNames.BARCODE_SET] selectedBarcodes = [] samplesTable = json.loads( self.savedFields[SavePlanFieldNames.SAMPLES_TABLE]) #logger.debug("save_plan_step_data - anySamples? samplesTable=%s" %(samplesTable)) for row in samplesTable: sample_name = row.get(SavePlanFieldNames.SAMPLE_NAME, '').strip() #logger.debug("save_plan_step_data - anySamples? sampleName=%s" %(sample_name)) if sample_name: any_samples = True if validate_sample_name(sample_name): self.validationErrors[ SavePlanFieldNames.BAD_SAMPLE_NAME].append(sample_name) external_id = row.get(SavePlanFieldNames.SAMPLE_EXTERNAL_ID, '') if external_id: self.validate_field( external_id, self.validationErrors[ SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID]) description = row.get(SavePlanFieldNames.SAMPLE_DESCRIPTION, '') if description: self.validate_field( description, self.validationErrors[ SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION], False, MAX_LENGTH_SAMPLE_DESCRIPTION) ir_set_id = row.get('irSetId', '') if ir_set_id and not (str(ir_set_id).isdigit()): self.validationErrors[ SavePlanFieldNames.BAD_IR_SET_ID].append(ir_set_id) tube_label = row.get('tubeLabel', '') if validate_sample_tube_label(tube_label): self.validationErrors[ SavePlanFieldNames.BAD_TUBE_LABEL].append(tube_label) if barcodeSet: selectedBarcodes.append(row.get('barcodeId')) if any_samples: self.validationErrors.pop(SavePlanFieldNames.NO_SAMPLES, None) else: self.validationErrors[ SavePlanFieldNames. NO_SAMPLES] = "You must enter at least one sample" if not self.validationErrors[SavePlanFieldNames.BAD_SAMPLE_NAME]: self.validationErrors.pop(SavePlanFieldNames.BAD_SAMPLE_NAME, None) if not self.validationErrors[SavePlanFieldNames.BAD_TUBE_LABEL]: self.validationErrors.pop(SavePlanFieldNames.BAD_TUBE_LABEL, None) if not self.validationErrors[ SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID]: self.validationErrors.pop( SavePlanFieldNames.BAD_SAMPLE_EXTERNAL_ID, None) if not self.validationErrors[ SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION]: self.validationErrors.pop( SavePlanFieldNames.BAD_SAMPLE_DESCRIPTION, None) if not self.validationErrors[SavePlanFieldNames.BAD_IR_SET_ID]: self.validationErrors.pop(SavePlanFieldNames.BAD_IR_SET_ID, None) if barcodeSet: errors = validate_barcode_sample_association( selectedBarcodes, barcodeSet) myErrors = convert(errors) if myErrors.get("MISSING_BARCODE", ""): self.validationErrors[ SavePlanFieldNames.NO_BARCODE] = myErrors.get( "MISSING_BARCODE", "") if myErrors.get("DUPLICATE_BARCODE", ""): self.validationErrors[ SavePlanFieldNames.BAD_BARCODES] = myErrors.get( "DUPLICATE_BARCODE", "")
def get_ampliseq_designs(user, password, api_url): ctx = {} ampliseq_url = settings.AMPLISEQ_URL chemistryType = "Ampliseq" if "hd" in api_url: chemistryType = "AmpliseqHD" response, designs = _get_all_ampliseq_designs(api_url, user, password) if designs: ctx["unordered_solutions"] = [] ctx["ordered_solutions"] = [] unordered_tmpList = [] ordered_tmpList = [] for design in designs: for template in design.get("DesignSolutions", []): ampliSeq = AmpliSeqPanelImport(data=template) solution, meta = ampliSeq.handle_versioned_plans() solution_id = solution["id"] configurationChoices = solution["configuration_choices"] sourceUrl = solution["resultsUri"] uploadHistoryLink = None status = None downloadObj = getASPanelImportStatus( "ordered", design["id"], solution_id, sourceUrl ) if downloadObj: try: uploadHistoryLink = "/rundb/uploadstatus/{0}/".format( downloadObj.id ) status = downloadObj.status except Exception as Err: logger.error( "Unknown error %s" % Err ) # do not crash if any unknown issue if solution.get("ordered", False): panelType = template.get("panelType") or "on-demand" ordered_tmpList.append( { "configuration_choices": configurationChoices, "id": solution_id, "solution_id": solution_id, "displayedID": template.get( "request_id_and_solution_ordering_id", "" ), "design_id": design["id"], "name": template["designName"], "genome": template["genome"], "pipeline": template["pipeline"], "ampliseq_url": ampliseq_url, "chemistryType": chemistryType, "panelType": panelType, "status": status, "uploadHistory": uploadHistoryLink, "recommended_application": "", } ) else: panelType = template.get("panelType") or "made-to-order" unordered_tmpList.append( { "configuration_choices": configurationChoices, "id": solution_id, "displayedID": template.get( "request_id_and_solution_ordering_id", "" ), "solution_id": solution_id, "design_id": design["id"], "name": template["designName"], "genome": template["genome"], "pipeline": template["pipeline"], "ampliseq_url": ampliseq_url, "chemistryType": chemistryType, "panelType": panelType, "status": status, "uploadHistory": uploadHistoryLink, "recommended_application": "", } ) unordered_tmpList = convert(unordered_tmpList) ordered_tmpList = convert(ordered_tmpList) ctx["unordered_solutions"] = unordered_tmpList ctx["ordered_solutions"] = ordered_tmpList return ctx else: return {}