def test_set_placements_list(self):
        a1 = Artifact(uri='http://testgenologics.com:4040/artifacts/a1', lims=self.lims)
        a2 = Artifact(uri='http://testgenologics.com:4040/artifacts/a2', lims=self.lims)
        c1 = Container(uri='http://testgenologics.com:4040/containers/c1', lims=self.lims)
        c2 = Container(uri='http://testgenologics.com:4040/containers/c2', lims=self.lims)

        s = StepPlacements(uri=self.lims.get_uri('steps', 's1', 'placements'), lims=self.lims)
        with patch('requests.Session.get',
                   return_value=Mock(content=self.original_step_placements_xml, status_code=200)):
            new_placements = [[a1, (c1, '3:1')], [a2, (c1, '4:1')]]
            s.set_placement_list(new_placements)
            assert elements_equal(s.root, ElementTree.fromstring(self.modloc_step_placements_xml))
Beispiel #2
0
 def __get__(self, instance, cls):
     from genologics.entities import Container
     instance.get()
     node = instance.root.find(self.tag)
     if node is None:
         return (None, None)
     uri = node.find('container').attrib['uri']
     return Container(instance.lims, uri=uri), node.find('value').text
Beispiel #3
0
 def save_containers(self, container_details: ObjectifiedElement):
     """Save a batch of containers."""
     container_uri = f"{self.get_uri()}/containers/batch/create"
     results = self.save_xml(container_uri, container_details)
     container_map = {}
     for link in results.findall("link"):
         lims_container = Container(self, uri=link.attrib["uri"])
         container_map[lims_container.name] = lims_container
     return container_map
 def test_get_placements_list(self):
     s = StepPlacements(uri=self.lims.get_uri('steps', 's1', 'placements'), lims=self.lims)
     with patch('requests.Session.get',
                return_value=Mock(content=self.original_step_placements_xml, status_code=200)):
         a1 = Artifact(uri='http://testgenologics.com:4040/artifacts/a1', lims=self.lims)
         a2 = Artifact(uri='http://testgenologics.com:4040/artifacts/a2', lims=self.lims)
         c1 = Container(uri='http://testgenologics.com:4040/containers/c1', lims=self.lims)
         expected_placements = [[a1, (c1, '1:1')], [a2, (c1, '2:1')]]
         assert s.get_placement_list() == expected_placements
 def test_create_entity(self):
     with patch('genologics.lims.requests.post',
                return_value=Mock(content=self.sample_creation, status_code=201)) as patch_post:
         l = Sample.create(
             self.lims,
             project=Project(self.lims, uri='project'),
             container=Container(self.lims, uri='container'),
             position='1:1',
             name='s1',
         )
         data = '''<?xml version=\'1.0\' encoding=\'utf-8\'?>
         <smp:samplecreation xmlns:smp="http://genologics.com/ri/sample">
         <name>s1</name>
         <project uri="project" limsid="project" />
         <location>
           <container uri="container" />
           <value>1:1</value>
         </location>
         </smp:samplecreation>'''
         assert elements_equal(ElementTree.fromstring(patch_post.call_args_list[0][1]['data']),
                               ElementTree.fromstring(data))
Beispiel #6
0
    def get(self):
        limsl = lims.Lims(BASEURI, USERNAME, PASSWORD)
        #qPCR queues
        queues = {}
        queues['MiSeq'] = Queue(limsl, id='1002')
        queues['NovaSeq'] = Queue(limsl, id='1666')
        queues['LibraryValidation'] = Queue(limsl, id='41')

        methods = queues.keys()
        pools = {}

        for method in methods:
            pools[method] = {}
            if queues[method].artifacts:
                tree = ET.fromstring(queues[method].xml())
                if tree.find('next-page') is not None:
                    flag = True
                    next_page_uri = tree.find('next-page').attrib['uri']
                    while flag:
                        next_page = ET.fromstring(
                            Queue(limsl, uri=next_page_uri).xml())
                        for elem in next_page.findall('artifacts'):
                            tree.insert(0, elem)
                        if next_page.find('next-page') is not None:
                            next_page_uri = next_page.find(
                                'next-page').attrib['uri']
                        else:
                            flag = False
                for artifact in tree.iter('artifact'):
                    queue_time = artifact.find('queue-time').text
                    container = Container(limsl,
                                          uri=artifact.find('location').find(
                                              'container').attrib['uri']).name
                    art = Artifact(limsl, uri=artifact.attrib['uri'])
                    value = artifact.find('location').find('value').text
                    library_type = ''
                    runmode = ''
                    if not 'lambda DNA' in art.name:
                        library_type = art.samples[0].project.udf[
                            "Library construction method"]
                        try:
                            runmode = art.samples[0].project.udf[
                                'Sequencing platform']
                        except KeyError:
                            runmode = 'NA'
                    if container in pools[method]:
                        pools[method][container]['samples'].append({
                            'name':
                            art.name,
                            'well':
                            value,
                            'queue_time':
                            queue_time
                        })
                        if library_type and library_type not in pools[method][
                                container]['library_types']:
                            pools[method][container]['library_types'].append(
                                library_type)
                        if runmode and runmode not in pools[method][container][
                                'runmodes']:
                            pools[method][container]['runmodes'].append(
                                runmode)
                    else:
                        pools[method][container] = {
                            'samples': [{
                                'name': art.name,
                                'well': value,
                                'queue_time': queue_time
                            }],
                            'library_types': [library_type],
                            'runmodes': [runmode]
                        }

        self.set_header("Content-type", "application/json")
        self.write(json.dumps(pools))
Beispiel #7
0
    def get(self):
        limsl = lims.Lims(BASEURI, USERNAME, PASSWORD)
        #sequencing queues are currently taken as the following
        #Miseq- Step 7: Denature, Dilute and load sample
        #Novaseq Step 11: Load to flow cell
        queues = {}
        queues['MiSeq'] = Queue(limsl, id='55')
        queues['NovaSeq'] = Queue(limsl, id='1662')

        methods = queues.keys()
        pools = {}

        for method in methods:
            pools[method] = {}
            if queues[method].artifacts:
                tree = ET.fromstring(queues[method].xml())
                for artifact in tree.iter('artifact'):
                    queue_time = artifact.find('queue-time').text
                    container = Container(limsl,
                                          uri=artifact.find('location').find(
                                              'container').attrib['uri']).name
                    attr_name = Artifact(limsl,
                                         uri=artifact.attrib['uri']).name
                    value = artifact.find('location').find('value').text
                    proj_and_samples = {}
                    conc_qpcr = ''
                    is_rerun = False
                    art = Artifact(limsl, uri=artifact.attrib['uri'])
                    if method is 'MiSeq':
                        #FinishedLibrary
                        if 'Concentration' in dict(art.udf.items()).keys():
                            conc_qpcr = art.udf['Concentration']
                        #InhouseLibrary
                        elif 'Pool Conc. (nM)' in dict(art.udf.items()).keys():
                            conc_qpcr = str(art.udf['Pool Conc. (nM)'])
                        else:
                            pass
                        is_rerun = art.udf["Rerun"]
                    elif method is 'NovaSeq':
                        if 'Concentration' in dict(art.udf.items()).keys():
                            conc_qpcr = art.udf["Concentration"]
                            if 'Rerun' in dict(art.udf.items()).keys():
                                is_rerun = art.udf["Rerun"]
                        else:
                            new_art = art.parent_process.input_output_maps[0][
                                0]
                            # The loop iterates 4 times as the values were found within the first 4 preceding
                            # parent processes(through trial and error). If the values are not found within 4 iterations, they can be looked up
                            # manually in LIMS. The loop is structured so as its not very clear in the genologics API which of the parent processes
                            # will contain the values in post process and 4 seemed to get everything for the data at hand.
                            i = 0
                            while i < 4:
                                if 'Concentration' in dict(
                                        new_art['post-process-uri'].udf.items(
                                        )).keys():
                                    conc_qpcr = new_art[
                                        'post-process-uri'].udf[
                                            "Concentration"]
                                    if 'Rerun' in dict(
                                            new_art['post-process-uri'].udf.
                                            items()).keys():
                                        is_rerun = new_art[
                                            'post-process-uri'].udf["Rerun"]
                                    break
                                else:
                                    new_art = new_art[
                                        'parent-process'].input_output_maps[0][
                                            0]
                                    i = i + 1

                    for sample in art.samples:
                        project = sample.project.id
                        if project in pools[method]:
                            if container in pools[method][project]['plates']:
                                pools[method][project]['plates'][container][
                                    'samples'].append(sample.name)
                            else:
                                pools[method][project]['plates'][container] = {
                                    'samples': [sample.name],
                                    'well': value,
                                    'queue_time': queue_time,
                                    'conc_pool_qpcr': conc_qpcr,
                                    'is_rerun': is_rerun
                                }
                        else:
                            setup = sample.project.udf['Sequencing setup']
                            lanes = sample.project.udf[
                                'Sequence units ordered (lanes)']
                            librarytype = sample.project.udf[
                                'Library construction method']
                            runmode = sample.project.udf['Sequencing platform']
                            final_loading_conc = 'TBD'
                            if method is 'NovaSeq':
                                try:
                                    final_loading_conc = Artifact(
                                        limsl, uri=artifact.attrib['uri']
                                    ).udf['Final Loading Concentration (pM)']
                                except KeyError:
                                    pass
                            pools[method][project] = {
                                'name': sample.project.name,
                                'setup': setup,
                                'lanes': lanes,
                                'runmode': runmode,
                                'final_loading_conc': final_loading_conc,
                                'librarytype': librarytype,
                                'plates': {
                                    container: {
                                        'samples': [sample.name],
                                        'well': value,
                                        'queue_time': queue_time,
                                        'conc_pool_qpcr': conc_qpcr,
                                        'is_rerun': is_rerun
                                    }
                                }
                            }
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(pools))
Beispiel #8
0
    def get(self):
        limsl = lims.Lims(BASEURI, USERNAME, PASSWORD)
        #qPCR queues
        queues = {}
        queues['MiSeq'] = Queue(limsl, id='1002')
        queues['NovaSeq'] = Queue(limsl, id='1666')
        queues['LibraryValidation'] = Queue(limsl, id='41')

        methods = queues.keys()
        pools = {}
        qpcr_control_names = [
            'AM7852', 'E.Coli genDNA', 'Endogenous Positive Control',
            'Exogenous Positive Control', 'Human Brain Reference RNA',
            'lambda DNA', 'mQ Negative Control', 'NA10860', 'NA11992',
            'NA11993', 'NA12878', 'NA12891', 'NA12892',
            'No Amplification Control', 'No Reverse Transcriptase Control',
            'No Template Control', 'PhiX v3', 'Universal Human Reference RNA',
            'lambda DNA (qPCR)'
        ]
        for method in methods:
            pools[method] = {}
            if queues[method].artifacts:
                tree = ET.fromstring(queues[method].xml())
                if tree.find('next-page') is not None:
                    flag = True
                    next_page_uri = tree.find('next-page').attrib['uri']
                    while flag:
                        next_page = ET.fromstring(
                            Queue(limsl, uri=next_page_uri).xml())
                        for elem in next_page.findall('artifacts'):
                            tree.insert(0, elem)
                        if next_page.find('next-page') is not None:
                            next_page_uri = next_page.find(
                                'next-page').attrib['uri']
                        else:
                            flag = False
                for artifact in tree.iter('artifact'):
                    queue_time = artifact.find('queue-time').text
                    container = Container(limsl,
                                          uri=artifact.find('location').find(
                                              'container').attrib['uri']).name
                    art = Artifact(limsl, uri=artifact.attrib['uri'])
                    value = artifact.find('location').find('value').text
                    library_type = ''
                    runmode = ''

                    #skip if the Artifact is a control
                    if art.name in qpcr_control_names:
                        continue

                    library_type = art.samples[0].project.udf.get(
                        "Library construction method", 'NA')
                    try:
                        runmode = art.samples[0].project.udf[
                            'Sequencing platform']
                    except KeyError:
                        runmode = 'NA'
                    if container in pools[method]:
                        pools[method][container]['samples'].append({
                            'name':
                            art.name,
                            'well':
                            value,
                            'queue_time':
                            queue_time
                        })
                        if library_type and library_type not in pools[method][
                                container]['library_types']:
                            pools[method][container]['library_types'].append(
                                library_type)
                        if runmode and runmode not in pools[method][container][
                                'runmodes']:
                            pools[method][container]['runmodes'].append(
                                runmode)
                    else:
                        pools[method][container] = {
                            'samples': [{
                                'name': art.name,
                                'well': value,
                                'queue_time': queue_time
                            }],
                            'library_types': [library_type],
                            'runmodes': [runmode]
                        }

        self.set_header("Content-type", "application/json")
        self.write(json.dumps(pools))
def main(args):
    lims = Lims(BASEURI, USERNAME, PASSWORD)
    cont = Container(lims, id=args.flowcell)
    cont.name = cont.id
    cont.put()