Esempio n. 1
0
class BiolomicsLiteratureClientTest(unittest.TestCase):
    def setUp(self):
        self.client = BiolomicsMirriClient(SERVER_URL, VERSION, CLIENT_ID,
                                           SECRET_ID, USERNAME, PASSWORD)

    def test_retrieve_biblio_by_id(self):
        record_id = 100
        record_name = "Miscellaneous notes on Mucoraceae"
        biblio = self.client.retrieve_by_id(BIBLIOGRAPHY_WS, record_id)
        self.assertEqual(biblio.record_id, record_id)

        self.assertEqual(biblio.record_name, record_name)

    def test_retrieve_media_by_id(self):
        record_id = 100
        record_name = "Miscellaneous notes on Mucoraceae"
        biblio = self.client.retrieve_by_name(BIBLIOGRAPHY_WS, record_name)
        self.assertEqual(biblio.record_id, record_id)
        self.assertEqual(biblio.record_name, record_name)
        self.assertEqual(biblio.year, 1994)

    def test_create_biblio(self):
        pub = Publication()
        pub.pubmed_id = 'PM18192'
        pub.journal = 'my_journal'
        pub.title = 'awesome title'
        pub.authors = 'pasdas, aposjdasd, alsalsfda'
        record_id = None
        try:
            new_pub = self.client.create(BIBLIOGRAPHY_WS, pub)
            record_id = new_pub.record_id
            self.assertEqual(new_pub.title, pub.title)
        finally:
            if record_id is not None:
                self.client.delete_by_id(BIBLIOGRAPHY_WS, record_id)
Esempio n. 2
0
def get_or_create_sequence(client: BiolomicsMirriClient,
                           sequence: GenomicSequenceBiolomics):
    seq = client.retrieve_by_name(sequence.marker_id)
    if seq is not None:
        return seq, False
    new_seq = client.create(SEQUENCE_WS, sequence)
    return new_seq, True
Esempio n. 3
0
def get_or_create_strain(client: BiolomicsMirriClient, strain: StrainMirri):
    new_strain = retrieve_strain_by_accession_number(client,
                                                     strain.id.strain_id)
    if new_strain:
        return new_strain, False

    created_ids = OrderedDict()
    try:
        for pub in strain.publications:
            new_pub, created = get_or_create_publication(client, pub)
            if created:
                if BIBLIOGRAPHY_WS not in created_ids:
                    created_ids[BIBLIOGRAPHY_WS] = []
                created_ids[BIBLIOGRAPHY_WS].append(new_pub.record_id)

        for marker in strain.genetics.markers:
            new_marker, created = get_or_create_sequence(client, marker)
            if created:
                if SEQUENCE_WS not in created_ids:
                    created_ids[SEQUENCE_WS] = []
                created_ids[SEQUENCE_WS].append(new_marker.record_id)

        new_strain = client.create(STRAIN_WS, strain)
        created_ids[STRAIN_WS] = [new_strain.record_id]
        return new_strain, True

    except Exception:
        client.rollback(created_ids)
        raise
Esempio n. 4
0
class BiolomicsClientGrowthMediaTest(unittest.TestCase):
    def setUp(self):
        self.client = BiolomicsMirriClient(SERVER_URL, VERSION, CLIENT_ID,
                                           SECRET_ID, USERNAME, PASSWORD)

    def xtest_growth_media_by_name(self):
        gm = self.client.retrieve('growth_media', 'AAA')
        self.assertEqual(gm['Record Id'], 1)
Esempio n. 5
0
class BiolomicsSequenceClientTest(unittest.TestCase):
    def setUp(self):
        self.client = BiolomicsMirriClient(SERVER_URL, VERSION, CLIENT_ID,
                                           SECRET_ID, USERNAME, PASSWORD)

    def test_retrieve_media_by_id(self):
        record_id = 101
        growth_medium = self.client.retrieve_by_id('growth_medium', record_id)
        self.assertEqual(growth_medium.record_id, record_id)

        self.assertEqual(growth_medium.record_name, 'MA2PH6')

    def test_retrieve_media_by_id(self):
        record_name = 'MA2PH6'
        record_id = 101
        growth_medium = self.client.retrieve_by_name('growth_medium', record_name)
        self.assertEqual(growth_medium.record_id, record_id)
        self.assertEqual(growth_medium.record_name, record_name)
Esempio n. 6
0
 def test_serialize_to_biolomics_remote(self):
     client = BiolomicsMirriClient(SERVER_URL, VERSION, CLIENT_ID,
                                   SECRET_ID, USERNAME, PASSWORD)
     strain = create_full_data_strain()
     ws_strain = strain_to_biolomics(strain, client=client)
     self.assertEqual(
         strain.collect.habitat_ontobiotope, ws_strain['RecordDetails']
         ['Ontobiotope']['Value'][0]['Name']['Value'])
     self.assertEqual(
         pycountry.countries.get(
             alpha_3=strain.collect.location.country).name,
         ws_strain['RecordDetails']['Country']['Value'][0]['Name']['Value'])
     self.assertEqual(
         strain.publications[0].title, ws_strain['RecordDetails']
         ['Literature']['Value'][0]['Name']['Value'])
Esempio n. 7
0
class BiolomicsSequenceClientTest(unittest.TestCase):
    def setUp(self) -> None:
        self.client = BiolomicsMirriClient(SERVER_URL, VERSION, CLIENT_ID,
                                           SECRET_ID, USERNAME, PASSWORD)

    def test_retrieve_seq_by_id(self):
        record_id = 101
        sequence = self.client.retrieve_by_id('sequence', record_id)

        self.assertEqual(sequence.record_id, record_id)
        self.assertEqual(sequence.record_name, 'MUM 02.54 - CaM')
        self.assertEqual(sequence.marker_type, 'CaM')

    def test_retrieve_seq_by_name(self):
        record_name = 'MUM 02.54 - CaM'
        sequence = self.client.retrieve_by_name('sequence', record_name)

        self.assertEqual(sequence.record_id, 101)
        self.assertEqual(sequence.record_name, record_name)
        self.assertEqual(sequence.marker_type, 'CaM')

    def test_create_delete_sequence(self):
        marker = GenomicSequenceBiolomics()
        marker.marker_id = 'GGAAUUA'
        marker.marker_seq = 'aattgacgat'
        marker.marker_type = 'CaM'
        marker.record_name = 'peioMarker'

        new_marker = self.client.create('sequence', marker)
        self.assertEqual(new_marker.marker_id, 'GGAAUUA')
        self.assertEqual(new_marker.marker_seq, 'aattgacgat')
        self.assertEqual(new_marker.marker_type, 'CaM')
        self.assertEqual(new_marker.record_name, 'peioMarker')
        self.assertTrue(new_marker.record_id)

        self.client.delete_by_id('sequence', new_marker.record_id)
Esempio n. 8
0
 def setUp(self):
     self.client = BiolomicsMirriClient(SERVER_URL, VERSION, CLIENT_ID,
                                        SECRET_ID, USERNAME, PASSWORD)
Esempio n. 9
0
def get_or_create_publication(client: BiolomicsMirriClient, pub: Publication):
    pub = client.retrieve_by_name(pub.title)
    if pub is not None:
        return pub, False
    new_pub = client.create(BIBLIOGRAPHY_WS, pub)
    return new_pub, True
Esempio n. 10
0
class BiolomicsSequenceClientTest(unittest.TestCase):
    def setUp(self):
        self.client = BiolomicsMirriClient(SERVER_URL, VERSION, CLIENT_ID,
                                           SECRET_ID, USERNAME, PASSWORD)

    def test_retrieve_strain_by_id(self):
        record_id = 148038
        strain = self.client.retrieve_by_id('strain', record_id)
        self.assertEqual(strain.record_id, record_id)

    def test_retrieve_strain_by_name(self):
        record_id = 148038
        record_name = 'MIRRI 2240561'
        strain = self.client.retrieve_by_name('strain', record_name)
        self.assertEqual(strain.record_name, record_name)
        self.assertEqual(strain.record_id, record_id)

    def test_search_strain(self):
        accession_number = "BEA 0014B"
        query = {
            "Query": [{
                "Index": 0,
                "FieldName": "Collection accession number",
                "Operation": "TextExactMatch",
                "Value": accession_number
            }],
            "Expression":
            "Q0",
            "DisplayStart":
            0,
            "DisplayLength":
            10
        }

        search_response = self.client.search('strain', query)

        self.assertEqual(search_response['total'], 1)
        self.assertEqual(search_response['records'][0].id.strain_id,
                         accession_number)

    def test_search_strain4(self):
        accession_number = "TESTCC 1"
        query = {
            "Query": [{
                "Index": 0,
                "FieldName": "Collection accession number",
                "Operation": "TextExactMatch",
                "Value": accession_number
            }],
            "Expression":
            "Q0",
            "DisplayStart":
            0,
            "DisplayLength":
            10
        }

        search_response = self.client.search('strain', query)
        for strain in search_response['records']:
            print(strain)
            self.client.delete_by_id('strain', strain.record_id)

    def test_search_strain_no_found(self):
        accession_number = "BEA 0014B_"
        query = {
            "Query": [{
                "Index": 0,
                "FieldName": "Collection accession number",
                "Operation": "TextExactMatch",
                "Value": accession_number
            }],
            "Expression":
            "Q0",
            "DisplayStart":
            0,
            "DisplayLength":
            10
        }

        search_response = self.client.search('strain', query)

        self.assertEqual(search_response['total'], 0)
        self.assertFalse(search_response['records'])

    def test_create_strain(self):
        strain = create_full_data_strain()
        record_id = None
        try:
            new_strain = self.client.create('strain', strain)

            record_id = new_strain.record_id
            self.assertEqual(new_strain.growth.recommended_media, ['AAA'])
            self.assertEqual(new_strain.id.strain_id, strain.id.strain_id)
        finally:
            if record_id is not None:
                self.client.delete_by_id('strain', record_id)

    def test_update_strain(self):
        strain = create_full_data_strain()
        strain.growth.recommended_media.append('ahgfsdha')
        record_id = None
        try:
            new_strain = self.client.create('strain', strain)
            record_id = new_strain.record_id
            self.assertEqual(new_strain.id.strain_id, strain.id.strain_id)
            new_strain.id.number = '2'
            updated_strain = self.client.update(STRAIN_WS, new_strain)
            self.assertEqual(updated_strain.id.strain_id,
                             new_strain.id.strain_id)

            retrieved_strain = self.client.retrieve_by_id(STRAIN_WS, record_id)
            self.assertEqual(retrieved_strain.id.strain_id,
                             new_strain.id.strain_id)

        finally:
            if record_id is not None:
                print('deleting')
                self.client.delete_by_id('strain', record_id)

    def test_search_by_accession_number(self):
        accession_number = "BEA 0014B"
        strain = retrieve_strain_by_accession_number(self.client,
                                                     accession_number)
        self.assertEqual(strain.id.strain_id, accession_number)

    def test_search_by_accession_number(self):
        accession_number = "BEA 0014B_"
        strain = retrieve_strain_by_accession_number(self.client,
                                                     accession_number)
        self.assertFalse(strain)