Exemplo n.º 1
0
def create_sequencing_process(user, pools):
    seq_process = SequencingProcess.create(
        user, pools, 'New sequencing run %s' % datetime.now(),
        'Run experiment %s' % datetime.now(), Equipment(18), 151, 151,
        User('*****@*****.**'),
        contacts=[User('*****@*****.**'), User('*****@*****.**')])
    return seq_process
Exemplo n.º 2
0
    def post(self):
        email = self.get_argument('email')
        op = self.get_argument('operation')

        if op == 'grant':
            User(email).grant_access()
        elif op == 'revoke':
            User(email).revoke_access()
        else:
            raise HTTPError(400, 'Operation %s not recognized')

        self.finish()
Exemplo n.º 3
0
 def test_attributes(self):
     s = Study(1)
     self.assertEqual(
         s.title, 'Identification of the Microbiomes '
         'for Cannabis Soils')
     self.assertEqual(s.creator, User('*****@*****.**'))
     self.assertEqual(s.num_samples, 27)
Exemplo n.º 4
0
    def test_plate_handler_patch_request(self):
        tester = Plate(21)
        user = User('*****@*****.**')

        # Incorrect path parameter
        regex = 'Incorrect path parameter'
        with self.assertRaisesRegex(HTTPError, regex):
            plate_handler_patch_request(user, 21, 'replace', '/name/newname',
                                        'NewName', None)

        # Unknown attribute
        regex = 'Attribute unknown not recognized'
        with self.assertRaisesRegex(HTTPError, regex):
            plate_handler_patch_request(user, 21, 'replace', '/unknown/',
                                        'NewName', None)

        # Unknown operation
        regex = ('Operation add not supported. Current supported '
                 'operations: replace')
        with self.assertRaisesRegex(HTTPError, regex):
            plate_handler_patch_request(user, 21, 'add', '/name/', 'NewName',
                                        None)

        # Plate doesn't exist
        regex = 'Plate 100 doesn\'t exist'
        with self.assertRaisesRegex(HTTPError, regex):
            plate_handler_patch_request(user, 100, 'replace', '/name/',
                                        'NewName', None)

        # Test success - Name
        plate_handler_patch_request(user, 21, 'replace', '/name/', 'NewName',
                                    None)
        self.assertEqual(tester.external_id, 'NewName')
        tester.external_id = 'Test plate 1'
Exemplo n.º 5
0
def stress_tests(num_plates):
    """Creates num_plates plates and complete the amplicon/shotgun workflow
    """
    samples = get_samples()
    user = User('*****@*****.**')
    stress_tests_amplicon_workflow(user, samples, num_plates=num_plates)
    stress_tests_shotgun_workflow(user, samples, num_plates=num_plates)
Exemplo n.º 6
0
 def post(self):
     pool_id = self.get_argument('pool')
     run_name = self.get_argument('run_name')
     sequencer_id = self.get_argument('sequencer')
     fwd_cycles = int(self.get_argument('fwd_cycles'))
     rev_cycles = int(self.get_argument('rev_cycles'))
     assay = self.get_argument('assay')
     pi = self.get_argument('principal_investigator')
     c0 = self.get_argument('contact_0')
     c1 = self.get_argument('contact_1')
     c2 = self.get_argument('contact_2')
     process = SequencingProcess.create(
         self.current_user, PoolComposition(pool_id), run_name,
         Equipment(sequencer_id), fwd_cycles, rev_cycles, assay,
         User(pi), User(c0), User(c1), User(c2))
     self.write({'process': process.id})
Exemplo n.º 7
0
    def post(self):
        pools = self.get_argument('pools')
        run_name = self.get_argument('run_name')
        experiment = self.get_argument('experiment')
        sequencer_id = self.get_argument('sequencer')
        fwd_cycles = int(self.get_argument('fwd_cycles'))
        rev_cycles = int(self.get_argument('rev_cycles'))
        pi = self.get_argument('principal_investigator')
        contacts = self.get_argument('additional_contacts')

        pools = [PoolComposition(x) for x in json_decode(pools)]
        contacts = [User(x) for x in json_decode(contacts)]

        process = SequencingProcess.create(self.current_user, pools,
                                           run_name, experiment,
                                           Equipment(sequencer_id), fwd_cycles,
                                           rev_cycles, User(pi), contacts)
        self.write({'process': process.id})
Exemplo n.º 8
0
 def get_current_user(self):
     """Get the current connected user"""
     username = self.get_secure_cookie("user")
     if username is not None:
         # strip off quotes added by get_secure_cookie and decode
         # becuase it is stored as character varying in the DB
         return User(username.strip(b"\"' ").decode())
     else:
         self.clear_cookie("user")
         return None
Exemplo n.º 9
0
    def test_login(self):
        exp = User('*****@*****.**')
        obs = User.login('*****@*****.**', 'password')
        self.assertEqual(obs, exp)

        with self.assertRaises(LabmanUnknownIdError):
            User.login('*****@*****.**', 'password')

        with self.assertRaises(LabmanLoginError):
            User.login('*****@*****.**', 'wrongpassword')
Exemplo n.º 10
0
def integration_tests():
    """Creates one amplicon and one shotgun workflow from plating to sequencing
    """
    samples = get_samples()
    user = User('*****@*****.**')

    amplicon_seq_process = integration_tests_amplicon_workflow(user, samples)
    obs = amplicon_seq_process.generate_sample_sheet()
    res = re.match(EXP_AMPLICON_SAMPLE_SHEET, obs)
    if res is None:
        raise ValueError(
            'Amplicon sample sheet does not match expected regex:\n%s' % obs)
Exemplo n.º 11
0
    def test_sample_plating_process_handler_patch_request(self):
        user = User('*****@*****.**')
        # Test operation not supported
        regex = ('Operation add not supported. Current supported '
                 'operations: replace')
        with self.assertRaisesRegex(HTTPError, regex):
            sample_plating_process_handler_patch_request(
                user, 10, 'add', '/well/8/1/', '1.SKM8.640201', None)

        # Test incorrect path parameter
        regex = 'Incorrect path parameter'
        with self.assertRaisesRegex(HTTPError, regex):
            sample_plating_process_handler_patch_request(
                user, 10, 'replace', '/8/1/', '1.SKM8.640201', None)
        with self.assertRaisesRegex(HTTPError, regex):
            sample_plating_process_handler_patch_request(
                user, 10, 'replace', '/well/8/1/content', '1.SKM8.640201',
                None)

        # Test attribute not found
        regex = 'Attribute content not found'
        with self.assertRaisesRegex(HTTPError, regex):
            sample_plating_process_handler_patch_request(
                user, 10, 'replace', '/content/8/1/', '1.SKM8.640201', None)

        # Test missing req_value
        regex = 'A new value for the well should be provided'
        with self.assertRaisesRegex(HTTPError, regex):
            sample_plating_process_handler_patch_request(
                user, 10, 'replace', '/well/8/1/', None, None)
        with self.assertRaisesRegex(HTTPError, regex):
            sample_plating_process_handler_patch_request(
                user, 10, 'replace', '/well/8/1/', '', None)
        with self.assertRaisesRegex(HTTPError, regex):
            sample_plating_process_handler_patch_request(
                user, 10, 'replace', '/well/8/1/', '  ', None)

        # Test success
        obs = SampleComposition(85)
        self.assertEqual(obs.sample_composition_type, 'blank')
        self.assertIsNone(obs.sample_id)

        sample_plating_process_handler_patch_request(
            user, 10, 'replace', '/well/8/1/', '1.SKM8.640201', None)
        self.assertEqual(obs.sample_composition_type, 'experimental sample')
        self.assertEqual(obs.sample_id, '1.SKM8.640201')

        sample_plating_process_handler_patch_request(
            user, 10, 'replace', '/well/8/1/', 'blank', None)
        self.assertEqual(obs.sample_composition_type, 'blank')
        self.assertIsNone(obs.sample_id)
Exemplo n.º 12
0
def stress_tests(num_plates_amplicon, num_plates_shotgun, user):
    """Creates num_plates plates and complete the amplicon/shotgun workflow
    """
    samples = get_samples()
    user = User(user)

    if num_plates_amplicon:
        stress_tests_amplicon_workflow(user,
                                       samples,
                                       num_plates=num_plates_amplicon)
    if num_plates_shotgun:
        stress_tests_shotgun_workflow(user,
                                      samples,
                                      num_plates=num_plates_shotgun)
Exemplo n.º 13
0
    def test_get_previously_plated_wells(self):
        tester = Plate(21)
        three_plates_list = [Plate(27), Plate(30), Plate(33)]
        exp = {Well(3073): three_plates_list, Well(3079): three_plates_list,
               Well(3085): three_plates_list, Well(3091): three_plates_list,
               Well(3097): three_plates_list, Well(3103): three_plates_list,
               Well(3121): three_plates_list, Well(3127): three_plates_list,
               Well(3133): three_plates_list, Well(3139): three_plates_list,
               Well(3145): three_plates_list, Well(3151): three_plates_list,
               Well(3169): three_plates_list, Well(3175): three_plates_list,
               Well(3181): three_plates_list, Well(3187): three_plates_list,
               Well(3193): three_plates_list, Well(3199): three_plates_list,
               Well(3217): three_plates_list, Well(3223): three_plates_list,
               Well(3229): three_plates_list, Well(3235): three_plates_list,
               Well(3241): three_plates_list, Well(3247): three_plates_list,
               Well(3265): three_plates_list, Well(3271): three_plates_list,
               Well(3277): three_plates_list, Well(3283): three_plates_list,
               Well(3289): three_plates_list, Well(3295): three_plates_list,
               Well(3313): three_plates_list, Well(3319): three_plates_list,
               Well(3325): three_plates_list, Well(3331): three_plates_list,
               Well(3337): three_plates_list, Well(3343): three_plates_list,
               Well(3361): three_plates_list, Well(3367): three_plates_list,
               Well(3373): three_plates_list, Well(3379): three_plates_list,
               Well(3385): three_plates_list, Well(3391): three_plates_list,
               Well(3409): three_plates_list, Well(3415): three_plates_list,
               Well(3421): three_plates_list, Well(3427): three_plates_list,
               Well(3433): three_plates_list, Well(3439): three_plates_list,
               Well(3457): three_plates_list, Well(3463): three_plates_list,
               Well(3469): three_plates_list, Well(3475): three_plates_list,
               Well(3481): three_plates_list, Well(3487): three_plates_list,
               Well(3505): three_plates_list, Well(3511): three_plates_list,
               Well(3517): three_plates_list, Well(3523): three_plates_list,
               Well(3529): three_plates_list, Well(3535): three_plates_list,
               Well(3553): three_plates_list, Well(3559): three_plates_list,
               Well(3565): three_plates_list, Well(3571): three_plates_list,
               Well(3577): three_plates_list, Well(3583): three_plates_list,
               Well(3601): three_plates_list, Well(3607): three_plates_list,
               Well(3613): three_plates_list, Well(3619): three_plates_list,
               Well(3625): three_plates_list}
        obs = tester.get_previously_plated_wells()
        self.assertEqual(obs, exp)

        # Create another plate and put a sample on it that isn't anywhere else
        spp = SamplePlatingProcess.create(
            User('*****@*****.**'), PlateConfiguration(1), 'New Plate For Prev')
        spp.update_well(1, 1, '1.SKM1.640184')
        obs = spp.plate.get_previously_plated_wells()
        self.assertEqual(obs, {})
Exemplo n.º 14
0
def integration_tests():
    samples = get_samples()
    user = User('*****@*****.**')
    amplicon_seq_process = amplicon_workflow(user, samples)
    shotgun_seq_process = shotgun_workflow(user, samples)

    obs = amplicon_seq_process.generate_sample_sheet()
    res = re.match(EXP_AMPLICON_SAMPLE_SHEET, obs)
    if res is None:
        raise ValueError(
            'Amplicon sample sheet does not match expected regex:\n%s' % obs)

    obs = shotgun_seq_process.generate_sample_sheet()
    res = re.match(EXP_SHOTGUN_SAMPLE_SHEET, obs)
    if res is None:
        raise ValueError(
            'Shotgun sample sheet does not match expected regex:\n%s' % obs)
Exemplo n.º 15
0
    def test_get_previously_plated_wells(self):
        tester = Plate(21)
        self.assertEqual(tester.get_previously_plated_wells(), {})

        # Create another plate and plate some samples in it
        spp = SamplePlatingProcess.create(
            User('*****@*****.**'), PlateConfiguration(1), 'New Plate For Prev')
        spp.update_well(1, 1, '1.SKD1.640179')
        exp = {}
        plate = spp.plate
        exp[Well(3208)] = [plate]
        exp[Well(3388)] = [plate]
        exp[Well(3568)] = [plate]
        exp[Well(3748)] = [plate]
        exp[Well(3928)] = [plate]
        exp[Well(4108)] = [plate]
        obs = tester.get_previously_plated_wells()
        self.assertEqual(obs, exp)
Exemplo n.º 16
0
 def test_attributes(self):
     s = Study(1)
     self.assertEqual(s.title, 'Identification of the Microbiomes '
                               'for Cannabis Soils')
     self.assertEqual(s.creator, User('*****@*****.**'))
     self.assertEqual(s.num_samples, 27)
     exp = {'num_samples': 27,
            'number_samples_plated': 6,
            'number_samples_extracted': 6,
            'number_samples_amplicon_libraries': 6,
            'number_samples_amplicon_pools': 6,
            'number_samples_amplicon_sequencing_pools': 6,
            'number_samples_amplicon_sequencing_runs': 6,
            'number_samples_compressed': 6,
            'number_samples_normalized': 6,
            'number_samples_shotgun_libraries': 6,
            'number_samples_shotgun_pool': 6,
            'number_samples_shotgun_sequencing_runs': 6}
     self.assertEqual(s.sample_numbers_summary, exp)
Exemplo n.º 17
0
    def test_access_handler_post(self):
        tester = User('*****@*****.**')
        response = self.post('/auth/access/', {
            'email': '*****@*****.**',
            'operation': 'grant'
        })
        self.assertEqual(response.code, 200)
        self.assertEqual(User.login('*****@*****.**', 'password'), tester)

        response = self.post('/auth/access/', {
            'email': '*****@*****.**',
            'operation': 'revoke'
        })
        self.assertEqual(response.code, 200)
        with self.assertRaises(LabmanLoginDisabledError):
            User.login('*****@*****.**', 'password')

        response = self.post('/auth/access/', {
            'email': '*****@*****.**',
            'operation': 'unknown'
        })
        self.assertEqual(response.code, 400)
Exemplo n.º 18
0
 def test_attributes(self):
     tester = User('*****@*****.**')
     self.assertEqual(tester.name, 'Dude')
     self.assertEqual(tester.email, '*****@*****.**')
Exemplo n.º 19
0
 def test_init(self):
     with self.assertRaises(LabmanUnknownIdError):
         User('Dude')
Exemplo n.º 20
0
    def test_sample_plating_process_handler_patch_request(self):
        user = User('*****@*****.**')
        # Test operation not supported
        regex = ('Operation add not supported. Current supported '
                 'operations: replace')
        with self.assertRaisesRegex(HTTPError, regex):
            sample_plating_process_handler_patch_request(
                user, 10, 'add', '/well/8/1/sample', '1.SKM8.640201', None)

        # Test incorrect path parameter
        regex = 'Incorrect path parameter'
        with self.assertRaisesRegex(HTTPError, regex):
            sample_plating_process_handler_patch_request(
                user, 10, 'replace', '/8/1/', '1.SKM8.640201', None)
        with self.assertRaisesRegex(HTTPError, regex):
            sample_plating_process_handler_patch_request(
                user, 10, 'replace', '/well/8/1/sample/content',
                '1.SKM8.640201', None)

        # Test attribute not found
        regex = 'Attribute content not found'
        with self.assertRaisesRegex(HTTPError, regex):
            sample_plating_process_handler_patch_request(
                user, 10, 'replace', '/content/8/1/sample', '1.SKM8.640201',
                None)

        # Test well not found
        regex = 'Well attribute WRONG not found'
        with self.assertRaisesRegex(HTTPError, regex):
            sample_plating_process_handler_patch_request(
                user, 10, 'replace', '/well/8/1/WRONG', '1.SKM8.640201', None)

        # Test missing req_value
        regex = 'A new value for the well should be provided'
        with self.assertRaisesRegex(HTTPError, regex):
            sample_plating_process_handler_patch_request(
                user, 10, 'replace', '/well/8/1/sample', None, None)
        with self.assertRaisesRegex(HTTPError, regex):
            sample_plating_process_handler_patch_request(
                user, 10, 'replace', '/well/8/1/sample', '', None)
        with self.assertRaisesRegex(HTTPError, regex):
            sample_plating_process_handler_patch_request(
                user, 10, 'replace', '/well/8/1/sample', '  ', None)

        # Test success
        tester = SampleComposition(85)
        self.assertEqual(tester.sample_composition_type, 'blank')
        self.assertIsNone(tester.sample_id)
        self.assertEqual(tester.content, 'blank.21.H1')

        obs = sample_plating_process_handler_patch_request(
            user, 10, 'replace', '/well/8/1/sample', '1.SKM8.640201', None)
        self.assertEqual(tester.sample_composition_type, 'experimental sample')
        self.assertEqual(tester.sample_id, '1.SKM8.640201')
        self.assertEqual(tester.content, '1.SKM8.640201')
        self.assertEqual(obs, {
            'sample_id': '1.SKM8.640201',
            'previous_plates': [],
            'sample_ok': True
        })

        obs = sample_plating_process_handler_patch_request(
            user, 10, 'replace', '/well/8/1/sample', 'Unknown', None)
        self.assertEqual(tester.sample_composition_type, 'experimental sample')
        self.assertIsNone(tester.sample_id)
        self.assertEqual(tester.content, 'Unknown')
        self.assertEqual(obs, {
            'sample_id': 'Unknown',
            'previous_plates': [],
            'sample_ok': False
        })

        obs = sample_plating_process_handler_patch_request(
            user, 10, 'replace', '/well/8/1/sample', 'blank', None)
        self.assertEqual(tester.sample_composition_type, 'blank')
        self.assertIsNone(tester.sample_id)
        self.assertEqual(tester.content, 'blank.21.H1')
        self.assertEqual(obs, {
            'sample_id': 'blank.21.H1',
            'previous_plates': [],
            'sample_ok': True
        })

        # Test commenting a well
        self.assertIsNone(tester.notes)
        obs = sample_plating_process_handler_patch_request(
            user, 10, 'replace', '/well/8/1/notes', 'New Notes', None)
        self.assertEqual(tester.notes, 'New Notes')
        obs = sample_plating_process_handler_patch_request(
            user, 10, 'replace', '/well/8/1/notes', '  ', None)
        self.assertIsNone(tester.notes)
Exemplo n.º 21
0
 def setUp(self):
     super().setUp()
     self.user = User('*****@*****.**')
Exemplo n.º 22
0
 def get_app(self):
     BaseHandler.get_current_user = Mock(return_value=User("*****@*****.**"))
     self.app.settings['debug'] = False
     return self.app