First import

This commit is contained in:
2022-02-18 12:09:05 +01:00
commit 332876f58c
73 changed files with 12572 additions and 0 deletions
View File
View File
+22
View File
@@ -0,0 +1,22 @@
import unittest
from mirri.biolomics.remote.rest_client import BiolomicsClient
try:
from mirri.biolomics.secrets import CLIENT_ID, SECRET_ID, USERNAME, PASSWORD
except ImportError:
raise ImportError(
'You need a secrets.py in the project dir. with CLIENT_ID, SECRET_ID, USERNAME, PASSWORD')
from .utils import VERSION, SERVER_URL
class BiolomicsClientAuthTest(unittest.TestCase):
def test_authentication(self):
client = BiolomicsClient(SERVER_URL, VERSION, CLIENT_ID, SECRET_ID,
USERNAME, PASSWORD)
access1 = client.get_access_token()
access2 = client.get_access_token()
assert access1 is not None
self.assertEqual(access1, access2)
@@ -0,0 +1,62 @@
import unittest
from mirri.biolomics.remote.endoint_names import GROWTH_MEDIUM_WS
from mirri.biolomics.serializers.growth_media import GrowthMedium
from mirri.biolomics.settings import CLIENT_ID, SECRET_ID, USERNAME, PASSWORD
from mirri.biolomics.remote.biolomics_client import BiolomicsMirriClient
from tests.biolomics.utils import SERVER_URL, VERSION
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)
def test_create_growth_media(self):
self.client.start_transaction()
try:
growth_medium = GrowthMedium()
growth_medium.acronym = 'BBB'
growth_medium.ingredients = 'alkhdflakhf'
growth_medium.description = 'desc'
new_growth_medium = self.client.create(GROWTH_MEDIUM_WS, growth_medium)
print(new_growth_medium.dict())
finally:
self.client.rollback()
def test_update_growth_media(self):
self.client.start_transaction()
try:
growth_medium = GrowthMedium()
growth_medium.acronym = 'BBB'
growth_medium.ingredients = 'alkhdflakhf'
growth_medium.description = 'desc'
growth_medium.full_description = 'full'
new_growth_medium = self.client.create(GROWTH_MEDIUM_WS, growth_medium)
new_growth_medium.full_description = 'full2'
updated_gm = new_growth_medium = self.client.update(GROWTH_MEDIUM_WS, new_growth_medium)
self.assertEqual(updated_gm.full_description, new_growth_medium.full_description)
retrieved = self.client.retrieve_by_id(GROWTH_MEDIUM_WS, new_growth_medium.record_id)
self.assertEqual(retrieved.full_description, updated_gm.full_description)
finally:
self.client.rollback()
@@ -0,0 +1,46 @@
import unittest
from .utils import VERSION, SERVER_URL
from mirri.biolomics.settings import CLIENT_ID, SECRET_ID, USERNAME, PASSWORD
from mirri.biolomics.remote.biolomics_client import BiolomicsMirriClient, BIBLIOGRAPHY_WS
from mirri.entities.publication import Publication
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)
self.assertEqual(biblio.volume, '50')
def test_create_biblio(self):
pub = Publication()
pub.pubmed_id = 'PM18192'
pub.journal = 'my_journal'
pub.title = 'awesome title'
pub.authors = 'pasdas, aposjdasd, alsalsfda'
pub.volume = 'volume 0'
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)
self.assertEqual(new_pub.volume, pub.volume)
finally:
if record_id is not None:
self.client.delete_by_id(BIBLIOGRAPHY_WS, record_id)
@@ -0,0 +1,49 @@
import unittest
from mirri.biolomics.settings import CLIENT_ID, SECRET_ID, USERNAME, PASSWORD
from mirri.biolomics.remote.biolomics_client import BiolomicsMirriClient
from mirri.biolomics.serializers.sequence import GenomicSequenceBiolomics
from .utils import VERSION, SERVER_URL
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)
if __name__ == "__main__":
# import sys;sys.argv = ['', 'BiolomicsClient.Test.test_get_strain_by_id']
unittest.main()
+727
View File
@@ -0,0 +1,727 @@
import unittest
import pycountry
import deepdiff
from pprint import pprint
from mirri.biolomics.serializers.sequence import (
GenomicSequenceBiolomics,
serialize_to_biolomics as sequence_to_biolomics,
serialize_from_biolomics as sequence_from_biolomics)
from mirri.biolomics.serializers.strain import (
serialize_to_biolomics as strain_to_biolomics,
serialize_from_biolomics as strain_from_biolomics)
from mirri.biolomics.serializers.growth_media import (
# serialize_to_biolomics as growth_medium_to_biolomics,
serialize_from_biolomics as growth_medium_from_biolomics)
from mirri.biolomics.serializers.bibliography import (
serializer_from_biolomics as literature_from_biolomics,
serializer_to_biolomics as literature_to_biolomics
)
from mirri.biolomics.settings import CLIENT_ID, SECRET_ID, USERNAME, PASSWORD
from mirri.biolomics.remote.biolomics_client import BiolomicsMirriClient
from mirri.entities.publication import Publication
from .utils import create_full_data_strain, VERSION, SERVER_URL
STRAIN_WS = {
'CreationDate': '2021-05-19T12:22:33',
'CreatorUserName': 'pziarsolo@cect.org',
'LastChangeDate': '2021-05-19T12:22:36',
'LastChangeUserName': 'pziarsolo@cect.org',
'RecordDetails': {'ABS related files': {'FieldType': 21,
'Value': [{'Name': 'link',
'Value': 'https://example.com'}]},
'Altitude of geographic origin': {'FieldType': 4,
'Value': 121.0},
'Applications': {'FieldType': 5, 'Value': 'health'},
'Catalog URL': {'FieldType': 21, 'Value': []},
'Collection accession number': {'FieldType': 5,
'Value': 'TESTCC 1'},
'Collection date': {'FieldType': 8, 'Value': '1991/01/01'},
'Collector': {'FieldType': 5, 'Value': 'the collector'},
'Comment on taxonomy': {'FieldType': 5,
'Value': 'lalalalla'},
'Coordinates of geographic origin': {'FieldType': 12,
'Value': {'Altitude': 0.0,
'Latitude': 23.3,
'Longitude': 23.3,
'Precision': 0.0}},
'Country': {'FieldType': 118,
'Value': [{'Name': {'FieldType': 5,
'Value': 'Spain'},
'RecordId': 54,
'TargetFieldValue': None}]},
'Data provided by': {'FieldType': 22, 'Value': 'Unknown'},
'Date of inclusion in the catalogue': {'FieldType': 8,
'Value': '1985/05/02'},
'Deposit date': {'FieldType': 8, 'Value': '1985/05/02'},
'Depositor': {'FieldType': 5,
'Value': 'NCTC, National Collection of Type '
'Cultures - NCTC, London, United '
'Kingdom of Great Britain and '
'Northern Ireland.'},
'Dual use': {'FieldType': 20, 'Value': 'yes'},
'Enzyme production': {'FieldType': 5,
'Value': 'some enzimes'},
'Form': {'FieldType': 3,
'Value': [{'Name': 'Agar', 'Value': 'yes'},
{'Name': 'Cryo', 'Value': 'no'},
{'Name': 'Dry Ice', 'Value': 'no'},
{'Name': 'Liquid Culture Medium',
'Value': 'no'},
{'Name': 'Lyo', 'Value': 'yes'},
{'Name': 'Oil', 'Value': 'no'},
{'Name': 'Water', 'Value': 'no'}]},
'GMO': {'FieldType': 22, 'Value': 'Yes'},
'GMO construction information': {'FieldType': 5,
'Value': 'instructrion to '
'build'},
'Genotype': {'FieldType': 5, 'Value': 'some genotupe'},
'Geographic origin': {'FieldType': 5,
'Value': 'una state; one '
'municipality; somewhere in '
'the world'},
'History': {'FieldType': 5,
'Value': 'newer < In the middle < older'},
'Infrasubspecific names': {'FieldType': 5,
'Value': 'serovar tete'},
'Interspecific hybrid': {'FieldType': 20, 'Value': 'no'},
'Isolation date': {'FieldType': 8, 'Value': '1900/01/01'},
'Isolation habitat': {'FieldType': 5,
'Value': 'some habitat'},
'Isolator': {'FieldType': 5, 'Value': 'the isolator'},
'Literature': {'FieldType': 118, 'Value': []},
'MTA files URL': {'FieldType': 21,
'Value': [{'Name': 'link',
'Value': 'https://example.com'}]},
'MTA text': {'FieldType': 5, 'Value': ''},
'Metabolites production': {'FieldType': 5,
'Value': 'big factory of cheese'},
'Mutant information': {'FieldType': 5, 'Value': 'x-men'},
'Nagoya protocol restrictions and compliance conditions': {'FieldType': 20,
'Value': 'no '
'known '
'restrictions '
'under '
'the '
'Nagoya '
'protocol'},
'Ontobiotope': {'FieldType': 118,
'Value': [{'Name': {'FieldType': 5,
'Value': 'anaerobic '
'bioreactor '
'(OBT:000190)'},
'RecordId': 100,
'TargetFieldValue': None}]},
'Ontobiotope term for the isolation habitat': {'FieldType': 5,
'Value': ''},
'Orders': {'FieldType': 118, 'Value': []},
'Organism type': {'FieldType': 3,
'Value': [{'Name': 'Algae', 'Value': 'no'},
{'Name': 'Archaea',
'Value': 'yes'},
{'Name': 'Bacteria',
'Value': 'no'},
{'Name': 'Cyanobacteria',
'Value': 'no'},
{'Name': 'Filamentous Fungi',
'Value': 'no'},
{'Name': 'Phage', 'Value': 'no'},
{'Name': 'Plasmid',
'Value': 'no'},
{'Name': 'Virus', 'Value': 'no'},
{'Name': 'Yeast', 'Value': 'no'},
{'Name': 'Microalgae',
'Value': '?'}]},
'Other culture collection numbers': {'FieldType': 5,
'Value': 'aaa a; aaa3 '
'a3'},
'Other denomination': {'FieldType': 5, 'Value': ''},
'Pathogenicity': {'FieldType': 5, 'Value': 'illness'},
'Plasmids': {'FieldType': 5, 'Value': 'asda'},
'Plasmids collections fields': {'FieldType': 5,
'Value': 'asdasda'},
'Ploidy': {'FieldType': 20, 'Value': 'Polyploid'},
'Quarantine in Europe': {'FieldType': 20, 'Value': 'no'},
'Recommended growth medium': {'FieldType': 118,
'Value': [{'Name': {'FieldType': 5,
'Value': 'AAA'},
'RecordId': 1,
'TargetFieldValue': None}]},
'Recommended growth temperature': {'FieldType': 19,
'MaxValue': 30.0,
'MinValue': 30.0},
'Remarks': {'FieldType': 5, 'Value': 'no remarks for me'},
'Restrictions on use': {'FieldType': 20,
'Value': 'no restriction apply'},
'Risk group': {'FieldType': 20, 'Value': '1'},
'Sequences 16s': {"Value": [
{
"Name": {
"Value": "X76436",
"FieldType": 5
},
"RecordId": 50992,
"TargetFieldValue": {
"Value": {
"Sequence": ""
},
"FieldType": 14
}
}
],
"FieldType": 114},
'Sequences 18S rRNA': {'FieldType': 114, 'Value': []},
'Sequences 23S rRNA': {'FieldType': 114, 'Value': []},
'Sequences ACT': {'FieldType': 114, 'Value': []},
'Sequences AmdS': {'FieldType': 114, 'Value': []},
'Sequences Amds12': {'FieldType': 114, 'Value': []},
'Sequences Beta tubulin': {'FieldType': 114, 'Value': []},
'Sequences COX1': {'FieldType': 114, 'Value': []},
'Sequences COX2': {'FieldType': 114, 'Value': []},
'Sequences CaM': {'FieldType': 114, 'Value': []},
'Sequences Cct8': {'FieldType': 114, 'Value': []},
'Sequences Cit1': {'FieldType': 114, 'Value': []},
'Sequences CypA': {'FieldType': 114, 'Value': []},
'Sequences GDP': {'FieldType': 114, 'Value': []},
'Sequences GPD': {'FieldType': 114, 'Value': []},
'Sequences Genome': {'FieldType': 114, 'Value': []},
'Sequences HIS': {'FieldType': 114, 'Value': []},
'Sequences HSP': {'FieldType': 114, 'Value': []},
'Sequences IDH': {'FieldType': 114, 'Value': []},
'Sequences IGS': {'FieldType': 114, 'Value': []},
'Sequences ITS': {'FieldType': 114, 'Value': []},
'Sequences LSU': {'FieldType': 114, 'Value': []},
'Sequences MAT': {'FieldType': 114, 'Value': []},
'Sequences MAT1': {'FieldType': 114, 'Value': []},
'Sequences Miscellaneous': {'FieldType': 114, 'Value': []},
'Sequences NorA': {'FieldType': 114, 'Value': []},
'Sequences NorB': {'FieldType': 114, 'Value': []},
'Sequences Omt12': {'FieldType': 114, 'Value': []},
'Sequences OmtA': {'FieldType': 114, 'Value': []},
'Sequences PcCYP': {'FieldType': 114, 'Value': []},
'Sequences PpgA': {'FieldType': 114, 'Value': []},
'Sequences PreA': {'FieldType': 114, 'Value': []},
'Sequences PreB': {'FieldType': 114, 'Value': []},
'Sequences RAPD': {'FieldType': 114, 'Value': []},
'Sequences RPB1': {'FieldType': 114, 'Value': []},
'Sequences RPB2': {'FieldType': 114, 'Value': []},
'Sequences SSU': {'FieldType': 114, 'Value': []},
'Sequences TEF1a': {'FieldType': 114, 'Value': []},
'Sequences TEF2': {'FieldType': 114, 'Value': []},
'Sequences TUB': {'FieldType': 114, 'Value': []},
'Sequences Tsr1': {'FieldType': 114, 'Value': []},
'Sequences c16S rRNA': {'FieldType': 114, 'Value': []},
'Sequences cbhI': {'FieldType': 114, 'Value': []},
'Sequences mcm7': {'FieldType': 114, 'Value': []},
'Sequences rbcL': {'FieldType': 114, 'Value': []},
'Sexual state': {'FieldType': 5, 'Value': 'MT+A'},
'Status': {'FieldType': 5,
'Value': 'type of Bacillus alcalophilus'},
'Strain from a registered collection': {'FieldType': 20,
'Value': 'no'},
'Substrate of isolation': {'FieldType': 5,
'Value': 'some substrate'},
'Taxon name': {'FieldType': 109,
'Value': [{'Name': {'FieldType': 5,
'Value': 'Escherichia '
'coli'},
'RecordId': 100004123,
'TargetFieldValue': {'DesktopInfo': None,
'DesktopInfoHtml': '<b>Current '
'name: '
'</b><i>Escherichia '
'coli</i> '
'(Migula '
'1895) '
'Castellani '
'and '
'Chalmers '
'1919',
'FieldType': 27,
'NewSynFieldInfo': None,
'ObligateSynonymId': 0,
'OriginalSynFieldInfo': None,
'SynInfo': {'BasionymRecord': {'NameInfo': '',
'RecordId': 100004123,
'RecordName': '<i>Escherichia '
'coli</i> '
'(Migula '
'1895) '
'Castellani '
'and '
'Chalmers '
'1919',
'SecondLevelRecords': None},
'CurrentNameRecord': {'NameInfo': '',
'RecordId': 100004123,
'RecordName': '<i>Escherichia '
'coli</i> '
'(Migula '
'1895) '
'Castellani '
'and '
'Chalmers '
'1919',
'SecondLevelRecords': None},
'ObligateSynonymRecords': [],
'SelectedRecord': {
'NameInfo': '<i>Escherichia '
'coli</i> '
'(Migula '
'1895) '
'Castellani '
'and '
'Chalmers '
'1919',
'RecordId': 100004123,
'RecordName': '<i>Escherichia '
'coli</i> '
'(Migula '
'1895) '
'Castellani '
'and '
'Chalmers '
'1919',
'SecondLevelRecords': None},
'TaxonSynonymsRecords': []},
'SynonymId': 100004123}}]},
'Tested temperature growth range': {'FieldType': 19,
'MaxValue': 32.0,
'MinValue': 29.0},
'Type description': {'FieldType': 5, 'Value': ''}},
'RecordId': 148038,
'RecordName': 'MIRRI 2240561'}
STRAIN_WS_EXPECTED_NO_REMOTE = {
'Acronym': 'MIRRI',
'RecordDetails': {'ABS related files': {'FieldType': 'U',
'Value': [{'Name': 'link',
'Value': 'https://example.com'}]},
'Altitude of geographic origin': {'FieldType': 'D',
'Value': 121},
'Applications': {'FieldType': 'E', 'Value': 'health'},
'Collection accession number': {'FieldType': 'E',
'Value': 'TESTCC 1'},
'Collection date': {'FieldType': 'H', 'Value': '1991-01-01'},
'Collector': {'FieldType': 'E', 'Value': 'the collector'},
'Comment on taxonomy': {'FieldType': 'E',
'Value': 'lalalalla'},
'Coordinates of geographic origin': {'FieldType': 'L',
'Value': {'Latitude': 23.3,
'Longitude': 23.3}},
'Date of inclusion in the catalogue': {'FieldType': 'H',
'Value': '1985-05-02'},
'Deposit date': {'FieldType': 'H', 'Value': '1985-05-02'},
'Depositor': {'FieldType': 'E',
'Value': 'NCTC, National Collection of Type '
'Cultures - NCTC, London, United '
'Kingdom of Great Britain and '
'Northern Ireland.'},
'Dual use': {'FieldType': 'T', 'Value': 'yes'},
'Enzyme production': {'FieldType': 'E',
'Value': 'some enzimes'},
'Form': {'FieldType': 'C',
'Value': [{'Name': 'Agar', 'Value': 'yes'},
{'Name': 'Cryo', 'Value': 'no'},
{'Name': 'Dry Ice', 'Value': 'no'},
{'Name': 'Liquid Culture Medium',
'Value': 'no'},
{'Name': 'Lyo', 'Value': 'yes'},
{'Name': 'Oil', 'Value': 'no'},
{'Name': 'Water', 'Value': 'no'}]},
'GMO': {'FieldType': 'V', 'Value': 'Yes'},
'GMO construction information': {'FieldType': 'E',
'Value': 'instructrion to '
'build'},
'Genotype': {'FieldType': 'E', 'Value': 'some genotupe'},
'Geographic origin': {'FieldType': 'E',
'Value': 'una state; one '
'municipality; somewhere in '
'the world'},
'History': {'FieldType': 'E',
'Value': 'firstplave < seconn place < third '
'place'},
'Infrasubspecific names': {'FieldType': 'E',
'Value': 'serovar tete'},
'Interspecific hybrid': {'FieldType': 'T', 'Value': 'no'},
'Isolation date': {'FieldType': 'H', 'Value': '1900-01-01'},
'Isolation habitat': {'FieldType': 'E',
'Value': 'some habitat'},
'Isolator': {'FieldType': 'E', 'Value': 'the isolator'},
'MTA files URL': {'FieldType': 'U',
'Value': [{'Name': 'link',
'Value': 'https://example.com'}]},
'Metabolites production': {'FieldType': 'E',
'Value': 'big factory of cheese'},
'Mutant information': {'FieldType': 'E', 'Value': 'x-men'},
'Nagoya protocol restrictions and compliance conditions': {'FieldType': 'T',
'Value': 'no '
'known '
'restrictions '
'under '
'the '
'Nagoya '
'protocol'},
'Ontobiotope': {'FieldType': 'RLink', 'Value': 'OBT:000190'},
'Organism type': {'FieldType': 'C',
'Value': [{'Name': 'Algae', 'Value': 'no'},
{'Name': 'Archaea',
'Value': 'yes'},
{'Name': 'Bacteria',
'Value': 'no'},
{'Name': 'Cyanobacteria',
'Value': 'no'},
{'Name': 'Filamentous Fungi',
'Value': 'no'},
{'Name': 'Phage', 'Value': 'no'},
{'Name': 'Plasmid',
'Value': 'no'},
{'Name': 'Virus', 'Value': 'no'},
{'Name': 'Yeast',
'Value': 'no'}]},
'Other culture collection numbers': {'FieldType': 'E',
'Value': 'aaa a; aaa3 '
'a3'},
'Pathogenicity': {'FieldType': 'E', 'Value': 'illness'},
'Plasmids': {'FieldType': 'E', 'Value': 'asda'},
'Plasmids collections fields': {'FieldType': 'E',
'Value': 'asdasda'},
'Ploidy': {'FieldType': 'T', 'Value': 'Polyploid'},
'Quarantine in Europe': {'FieldType': 'T', 'Value': 'no'},
'Recommended growth temperature': {'FieldType': 'S',
'MaxValue': 30.0,
'MinValue': 30.0},
'Remarks': {'FieldType': 'E', 'Value': 'no remarks for me'},
'Restrictions on use': {'FieldType': 'T',
'Value': 'no restriction apply'},
'Risk group': {'FieldType': 'T', 'Value': '1'},
'Sexual state': {'FieldType': 'E', 'Value': 'MT+A'},
'Status': {'FieldType': 'E',
'Value': 'type of Bacillus alcalophilus'},
'Strain from a registered collection': {'FieldType': 'T',
'Value': 'no'},
'Substrate of isolation': {'FieldType': 'E',
'Value': 'some substrate'},
'Taxon name': {'FieldType': 'SynLink',
'Value': 'Escherichia coli'},
'Tested temperature growth range': {'FieldType': 'S',
'MaxValue': 32.0,
'MinValue': 29.0}}}
class StrainSerializerTest(unittest.TestCase):
def test_serialize_to_biolomics(self):
strain = create_full_data_strain()
ws_strain = strain_to_biolomics(strain, client=None)
self.assertDictEqual(ws_strain, STRAIN_WS_EXPECTED_NO_REMOTE)
def test_serialize_to_biolomics_remote(self):
client = BiolomicsMirriClient(SERVER_URL, VERSION, CLIENT_ID,
SECRET_ID, USERNAME, PASSWORD)
strain = create_full_data_strain()
marker = GenomicSequenceBiolomics()
marker.marker_id = "MUM 02.15 - Beta tubulin"
marker.marker_type = 'TUBB'
strain.genetics.markers = [marker]
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'])
self.assertEqual(strain.genetics.markers[0].marker_id,
ws_strain['RecordDetails']['Sequences TUB']['Value'][0]['Name']['Value'])
def test_serialize_from_biolomics(self):
ws_strain = STRAIN_WS
strain = strain_from_biolomics(ws_strain)
self.assertEqual(strain.record_id, 148038)
self.assertEqual(strain.record_name, 'MIRRI 2240561')
self.assertEqual(strain.taxonomy.long_name, 'Escherichia coli')
self.assertEqual(strain.growth.recommended_media, ['AAA'])
self.assertEqual(strain.collect.location.altitude, 121)
self.assertEqual(strain.collect.location.country, 'ESP')
self.assertEqual(strain.applications, 'health')
self.assertEqual(strain.id.strain_id, 'TESTCC 1')
self.assertEqual(strain.collect.date.strfdate, '19910101')
self.assertEqual(strain.taxonomy.comments, 'lalalalla')
self.assertEqual(strain.catalog_inclusion_date.strfdate, '19850502')
self.assertIn('NCTC, National Collection of Type ', strain.deposit.who)
self.assertTrue(strain.is_potentially_harmful)
self.assertEqual(strain.form_of_supply, ['Agar', 'Lyo'])
self.assertTrue(strain.genetics.gmo)
self.assertEqual(strain.genetics.gmo_construction, 'instructrion to build')
self.assertEqual(strain.genetics.genotype, 'some genotupe')
self.assertEqual(strain.history, ['newer', 'In the middle', 'older'])
self.assertEqual(strain.taxonomy.infrasubspecific_name, 'serovar tete')
self.assertEqual(strain.isolation.who, 'the isolator')
self.assertEqual(strain.isolation.date.strfdate, '19000101')
self.assertEqual(strain.mta_files, ['https://example.com'])
self.assertEqual(strain.genetics.mutant_info, 'x-men')
self.assertEqual(strain.collect.habitat_ontobiotope, 'OBT:000190')
self.assertEqual(strain.taxonomy.organism_type[0].name, 'Archaea')
self.assertEqual(strain.other_numbers[0].strain_id, 'aaa a')
self.assertEqual(strain.other_numbers[1].strain_id, 'aaa3 a3')
self.assertEqual(strain.pathogenicity, 'illness')
self.assertEqual(strain.genetics.plasmids, ['asda'])
self.assertEqual(strain.genetics.ploidy, 9)
self.assertFalse(strain.is_subject_to_quarantine)
self.assertEqual(strain.risk_group, '1')
self.assertFalse(strain.is_from_registered_collection)
self.assertEqual(strain.growth.tested_temp_range, {'min': 29, 'max': 32})
BIOLOMICSSEQ = {
'RecordDetails': {
'Barcode level': {'FieldType': 20, 'Value': 'undefined'},
'DNA extract number': {'FieldType': 5, 'Value': ''},
'DNA sequence': {'FieldType': 14,
'Value': {'Sequence': 'caaaggaggccttctccctcttcgtaag'}},
'Editing state': {'FieldType': 20, 'Value': 'Auto import'},
'Forward primer(s)': {'FieldType': 5, 'Value': ''},
'Genbank': {'FieldType': 21, 'Value': []},
'INSDC number': {'FieldType': 5, 'Value': 'AATGAT'},
'Literature': {'FieldType': 21, 'Value': []},
'Literature1': {'FieldType': 118, 'Value': []},
'Marker name': {'FieldType': 5, 'Value': 'CaM'},
'Privacy': {'FieldType': 20, 'Value': 'undefined'},
'Quality': {'FieldType': 5, 'Value': ''},
'Remarks': {'FieldType': 5, 'Value': ''},
'Reverse primer(s)': {'FieldType': 5, 'Value': ''},
'Review state': {'FieldType': 5, 'Value': ''},
'Strain number': {'FieldType': 5, 'Value': 'MUM 02.54'}},
'RecordId': 101,
'RecordName': 'MUM 02.54 - CaM'}
class SequenceSerializerTest(unittest.TestCase):
def test_from_biolomics(self):
marker = sequence_from_biolomics(BIOLOMICSSEQ)
self.assertEqual(marker.record_name, BIOLOMICSSEQ['RecordName'])
self.assertEqual(marker.record_id, BIOLOMICSSEQ['RecordId'])
self.assertEqual(marker.marker_type, BIOLOMICSSEQ['RecordDetails']['Marker name']['Value'])
self.assertEqual(marker.marker_id, BIOLOMICSSEQ['RecordDetails']['INSDC number']['Value'])
self.assertEqual(marker.marker_seq, BIOLOMICSSEQ['RecordDetails']['DNA sequence']['Value']['Sequence'])
def test_to_biolomics(self):
marker = GenomicSequenceBiolomics()
marker.marker_id = 'GGAAUUA'
marker.marker_seq = 'aattgacgat'
marker.marker_type = 'CaM'
marker.record_name = 'peioMarker'
marker.record_id = 111
ws_seq = sequence_to_biolomics(marker)
expected = {'RecordId': marker.record_id,
'RecordName': marker.record_name,
'RecordDetails': {
'INSDC number': {'Value': marker.marker_id, 'FieldType': 'E'},
'DNA sequence': {'Value': {'Sequence': marker.marker_seq}, 'FieldType': 'N'},
'Marker name': {'Value': marker.marker_type, 'FieldType': 'E'}}}
self.assertEqual(ws_seq, expected)
BIOLOMICS_MEDIUM = {
"RecordId": 100,
"RecordName": "MA20S",
"RecordDetails": {
"Full description": {
"Value": "mout agar+20% saccharose",
"FieldType": 5
},
"Ingredients": {
"Value": "Malt extract\r\n\tDilute brewery malt with water to 10% sugar solution (level 10 on Brix saccharose meter), 15 minutes at 121 C\r\nsaccharose\t200g\r\ndistilled water\t0.6l\r\nagar\t15g\r\n",
"FieldType": 5
},
"Link to full description": {
"Value": [],
"FieldType": 21
},
"Medium description": {
"Value": "",
"FieldType": 5
},
"Other name": {
"Value": "",
"FieldType": 5
},
"pH": {
"Value": "7 with KOH",
"FieldType": 5
},
"Remarks": {
"Value": "",
"FieldType": 5
},
"Reference": {
"Value": "",
"FieldType": 5
},
"Sterilization conditions": {
"Value": "15 minutes at 121 C",
"FieldType": 5
}
}
}
class MediumSerializerTest(unittest.TestCase):
def test_from_biolomics(self):
medium = growth_medium_from_biolomics(BIOLOMICS_MEDIUM)
self.assertEqual(medium.record_id, BIOLOMICS_MEDIUM['RecordId'])
self.assertEqual(medium.record_name, BIOLOMICS_MEDIUM['RecordName'])
self.assertEqual(medium.ingredients, BIOLOMICS_MEDIUM['RecordDetails']['Ingredients']['Value'])
self.assertEqual(medium.full_description, BIOLOMICS_MEDIUM['RecordDetails']['Full description']['Value'])
self.assertEqual(medium.ph, BIOLOMICS_MEDIUM['RecordDetails']['pH']['Value'])
BIOLOMICS_BIBLIOGRAPHY = {
"RecordId": 100,
"RecordName": "Miscellaneous notes on Mucoraceae",
"RecordDetails": {
"Associated strains": {
"Value": [],
"FieldType": 118
},
"Associated taxa": {
"Value": [],
"FieldType": 118
},
"Authors": {
"Value": "Schipper, M.A.A.; Samson, R.A.",
"FieldType": 5
},
"Associated sequences": {
"Value": [],
"FieldType": 118
},
"Abstract": {
"Value": "",
"FieldType": 5
},
"Collection": {
"Value": "",
"FieldType": 5
},
"DOI number": {
"Value": "",
"FieldType": 5
},
"Editor(s)": {
"Value": "",
"FieldType": 5
},
"Full reference": {
"Value": "",
"FieldType": 5
},
"Hyperlink": {
"Value": [],
"FieldType": 21
},
"ISBN": {
"Value": "",
"FieldType": 5
},
"ISSN": {
"Value": "",
"FieldType": 5
},
"Issue": {
"Value": "",
"FieldType": 5
},
"Journal": {
"Value": "Mycotaxon",
"FieldType": 5
},
"Journal-Book": {
"Value": "",
"FieldType": 5
},
"Keywords": {
"Value": "",
"FieldType": 5
},
"Page from": {
"Value": "475",
"FieldType": 5
},
"Page to": {
"Value": "491",
"FieldType": 5
},
"Publisher": {
"Value": "",
"FieldType": 5
},
"PubMed ID": {
"Value": "",
"FieldType": 5
},
"Volume": {
"Value": "50",
"FieldType": 5
},
"Year": {
"Value": 1994,
"FieldType": 4
}
}
}
class BibliographySerializerTest(unittest.TestCase):
def test_from_biolomics(self):
pub = literature_from_biolomics(BIOLOMICS_BIBLIOGRAPHY)
self.assertEqual(pub.record_name, "Miscellaneous notes on Mucoraceae")
self.assertEqual(pub.record_id, 100)
self.assertEqual(pub.year, 1994)
self.assertEqual(pub.authors, "Schipper, M.A.A.; Samson, R.A.")
def test_to_biolomics(self):
pub = Publication()
pub.title = 'My title'
pub.year = 1992
pub.authors = 'me and myself'
pub.pubmed_id = '1112222'
pub.issue = 'issue'
ws_data = literature_to_biolomics(pub)
expected = {
'RecordDetails': {
'Authors': {'FieldType': 'E', 'Value': 'me and myself'},
'PubMed ID': {'FieldType': 'E', 'Value': '1112222'},
'Issue': {'FieldType': 'E', 'Value': 'issue'},
'Year': {'FieldType': 'D', 'Value': 1992}},
'RecordName': 'My title'}
self.assertDictEqual(expected, ws_data)
def test_to_biolomics2(self):
pub = Publication()
pub.pubmed_id = '1112222'
ws_data = literature_to_biolomics(pub)
expected = {
'RecordDetails': {
'PubMed ID': {'FieldType': 'E', 'Value': '1112222'}},
'RecordName': f'PUBMED:{pub.pubmed_id}'}
self.assertDictEqual(expected, ws_data)
pub = Publication()
pub.doi = 'doi.er/111/12131'
ws_data = literature_to_biolomics(pub)
expected = {
'RecordDetails': {
'DOI number': {'FieldType': 'E', 'Value': pub.doi}},
'RecordName': f'DOI:{pub.doi}'}
self.assertDictEqual(expected, ws_data)
if __name__ == "__main__":
import sys;
sys.argv = ['', 'BibliographySerializerTest']
unittest.main()
+156
View File
@@ -0,0 +1,156 @@
import unittest
from mirri.biolomics.remote.endoint_names import STRAIN_WS
from .utils import VERSION, SERVER_URL, create_full_data_strain
from mirri.biolomics.settings import CLIENT_ID, SECRET_ID, USERNAME, PASSWORD
from mirri.biolomics.remote.biolomics_client import BiolomicsMirriClient
from mirri.biolomics.pipelines.strain import retrieve_strain_by_accession_number
class BiolomicsStrainClientTest(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 = 14803
strain = self.client.retrieve_by_id(STRAIN_WS, record_id)
self.assertEqual(strain.record_id, record_id)
print(strain.record_name)
def test_retrieve_strain_by_name(self):
record_id = 14803
record_name = 'MIRRI0014803'
strain = self.client.retrieve_by_name(STRAIN_WS, 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_WS, 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_WS, query)
for strain in search_response['records']:
print(strain)
self.client.delete_by_id(STRAIN_WS, 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_WS, query)
self.assertEqual(search_response['total'], 0)
self.assertFalse(search_response['records'])
def test_create_strain(self):
strain = create_full_data_strain()
strain.taxonomy.interspecific_hybrid = None
record_id = None
try:
new_strain = self.client.create(STRAIN_WS, strain)
record_id = new_strain.record_id
self.assertIsNone(new_strain.taxonomy.interspecific_hybrid)
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_WS, record_id)
def test_update_strain(self):
strain = create_full_data_strain()
record_id = None
try:
new_strain = self.client.create(STRAIN_WS, strain)
record_id = new_strain.record_id
self.assertEqual(new_strain.id.strain_id, strain.id.strain_id)
self.assertFalse(new_strain.taxonomy.interspecific_hybrid)
new_strain.id.number = '2'
new_strain.taxonomy.interspecific_hybrid = None
updated_strain = self.client.update(STRAIN_WS, new_strain)
self.assertEqual(updated_strain.id.strain_id, new_strain.id.strain_id)
self.assertIsNone(updated_strain.taxonomy.interspecific_hybrid)
retrieved_strain = self.client.retrieve_by_id(STRAIN_WS, record_id)
self.assertEqual(retrieved_strain.id.strain_id, new_strain.id.strain_id)
self.assertIsNone(retrieved_strain.taxonomy.interspecific_hybrid)
finally:
if record_id is not None:
print('deleting')
self.client.delete_by_id(STRAIN_WS, record_id)
def test_update_strain_pathogenicity(self):
strain = create_full_data_strain()
print(strain.pathogenicity)
record_id = None
try:
new_strain = self.client.create(STRAIN_WS, strain)
record_id = new_strain.record_id
self.assertEqual(new_strain.id.strain_id, strain.id.strain_id)
self.assertEqual(new_strain.pathogenicity, 'illness')
new_strain.pathogenicity = None
updated_strain = self.client.update(STRAIN_WS, new_strain)
self.assertEqual(updated_strain.id.strain_id, new_strain.id.strain_id)
self.assertIsNone(updated_strain.pathogenicity)
retrieved_strain = self.client.retrieve_by_id(STRAIN_WS, record_id)
self.assertEqual(retrieved_strain.id.strain_id, new_strain.id.strain_id)
self.assertIsNone(retrieved_strain.pathogenicity)
finally:
if record_id is not None:
self.client.delete_by_id(STRAIN_WS, 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)
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)
if __name__ == "__main__":
# import sys;sys.argv = ['',
# 'BiolomicsWriter.test_mirri_excel_parser_invalid']
unittest.main()
+99
View File
@@ -0,0 +1,99 @@
from mirri.biolomics.serializers.strain import StrainMirri
from mirri.entities.strain import StrainId, OrganismType
from mirri.entities.sequence import GenomicSequence
from mirri.entities.date_range import DateRange
from mirri.entities.publication import Publication
from mirri.settings import NAGOYA_NO_RESTRICTIONS
VERSION = 'v2'
SERVER_URL = 'https://webservices.bio-aware.com/mirri_test'
def create_full_data_strain():
strain = StrainMirri()
strain.id.number = "1"
strain.id.collection = "TESTCC"
strain.id.url = "https://cect/2342"
strain.restriction_on_use = "no_restriction"
strain.nagoya_protocol = NAGOYA_NO_RESTRICTIONS
strain.abs_related_files = ['https://example.com']
strain.mta_files = ['https://example.com']
strain.other_numbers.append(StrainId(collection="aaa", number="a"))
strain.other_numbers.append(StrainId(collection="aaa3", number="a3"))
strain.is_from_registered_collection = False
strain.risk_group = '1'
strain.is_potentially_harmful = True
strain.is_subject_to_quarantine = False
strain.taxonomy.organism_type = [OrganismType(2)]
strain.taxonomy.genus = 'Escherichia'
strain.taxonomy.species = 'coli'
strain.taxonomy.interspecific_hybrid = False
strain.taxonomy.infrasubspecific_name = 'serovar tete'
strain.taxonomy.comments = 'lalalalla'
strain.status = "type of Bacillus alcalophilus"
strain.history = 'firstplave < seconn place < third place'
strain.deposit.who = "NCTC, National Collection of Type Cultures - NCTC, London, United Kingdom of Great Britain and Northern Ireland."
strain.deposit.date = DateRange(year=1985, month=5, day=2)
strain.catalog_inclusion_date = DateRange(year=1985, month=5, day=2)
strain.collect.location.country = "ESP"
strain.collect.location.state = "una state"
strain.collect.location.municipality = "one municipality"
strain.collect.location.longitude = 23.3
strain.collect.location.latitude = 23.3
strain.collect.location.altitude = 121
strain.collect.location.site = "somewhere in the world"
strain.collect.habitat_ontobiotope = "OBT:000190"
strain.collect.habitat = 'some habitat'
strain.collect.who = "the collector"
strain.collect.date = DateRange(year=1991)
strain.isolation.date = DateRange(year=1900)
strain.isolation.who = 'the isolator'
strain.isolation.substrate_host_of_isolation = 'some substrate'
# already existing media in test_mirri
strain.growth.recommended_temp = {'min': 30, 'max': 30}
strain.growth.recommended_media = ["AAA"]
strain.growth.tested_temp_range = {'min': 29, 'max': 32}
strain.form_of_supply = ["Agar", "Lyo"]
#strain.other_denominations = ["lajdflasjdldj"]
gen_seq = GenomicSequence()
gen_seq.marker_id = "pepe"
gen_seq.marker_type = "16S rRNA"
strain.genetics.markers.append(gen_seq)
strain.genetics.ploidy = 9
strain.genetics.genotype = 'some genotupe'
strain.genetics.gmo = True
strain.genetics.gmo_construction = 'instructrion to build'
strain.genetics.mutant_info = 'x-men'
strain.genetics.sexual_state = 'MT+A'
strain.genetics.plasmids = ['asda']
strain.genetics.plasmids_in_collections = ['asdasda']
pub = Publication()
pub.title = "The genus Amylomyces"
strain.publications = [pub]
strain.plant_pathogenicity_code = 'PATH:001'
strain.pathogenicity = 'illness'
strain.enzyme_production = 'some enzimes'
strain.production_of_metabolites = 'big factory of cheese'
strain.applications = 'health'
strain.remarks = 'no remarks for me'
return strain
if __name__ == '__main__':
strain = create_full_data_strain()
print(strain.collect.habitat_ontobiotope)
Binary file not shown.
+5
View File
@@ -0,0 +1,5 @@
{
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
+318
View File
@@ -0,0 +1,318 @@
"""
Created on 2020(e)ko abe. 2(a)
@author: peio
"""
import unittest
from mirri.entities.publication import Publication
from mirri.entities.date_range import DateRange
from mirri.entities.location import Location
from mirri.entities.sequence import GenomicSequence
from mirri.entities.strain import (
Collect,
Deposit,
Isolation,
ValidationError,
OrganismType,
Strain,
StrainId,
Taxonomy,
)
from mirri.settings import (
COLLECT,
COUNTRY,
DATE_OF_ISOLATION,
DEPOSIT,
DEPOSITOR,
GENETICS,
GROWTH,
ISOLATED_BY,
ISOLATION,
LOCATION,
MARKERS,
NAGOYA_DOCS_AVAILABLE,
NAGOYA_PROTOCOL,
ORGANISM_TYPE,
OTHER_CULTURE_NUMBERS,
PLOIDY,
RECOMMENDED_GROWTH_MEDIUM,
TAXONOMY,
DATE_OF_INCLUSION, NO_RESTRICTION
)
from mirri.validation.entity_validators import validate_strain
class TestDataRange(unittest.TestCase):
def test_data_range_init(self):
dr = DateRange()
self.assertFalse(dr)
self.assertEqual(dr.__str__(), "")
self.assertEqual(dr.range["start"], None)
self.assertEqual(dr.range["end"], None)
dr.strpdate("2012")
self.assertEqual(dr.strfdate, "2012----")
self.assertTrue(dr)
dr.strpdate("2012----")
self.assertEqual(dr.strfdate, "2012----")
dr.strpdate("201212--")
self.assertEqual(dr.strfdate, "201212--")
try:
dr.strpdate("201213--")
self.fail()
except ValueError:
pass
try:
dr = DateRange(year=2012, month=13)
self.fail()
except ValueError:
pass
dr = DateRange(year=2020)
self.assertEqual(dr.strfdate, "2020----")
dr2 = dr.strpdate("2012")
self.assertEqual(dr2.range["start"].year, 2012)
self.assertEqual(dr2.range["start"].month, 1)
self.assertEqual(dr2.range["start"].day, 1)
self.assertEqual(dr2.range["end"].year, 2012)
self.assertEqual(dr2.range["end"].month, 12)
self.assertEqual(dr2.range["end"].day, 31)
class TestCollect(unittest.TestCase):
def test_collect_basic(self):
collect = Collect()
self.assertEqual(collect.dict(), {})
collect.location.country = "ESP"
collect.date = DateRange().strpdate("2012----")
collect.who = "pepito"
self.assertEqual(
dict(collect.dict()),
{
"location": {"countryOfOriginCode": "ESP"},
"collected_by": "pepito",
"date_of_collection": "2012----",
},
)
self.assertEqual(collect.__str__(),
"Collected: Spain in 2012---- by pepito")
class TestOrganismType(unittest.TestCase):
def test_basic_usage(self):
org_type = OrganismType(2)
self.assertEqual(org_type.name, "Archaea")
self.assertEqual(org_type.code, 2)
try:
org_type.ko = 'a'
self.fail()
except TypeError:
pass
org_type = OrganismType("Archaea")
class TestTaxonomy(unittest.TestCase):
def test_taxonomy_basic(self):
taxonomy = Taxonomy()
self.assertEqual(taxonomy.dict(), {})
self.assertFalse(taxonomy)
def test_taxonomy_with_data(self):
taxonomy = Taxonomy()
taxonomy.genus = "Bacilus"
taxonomy.organism_type = [OrganismType("Archaea")]
taxonomy.species = "vulgaris"
self.assertEqual(taxonomy.long_name, "Bacilus vulgaris")
# print(taxonomy.dict())
class TestLocation(unittest.TestCase):
def test_empty_init(self):
loc = Location()
self.assertEqual(loc.dict(), {})
self.assertFalse(loc)
def test_add_data(self):
loc = Location()
loc.country = "esp"
self.assertEqual(loc.dict(), {COUNTRY: "esp"})
loc.state = None
self.assertEqual(loc.dict(), {COUNTRY: "esp"})
class TestStrain(unittest.TestCase):
def test_empty_strain(self):
strain = Strain()
self.assertEqual(strain.dict(), {})
def test_strain_add_data(self):
strain = Strain()
strain.id.number = "5433"
strain.id.collection = "CECT"
strain.id.url = "https://cect/2342"
try:
strain.nagoya_protocol = "asdas"
self.fail()
except ValidationError:
pass
strain.nagoya_protocol = NAGOYA_DOCS_AVAILABLE
strain.dict()[NAGOYA_PROTOCOL] = NAGOYA_DOCS_AVAILABLE
strain.collect.location.country = "ESP"
self.assertEqual(strain.dict()[COLLECT][LOCATION][COUNTRY], "ESP")
strain.genetics.ploidy = 9
self.assertEqual(strain.dict()[GENETICS][PLOIDY], 9)
strain.growth.recommended_media = ["asd"]
strain.isolation.date = DateRange(year=1900)
self.assertEqual(strain.dict()[ISOLATION]
[DATE_OF_ISOLATION], "1900----")
strain.deposit.who = "pepe"
self.assertEqual(strain.dict()[DEPOSIT][DEPOSITOR], "pepe")
strain.growth.recommended_media = ["11"]
self.assertEqual(strain.dict()[GROWTH]
[RECOMMENDED_GROWTH_MEDIUM], ["11"])
strain.taxonomy.organism_type = [OrganismType(2)]
self.assertEqual(
strain.dict()[TAXONOMY][ORGANISM_TYPE], [
{"code": 2, "name": "Archaea"}]
)
strain.taxonomy.organism_type = [OrganismType("Algae")]
self.assertEqual(
strain.dict()[TAXONOMY][ORGANISM_TYPE], [
{"code": 1, "name": "Algae"}]
)
strain.other_numbers.append(StrainId(collection="aaa", number="a"))
strain.other_numbers.append(StrainId(collection="aaa3", number="a3"))
self.assertEqual(
strain.dict()[OTHER_CULTURE_NUMBERS],
[
{"collection_code": "aaa", "accession_number": "a"},
{"collection_code": "aaa3", "accession_number": "a3"},
],
)
strain.form_of_supply = ["Agar", "Lyo"]
gen_seq = GenomicSequence()
self.assertEqual(gen_seq.dict(), {})
gen_seq.marker_id = "pepe"
gen_seq.marker_type = "16S rRNA"
strain.genetics.markers.append(gen_seq)
self.assertEqual(
strain.dict()[GENETICS][MARKERS],
[{"marker_type": "16S rRNA", "INSDC": "pepe"}],
)
strain.collect.habitat_ontobiotope = "OBT:111111"
self.assertEqual(strain.collect.habitat_ontobiotope, "OBT:111111")
try:
strain.collect.habitat_ontobiotope = "OBT:11111"
self.fail()
except ValidationError:
pass
# publications
try:
strain.publications = 1
self.fail()
except ValidationError:
pass
pub = Publication()
pub.id = "1"
try:
strain.publications = pub
self.fail()
except ValidationError:
pass
strain.publications = [pub]
self.assertEqual(strain.publications[0].id, "1")
strain.catalog_inclusion_date = DateRange(year=1992)
self.assertEqual(strain.dict()[DATE_OF_INCLUSION], '1992----')
import pprint
pprint.pprint(strain.dict())
def test_strain_validation(self):
strain = Strain()
strain.form_of_supply = ['Lyo']
return
errors = validate_strain(strain)
self.assertEqual(len(errors), 10)
strain.id.collection = 'test'
strain.id.number = '1'
errors = validate_strain(strain)
self.assertEqual(len(errors), 9)
strain.nagoya_protocol = NAGOYA_DOCS_AVAILABLE
strain.restriction_on_use = NO_RESTRICTION
strain.risk_group = 1
strain.taxonomy.organism_type = [OrganismType(4)]
strain.taxonomy.hybrids = ['Sac lac', 'Sac lcac3']
strain.growth.recommended_media = ['aa']
strain.growth.recommended_temp = {'min': 2, 'max':5}
strain.form_of_supply = ['lyo']
strain.collect.location.country = 'ESP'
errors = validate_strain(strain)
self.assertFalse(errors)
class TestIsolation(unittest.TestCase):
def test_iniatialize_isollation(self):
isolation = Isolation()
self.assertEqual(isolation.dict(), {})
isolation.who = "pepito"
self.assertTrue(ISOLATED_BY in isolation.dict())
isolation.date = DateRange().strpdate("2012----")
self.assertTrue(DATE_OF_ISOLATION in isolation.dict())
try:
isolation.location.site = "spain"
self.fail()
except (ValueError, AttributeError):
pass
class TestGenomicSequence(unittest.TestCase):
def test_empty_init(self):
gen_seq = GenomicSequence()
self.assertEqual(gen_seq.dict(), {})
gen_seq.marker_id = "pepe"
gen_seq.marker_type = "16S rRNA"
self.assertEqual(gen_seq.dict(), {
"marker_type": "16S rRNA", "INSDC": "pepe"})
if __name__ == "__main__":
# import sys;sys.argv = ['', 'TestStrain']
unittest.main()
+51
View File
@@ -0,0 +1,51 @@
from mirri.entities.strain import ValidationError
import unittest
from pathlib import Path
from pprint import pprint
from mirri.io.parsers.mirri_excel import parse_mirri_excel
TEST_DATA_DIR = Path(__file__).parent / "data"
class MirriExcelTests(unittest.TestCase):
def test_mirri_excel_parser(self):
in_path = TEST_DATA_DIR / "valid.mirri.xlsx"
with in_path.open("rb") as fhand:
parsed_data = parse_mirri_excel(fhand, version="20200601")
medium = parsed_data["growth_media"][0]
self.assertEqual("1", medium.acronym)
self.assertEqual(medium.description, "NUTRIENT BROTH/AGAR I")
strains = list(parsed_data["strains"])
strain = strains[0]
self.assertEqual(strain.publications[0].id, 1)
self.assertEqual(strain.publications[0].title, 'Cosa')
self.assertEqual(strain.id.number, "1")
pprint(strain.dict())
def xtest_mirri_excel_parser_invalid_fail(self):
in_path = TEST_DATA_DIR / "invalid.mirri.xlsx"
with in_path.open("rb") as fhand:
try:
parse_mirri_excel(fhand, version="20200601")
self.fail()
except ValidationError:
pass
def xtest_mirri_excel_parser_invalid(self):
in_path = TEST_DATA_DIR / "invalid.mirri.xlsx"
with in_path.open("rb") as fhand:
parsed_data = parse_mirri_excel(
fhand, version="20200601")
errors = parsed_data["errors"]
for _id, _errors in errors.items():
print(_id, _errors)
if __name__ == "__main__":
# import sys;sys.argv = ['',
# 'MirriExcelTests.test_mirri_excel_parser_invalid']
unittest.main()
+589
View File
@@ -0,0 +1,589 @@
from datetime import datetime
import unittest
from pathlib import Path
from itertools import chain
from mirri.validation.tags import (
CHOICES,
COORDINATES,
CROSSREF,
CROSSREF_NAME,
DATE,
MATCH,
MISSING,
MULTIPLE,
NUMBER,
REGEXP,
SEPARATOR,
TAXON,
TYPE,
UNIQUE,
VALUES
)
from mirri.validation.excel_validator import (
is_valid_choices,
is_valid_coords,
is_valid_crossrefs,
is_valid_date,
is_valid_missing,
is_valid_number,
is_valid_regex,
is_valid_taxon,
is_valid_unique,
is_valid_file,
validate_mirri_excel,
)
TEST_DATA_DIR = Path(__file__).parent / "data"
TS_VALUE = "value"
TS_CONF = "conf"
TS_ASSERT = "assert_func"
class MirriExcelValidationTests(unittest.TestCase):
def test_validation_structure(self):
in_path = TEST_DATA_DIR / "invalid_structure.mirri.xlsx"
with in_path.open("rb") as fhand:
error_log = validate_mirri_excel(fhand)
entities = []
err_codes = []
for ett, errors in error_log.get_errors().items():
entities.append(ett)
err_codes.extend([err.code for err in errors])
self.assertIn("EFS", entities)
self.assertIn("STD", entities)
self.assertIn("GOD", entities)
self.assertIn("GMD", entities)
self.assertIn("EFS03", err_codes)
self.assertIn("EFS06", err_codes)
self.assertIn("EFS08", err_codes)
self.assertIn("GOD06", err_codes)
self.assertIn("GMD01", err_codes)
self.assertIn("STD05", err_codes)
self.assertIn("STD08", err_codes)
self.assertIn("STD12", err_codes)
def test_validation_content(self):
in_path = TEST_DATA_DIR / "invalid_content.mirri.xlsx"
with in_path.open("rb") as fhand:
error_log = validate_mirri_excel(fhand)
entities = []
err_codes = []
for ett, errors in error_log.get_errors().items():
entities.append(ett)
err_codes.extend([err.code for err in errors])
self.assertTrue(len(err_codes) > 0)
self.assertNotIn("EFS", entities)
self.assertIn("STD", entities)
self.assertIn("GOD", entities)
self.assertIn("GID", entities)
self.assertIn("GOD04", err_codes)
self.assertIn("GOD07", err_codes)
self.assertIn("GID03", err_codes)
self.assertIn("STD11", err_codes)
self.assertIn("STD15", err_codes)
self.assertIn("STD22", err_codes)
self.assertIn("STD04", err_codes)
self.assertIn("STD10", err_codes)
self.assertIn("STD07", err_codes)
self.assertIn("STD14", err_codes)
self.assertIn("STD16", err_codes)
def test_validation_valid(self):
in_path = TEST_DATA_DIR / "valid.mirri.xlsx"
with in_path.open("rb") as fhand:
error_log = validate_mirri_excel(fhand)
self.assertTrue(len(error_log.get_errors()) == 0)
class ValidatoionFunctionsTest(unittest.TestCase):
def test_is_valid_regex(self):
tests = [
{
TS_VALUE: "abcDEF",
TS_CONF: {TYPE: REGEXP, MATCH: r"[a-zA-Z]+"},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "123456",
TS_CONF: {TYPE: REGEXP, MATCH: r"[a-zA-Z]+"},
TS_ASSERT: self.assertFalse
},
{
TS_VALUE: "123456",
TS_CONF: {TYPE: REGEXP, MATCH: r"\d+"},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "abcdef",
TS_CONF: {TYPE: REGEXP, MATCH: r"\d+"},
TS_ASSERT: self.assertFalse
},
{
TS_VALUE: "abc 123",
TS_CONF: {TYPE: REGEXP, MATCH: r"\w+(\s\w+)*$"},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "123 abc",
TS_CONF: {TYPE: REGEXP, MATCH: r"\w+(\s\w+)*$"},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "123 ",
TS_CONF: {TYPE: REGEXP, MATCH: r"\w+(\s\w+)*$"},
TS_ASSERT: self.assertFalse
},
]
for test in tests:
value = test[TS_VALUE]
conf = test[TS_CONF]
assert_func = test[TS_ASSERT]
with self.subTest(value=value):
assert_func(is_valid_regex(value, conf))
def test_is_valid_choices(self):
tests = [
{
TS_VALUE: "1",
TS_CONF: {TYPE: CHOICES, VALUES: ["1", "2", "3", "4"]},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "1, 3",
TS_CONF: {
TYPE: CHOICES,
VALUES: ["1", "2", "3", "4"],
MULTIPLE: True,
SEPARATOR: ","
},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "5",
TS_CONF: {TYPE: CHOICES, VALUES: ["1", "2", "3", "4"]},
TS_ASSERT: self.assertFalse
},
]
for test in tests:
value = test[TS_VALUE]
conf = test[TS_CONF]
assert_func = test[TS_ASSERT]
with self.subTest(value=value):
assert_func(is_valid_choices(value, conf))
def test_is_valid_crossref(self):
tests = [
{
TS_VALUE: "abc",
TS_CONF: {
TYPE: CROSSREF,
CROSSREF_NAME: "values",
"crossrefs_pointer": {"values": ["abc", "def", "ghi"]},
},
TS_ASSERT: self.assertTrue,
},
{
TS_VALUE: "123",
TS_CONF: {
TYPE: CROSSREF,
CROSSREF_NAME: "values",
"crossrefs_pointer": {"values": ["abc", "def", "ghi"]},
},
TS_ASSERT: self.assertFalse,
},
{
TS_VALUE: "abc, def",
TS_CONF: {
TYPE: CROSSREF,
CROSSREF_NAME: "values",
"crossrefs_pointer": {"values": ["abc", "def", "ghi"]},
MULTIPLE: True,
SEPARATOR: ",",
},
TS_ASSERT: self.assertTrue,
},
{
TS_VALUE: "abc, 123",
TS_CONF: {
TYPE: CROSSREF,
CROSSREF_NAME: "values",
"crossrefs_pointer": {"values": ["abc", "def", "ghi"]},
MULTIPLE: True,
SEPARATOR: ",",
},
TS_ASSERT: self.assertFalse,
},
]
for test in tests:
value = test[TS_VALUE]
conf = test[TS_CONF]
assert_func = test[TS_ASSERT]
with self.subTest(value=value):
assert_func(is_valid_crossrefs(value, conf))
def test_is_valid_missing(self):
tests = [
{
TS_VALUE: 1,
TS_CONF: {TYPE: MISSING},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "abc",
TS_CONF: {TYPE: MISSING},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: None,
TS_CONF: {TYPE: MISSING},
TS_ASSERT: self.assertFalse
},
]
for test in tests:
value = test[TS_VALUE]
conf = test[TS_CONF]
assert_func = test[TS_ASSERT]
with self.subTest(value=value):
assert_func(is_valid_missing(value, conf))
def test_is_valid_date(self):
tests = [
{
TS_VALUE: '2020-04-07',
TS_CONF: {TYPE: DATE},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: '2020/04/07',
TS_CONF: {TYPE: DATE},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: datetime(2021, 5, 1),
TS_CONF: {TYPE: DATE},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: '2020-05',
TS_CONF: {TYPE: DATE},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: '2020/05',
TS_CONF: {TYPE: DATE},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: 2020,
TS_CONF: {TYPE: DATE},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: '2021 05 01',
TS_CONF: {TYPE: DATE},
TS_ASSERT: self.assertFalse
},
{
TS_VALUE: '04-07-2020',
TS_CONF: {TYPE: DATE},
TS_ASSERT: self.assertFalse
},
{
TS_VALUE: '2021-02-31',
TS_CONF: {TYPE: DATE},
TS_ASSERT: self.assertFalse
},
{
TS_VALUE: '2021-15',
TS_CONF: {TYPE: DATE},
TS_ASSERT: self.assertFalse
},
{
TS_VALUE: '15-2021',
TS_CONF: {TYPE: DATE},
TS_ASSERT: self.assertFalse
},
{
TS_VALUE: 3000,
TS_CONF: {TYPE: DATE},
TS_ASSERT: self.assertFalse
},
{
TS_VALUE: -2020,
TS_CONF: {TYPE: DATE},
TS_ASSERT: self.assertFalse
},
]
for test in tests:
value = test[TS_VALUE]
conf = test[TS_CONF]
assert_func = test[TS_ASSERT]
with self.subTest(value=value):
assert_func(is_valid_date(value, conf))
def test_is_valid_coordinates(self):
tests = [
{
TS_VALUE: "23; 50",
TS_CONF: {TYPE: COORDINATES},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "-90; -100",
TS_CONF: {TYPE: COORDINATES},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "90; 100",
TS_CONF: {TYPE: COORDINATES},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "0; 0",
TS_CONF: {TYPE: COORDINATES},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "10; 20; 5",
TS_CONF: {TYPE: COORDINATES},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "10; 20; -5",
TS_CONF: {TYPE: COORDINATES},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "91; 50",
TS_CONF: {TYPE: COORDINATES},
TS_ASSERT: self.assertFalse
},
{
TS_VALUE: "87; 182",
TS_CONF: {TYPE: COORDINATES},
TS_ASSERT: self.assertFalse
},
{
TS_VALUE: "-200; 182",
TS_CONF: {TYPE: COORDINATES},
TS_ASSERT: self.assertFalse
},
{
TS_VALUE: "20, 40",
TS_CONF: {TYPE: COORDINATES},
TS_ASSERT: self.assertFalse
},
{
TS_VALUE: "abc def",
TS_CONF: {TYPE: COORDINATES},
TS_ASSERT: self.assertFalse
},
{
TS_VALUE: 123,
TS_CONF: {TYPE: COORDINATES},
TS_ASSERT: self.assertFalse
},
]
for test in tests:
value = test[TS_VALUE]
conf = test[TS_CONF]
assert_func = test[TS_ASSERT]
with self.subTest(value=value):
assert_func(is_valid_coords(value, conf))
def test_is_valid_number(self):
tests = [
{
TS_VALUE: 1,
TS_CONF: {TYPE: NUMBER},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: 2.5,
TS_CONF: {TYPE: NUMBER},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "10",
TS_CONF: {TYPE: NUMBER},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "10.5",
TS_CONF: {TYPE: NUMBER},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: 5,
TS_CONF: {TYPE: NUMBER, "min": 0},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: 5,
TS_CONF: {TYPE: NUMBER, "max": 10},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: 5,
TS_CONF: {TYPE: NUMBER, "min": 0, "max": 10},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "hello",
TS_CONF: {TYPE: NUMBER},
TS_ASSERT: self.assertFalse
},
{
TS_VALUE: 10,
TS_CONF: {TYPE: NUMBER, "max": 5},
TS_ASSERT: self.assertFalse
},
{
TS_VALUE: 0,
TS_CONF: {TYPE: NUMBER, "min": 5},
TS_ASSERT: self.assertFalse
},
]
for test in tests:
value = test[TS_VALUE]
conf = test[TS_CONF]
assert_func = test[TS_ASSERT]
with self.subTest(value=value):
assert_func(is_valid_number(value, conf))
def test_is_valid_taxon(self):
tests = [
{
TS_VALUE: 'sp. species',
TS_CONF: {TYPE: TAXON},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: 'spp species subsp. subspecies',
TS_CONF: {TYPE: TAXON},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: 'spp species subsp. subspecies var. variety',
TS_CONF: {TYPE: TAXON},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: 'spp taxon',
TS_CONF: {TYPE: TAXON},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: 'Candidaceae',
TS_CONF: {TYPE: TAXON},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: 'sp sp species',
TS_CONF: {TYPE: TAXON},
TS_ASSERT: self.assertFalse
},
{
TS_VALUE: 'spp species abc. def',
TS_CONF: {TYPE: TAXON},
TS_ASSERT: self.assertFalse
},
]
for test in tests:
value = test[TS_VALUE]
conf = test[TS_CONF]
assert_func = test[TS_ASSERT]
with self.subTest(value=value):
assert_func(is_valid_taxon(value, conf))
def test_is_valid_unique(self):
tests = [
{
TS_VALUE: "abc",
TS_CONF: {
TYPE: UNIQUE,
"label": "values",
"shown_values": {}
},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "jkl",
TS_CONF: {
TYPE: UNIQUE,
"label": "values",
"shown_values": {
"values": {"abc": '',
"def": '',
"ghi": ''},
}
},
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: "abc",
TS_CONF: {
TYPE: UNIQUE,
"label": "values",
"shown_values": {
"values": {"abc": '',
"def": '',
"ghi": ''},
}
},
TS_ASSERT: self.assertFalse
},
]
for test in tests:
value = test[TS_VALUE]
conf = test[TS_CONF]
assert_func = test[TS_ASSERT]
with self.subTest(value=value):
assert_func(is_valid_unique(value, conf))
def test_is_valid_file(self):
tests = [
{
TS_VALUE: TEST_DATA_DIR / "invalid_structure.mirri.xlsx",
TS_ASSERT: self.assertTrue
},
{
TS_VALUE: TEST_DATA_DIR / "invalid_excel.mirri.json",
TS_ASSERT: self.assertFalse
},
]
for test in tests:
value = test[TS_VALUE]
assert_func = test[TS_ASSERT]
with self.subTest(value=value):
assert_func(is_valid_file(value,))
if __name__ == "__main__":
import sys
# sys.argv = ['',
# 'ValidatoionFunctionsTest.test_is_valid_regex']
unittest.main()
+24
View File
@@ -0,0 +1,24 @@
import unittest
from pathlib import Path
from mirri.io.writers.mirri_excel import write_mirri_excel
from mirri.io.parsers.mirri_excel import parse_mirri_excel
TEST_DATA_DIR = Path(__file__).parent / "data"
class MirriExcelTests(unittest.TestCase):
def test_valid_excel(self):
in_path = TEST_DATA_DIR / "valid.mirri.full.xlsx"
parsed_data = parse_mirri_excel(in_path.open('rb'), version="20200601")
strains = parsed_data["strains"]
growth_media = parsed_data["growth_media"]
out_path = Path("/tmp/test.xlsx")
write_mirri_excel(out_path, strains, growth_media, version="20200601")
if __name__ == "__main__":
# import sys;sys.argv = ['',
# 'BiolomicsWriter.test_mirri_excel_parser_invalid']
unittest.main()