def route_to_workflow(lims, process_id, workflow): """Route artifacts to a workflow.""" process = Process(lims, id=process_id) # Get all artifacts with workflow status == completed. artifacts_completed = [ action_artifact['artifact'] for action_artifact in process.step.actions.get_next_actions() if action_artifact['action'] == 'complete' ] if workflow == 'post_bioinf': # Remove research artifacts route_artifacts = [ artifact for artifact in artifacts_completed if artifact.samples[0].udf['Dx Stoftest code'] != config.research_stoftest_code ] lims.route_artifacts(route_artifacts, workflow_uri=Workflow( lims, id=config.post_bioinf_workflow).uri) elif workflow == 'sequencing': lims.route_artifacts(artifacts_completed, workflow_uri=Workflow( lims, id=config.sequencing_workflow).uri)
def _get_current_WF(self): art = self.process.all_inputs()[0] art_XML = api.GET(APIURI + 'artifacts/' + art.id) art_dom = parseString( art_XML ) WF_node = art_dom.getElementsByTagName('workflow-stage')[-1] wf_id = WF_node.getAttribute('uri').split('/stages/')[0].split('/')[-1] try: return Workflow(lims,id = wf_id) except: sys.exit('Could not get the current Work Flow. Contact lims developer.')
def unpooling(lims, process_id): """Unpool samples after sequencing.""" process = Process(lims, id=process_id) pool_artifact = process.all_inputs()[0] pool_artifact_parent_process = pool_artifact.parent_process pool_artifact_demux = lims.get(pool_artifact.uri + '/demux') run_id = pool_artifact.name # Assume run id is set as pool name using placement/artifact/set_runid_name sample_artifacts = [] # sample artifacts before pooling sample_projects = {} for artifact in pool_artifact_parent_process.result_files(): if (artifact.name == 'SampleSheet csv' or artifact.name == 'Sample Sheet') and artifact.files: file_id = artifact.files[0].id sample_sheet = lims.get_file_contents(id=file_id) project_index = None sample_index = None for line in sample_sheet.split('\n'): data = line.rstrip().split(',') if 'Sample_Project' in data and 'Sample_ID' in data: project_index = data.index('Sample_Project') sample_index = data.index('Sample_ID') elif project_index and len(data) >= project_index: sample_projects[data[sample_index]] = data[project_index] for node in pool_artifact_demux.getiterator('artifact'): if node.find('samples'): if len(node.find('samples').findall('sample')) == 1: sample_artifact = Artifact(lims, uri=node.attrib['uri']) sample = sample_artifact.samples[0] # 1 sample per artifact. # Get sample sequencing run and project from samplesheet sample_artifact.udf['Dx Sequencing Run ID'] = run_id if 'Sample Type' in sample.udf and 'library' in sample.udf[ 'Sample Type']: # Use sample.name for external (clarity_portal) samples sample_artifact.udf[ 'Dx Sequencing Run Project'] = sample_projects[ sample.name] else: # Use sample_artifact.name for Dx samples (upload via Helix) sample_artifact.udf[ 'Dx Sequencing Run Project'] = sample_projects[ sample_artifact.name] sample_artifact.put() if sample_artifact.samples[ 0].project and sample_artifact.samples[0].project.udf[ 'Application'] == 'DX': # Only move DX production samples to post sequencing workflow sample_artifacts.append(sample_artifact) lims.route_artifacts(sample_artifacts, workflow_uri=Workflow( lims, id=config.post_sequencing_workflow).uri)
def get_current_WF(self): # This should be done in a better way... # pick any art from the current wf: art = self.input_arts[0] art_XML = api.GET(APIURI + 'artifacts/' + art.id) art_dom = parseString(art_XML) # look for the last "workflow-stage" node, since that's # where we currently are WF_node = art_dom.getElementsByTagName('workflow-stage')[-1] wf_id = WF_node.getAttribute('uri').split('/stages/')[0].split('/')[-1] self.current_WF = Workflow(lims, id=wf_id) if not self.current_WF: sys.exit( 'Could not get the current Work Flow. Contact lims developer.')
def submit_dx_samples(): form = SubmitDXSampleForm() if form.validate_on_submit(): container_type = Containertype(lims, id='2') # Tube workflow = Workflow(lims, id=app.config['LIMS_DX_SAMPLE_SUBMIT_WORKFLOW']) for sample_name in form.parsed_samples: # Get or create project lims_projects = lims.get_projects(name=form.parsed_samples[sample_name]['project']) if not lims_projects: lims_project = Project.create(lims, name=form.parsed_samples[sample_name]['project'], researcher=form.researcher, udf={'Application': 'DX'}) else: lims_project = lims_projects[0] # Set sample udf data udf_data = form.parsed_worklist[sample_name] udf_data['Sample Type'] = form.parsed_samples[sample_name]['type'] udf_data['Dx Fragmentlengte (bp) Externe meting'] = form.pool_fragment_length.data udf_data['Dx Conc. (ng/ul) Externe meting'] = form.pool_concentration.data udf_data['Dx Exoomequivalent'] = form.parsed_samples[sample_name]['exome_count'] # Create sample container = Container.create(lims, type=container_type, name=udf_data['Dx Fractienummer']) sample = Sample.create(lims, container=container, position='1:1', project=lims_project, name=sample_name, udf=udf_data) print sample.name, sample.artifact.name # Add reagent label (barcode) artifact = sample.artifact artifact_xml_dom = minidom.parseString(artifact.xml()) for artifact_name_node in artifact_xml_dom.getElementsByTagName('name'): parent = artifact_name_node.parentNode reagent_label = artifact_xml_dom.createElement('reagent-label') reagent_label.setAttribute('name', form.parsed_samples[sample_name]['barcode']) parent.appendChild(reagent_label) lims.put(artifact.uri, artifact_xml_dom.toxml(encoding='utf-8')) lims.route_artifacts([sample.artifact], workflow_uri=workflow.uri) return render_template('submit_dx_samples_done.html', title='Submit DX samples', project_name=lims_project.name, form=form) return render_template('submit_dx_samples.html', title='Submit DX samples', form=form)
def stoftestcode_to_workflow(lims, stoftestcode): """Return workflow based on helix stoftestcode.""" if stoftestcode in config.stoftestcode_workflow: return Workflow(lims, id=config.stoftestcode_workflow[stoftestcode]) else: return None
def submit_samples(): form = SubmitSampleForm() if form.validate_on_submit(): # Create lims project lims_project = Project.create( lims, name=app.config['LIMS_INDICATIONS'][form.indicationcode.data]['project_name_prefix'], researcher=form.researcher, udf={'Application': form.indicationcode.data} ) lims_project.name = '{0}_{1}'.format(lims_project.name, lims_project.id) lims_project.put() # Save attachment attachment = form.attachment.data if attachment: temp_dir = mkdtemp() attachment_path = path.join(temp_dir, secure_filename(attachment.filename)) attachment.save(attachment_path) print attachment_path lims.upload_new_file(lims_project, attachment_path) rmtree(temp_dir) # Create Samples lims_container_type = Containertype(lims, id='2') # Tube sample_artifacts = [] for sample in form.parsed_samples: lims_container = Container.create(lims, type=lims_container_type, name=sample['name']) sample_udf_data = { 'Sample Type': 'DNA library', 'Dx Fragmentlengte (bp) Externe meting': form.pool_fragment_length.data, 'Dx Conc. (ng/ul) Externe meting': form.pool_concentration.data, 'Dx Exoomequivalent': sample['exome_count'], } lims_sample = Sample.create(lims, container=lims_container, position='1:1', project=lims_project, name=sample['name'], udf=sample_udf_data) print lims_sample.name, lims_sample.artifact.name artifact = lims_sample.artifact sample_artifacts.append(artifact) # Add reagent label (barcode) artifact_xml_dom = minidom.parseString(artifact.xml()) for artifact_name_node in artifact_xml_dom.getElementsByTagName('name'): parent = artifact_name_node.parentNode reagent_label = artifact_xml_dom.createElement('reagent-label') reagent_label.setAttribute('name', sample['barcode']) parent.appendChild(reagent_label) lims.put(artifact.uri, artifact_xml_dom.toxml(encoding='utf-8')) # Route artifacts to workflow workflow = Workflow(lims, id=app.config['LIMS_INDICATIONS'][form.indicationcode.data]['workflow_id']) lims.route_artifacts(sample_artifacts, workflow_uri=workflow.uri) # Send email subject = "Clarity Portal Sample Upload - {0}".format(lims_project.name) message = "Gebruikersnaam\t{0}\n".format(form.username.data) message += "Indicatie code\t{0}\n".format(form.indicationcode.data) message += "Lims Project naam\t{0}\n".format(lims_project.name) message += "Pool - Fragment lengte\t{0}\n".format(form.pool_fragment_length.data) message += "Pool - Concentratie\t{0}\n".format(form.pool_concentration.data) message += "Pool - Exoom equivalenten\t{0}\n\n".format(form.sum_exome_count) message += "Sample naam\tBarcode\tExome equivalenten\tSample type\n" for sample in form.parsed_samples: message += "{0}\t{1}\t{2}\t{3}\n".format(sample['name'], sample['barcode'], sample['exome_count'], sample['type']) send_email(app.config['EMAIL_FROM'], app.config['LIMS_INDICATIONS'][form.indicationcode.data]['email_to'], subject, message) return render_template('submit_samples_done.html', title='Submit samples', project_name=lims_project.name, form=form) return render_template('submit_samples.html', title='Submit samples', form=form)
import config # Setup lims connection baseuri = 'https://usf-lims.umcutrecht.nl' username = '******' password = '******' lims = Lims(baseuri, username, password) old_queue = Queue( lims, id='' ) # Example: Dx Sample registratie zuivering v1.0 = 1142 (same as step id) old_stage = Stage( lims, uri='' ) # Example: Dx Sample registratie zuivering v1.0 = https://usf-lims.umcutrecht.nl/api/v2/configuration/workflows/751/stages/2119 new_workflow = Workflow(lims, id='') # Example: Dx Exoom KAPA v1.6 = 901 skip_artifacts = [''] # Add samples that should not be moved to new workflow artifacts = [] print '# Old queue:', len(old_queue.artifacts) for artifact in old_queue.artifacts: if artifact.name not in skip_artifacts: print 'Move:', artifact.name artifacts.append(artifact) else: print 'Keep:', artifact.name print '# Move to new workflow:', len(artifacts) # Move things to new workflow, uncomment to enable.