EnsemblRestInfo.test_getInfoVariationBySpecies()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 14
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
import json
2
import logging
3
import re
4
import shlex
5
import subprocess
6
import time
7
import unittest
8
import urllib.parse
9
from typing import Any
10
11
import pytest
12
from requests import Response
13
14
import pyensemblrest
15
from pyensemblrest.ensemblrest import FakeResponse, ensembl_user_agent
16
17
# logger instance
18
logger = logging.getLogger(__name__)
19
20
# create console handler and set level to debug. NullHandler to put all into /dev/null
21
# ch = logging.NullHandler()
22
23
# This console handle write all logging to and opened strem. sys.stderr is the default
24
ch = logging.StreamHandler()
25
26
# Set the level for this handler
27
ch.setLevel(logging.DEBUG)
28
29
# create formatter
30
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
31
32
# add formatter to ch
33
ch.setFormatter(formatter)
34
35
# add ch to logger
36
logger.addHandler(ch)
37
38
# Wait some time before next request
39
WAIT = 1
40
41
# Sometimes curl fails
42
MAX_RETRIES = 5
43
44
# curl timeouts
45
TIMEOUT = 60
46
47
48
def launch(cmd: str) -> str:
49
    """Calling a cmd with subprocess"""
50
51
    # setting curl timeouts
52
    pattern = re.compile("curl")
53
    repl = "curl --connect-timeout %s --max-time %s" % (TIMEOUT, TIMEOUT * 2)
54
55
    # Setting curl options
56
    cmd = re.sub(pattern, repl, cmd)
57
58
    logger.debug("Executing: %s" % (cmd))
59
60
    args = shlex.split(cmd)
61
    p = subprocess.Popen(
62
        args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True
63
    )
64
    stdout, stderr = p.communicate()
65
66
    if len(stderr) > 0:
67
        logger.debug(stderr)
68
69
    # debug
70
    # logger.debug("Got: %s" % (stdout))
71
72
    return stdout
73
74
75
def jsonFromCurl(curl_cmd: str) -> dict[Any, Any] | None:
76
    """Parsing a JSON curl result"""
77
78
    data = None
79
    retry = 0
80
81
    while retry < MAX_RETRIES:
82
        # update retry
83
        retry += 1
84
85
        # execute the curl cmd
86
        result = launch(curl_cmd)
87
88
        # load it as a dictionary
89
        try:
90
            data = json.loads(result)
91
92
        except ValueError as e:
93
            logger.warning("Curl command failed: %s" % e)
94
            time.sleep(WAIT * 10)
95
96
            # next request
97
            continue
98
99
        if isinstance(data, dict):
100
            if "error" in data:
101
                logger.warning("Curl command failed: %s" % (data["error"]))
102
                time.sleep(WAIT * 10)
103
104
                # next request
105
                continue
106
107
        # If I arrive here, I assume that curl went well
108
        break
109
110
    return data
111
112
113
def _genericCMP(v1: Any, v2: Any) -> bool:
114
    """Check ensembl complex elements"""
115
116
    logger.debug("Check %s == %s" % (v1, v2))
117
118
    # check that types are the same
119
    if type(v1) is not type(v2):
120
        return False
121
    elif isinstance(v1, dict):
122
        # call comparedict
123
        if compareDict(v1, v2) is False:
124
            return False
125
    elif isinstance(v1, list):
126
        # call comparedict
127
        if compareList(v1, v2) is False:
128
            return False
129
    elif isinstance(v1, (str, float, int)):
130
        if v1 != v2:
131
            return False
132
    else:
133
        logger.error("%s <> %s" % (v1, v2))
134
        logger.critical("Case not implemented: type: %s" % (type(v1)))
135
136
    # default value
137
    return True
138
139
140
# A function to evaluate if two python complex dictionaries are the same
141
def compareDict(d1: dict[Any, Any], d2: dict[Any, Any]) -> bool:
142
    """A function to evaluate if two python complex dictionaries are the same"""
143
    if d1 == d2:
144
        return True
145
146
    # check keys
147
    k1 = d1.keys()
148
    k2 = d2.keys()
149
150
    # sorting keys
151
    k1 = sorted(k1)
152
    k2 = sorted(k2)
153
154
    logger.debug(k1)
155
    logger.debug(k2)
156
157
    # check keys are equals
158
    if k1 != k2:
159
        return False
160
161
    # now I have to check values for each key value
162
    for k in k1:
163
        # get values
164
        v1 = d1[k]
165
        v2 = d2[k]
166
167
        if v1 == v2:
168
            continue
169
170
        # the species key may differ in some cases: ex: Tgut-Mgal-Ggal[3] <> Ggal-Mgal-Tgut[3]
171
        if k in ["species", "tree"] and isinstance(v1, str) and isinstance(v2, str):
172
            pattern = re.compile(r"([\w]+)-?(?:\[\d\])?")
173
174
            # override values
175
            v1 = re.findall(pattern, v1)
176
            v2 = re.findall(pattern, v2)
177
178
        # check if elements are the same
179
        if _genericCMP(v1, v2) is False:
180
            return False
181
182
    # if I arrive here:
183
    return True
184
185
186
def compareList(l1: list[Any], l2: list[Any]) -> bool:
187
    """A function to evaluate if two python complex lists are the same"""
188
189
    # check if lists are equal
190
    if l1 == l2:
191
        return True
192
193
    # check if lengths are equal
194
    if len(l1) != len(l2):
195
        return False
196
197
    # I cannot use set nor collections.Count, since elements could't be hashable
198
    # sorting elements doesn't apply since elements may be un-hashable
199
    for i in range(len(l1)):
200
        v1 = l1[i]
201
202
        flag_found = False
203
204
        for j in range(len(l2)):
205
            v2 = l2[j]
206
207
            if v1 == v2:
208
                flag_found = True
209
210
            # check if elements are the same
211
            elif _genericCMP(v1, v2) is True:
212
                flag_found = True
213
214
            # If I found en equal element, i can stop
215
            if flag_found is True:
216
                break
217
218
        # After cycling amoung l2, if I can't find an equal element
219
        if flag_found is False:
220
            return False
221
222
    # if I arrive here
223
    return True
224
225
226
def compareNested(obj1: Any, obj2: Any) -> bool:
227
    """Compare complex nested objects."""
228
    if isinstance(obj1, dict) and isinstance(obj2, dict):
229
        return compareDict(obj1, obj2)
230
    if isinstance(obj1, list) and isinstance(obj2, list):
231
        return compareList(obj1, obj2)
232
    else:
233
        return obj1 == obj2
234
235
236
def normalize_genomes_response(
237
    data: dict[str, Any] | list[dict[str, Any]],
238
) -> dict[str, Any] | list[dict[str, Any]]:
239
    """
240
    Normalize Ensembl genomes API response to handle inconsistent formats.
241
242
    The Ensembl API sometimes returns nested structures with 'assembly' and
243
    'organism' objects, and sometimes returns flat structures. This function
244
    flattens nested structures for consistent comparison.
245
246
    Args:
247
        data: Response data from Ensembl genomes endpoints (single dict or list of dicts)
248
249
    Returns:
250
        Normalized (flattened) response data
251
    """
252
253
    def normalize_single(item: dict[str, Any]) -> dict[str, Any]:
254
        """Normalize a single genome item."""
255
        normalized = item.copy()
256
257
        # Flatten 'assembly' object if present
258
        if "assembly" in normalized and isinstance(normalized["assembly"], dict):
259
            assembly_data = normalized.pop("assembly")
260
            normalized.update(assembly_data)
261
262
        # Flatten 'organism' object if present
263
        if "organism" in normalized and isinstance(normalized["organism"], dict):
264
            organism_data = normalized.pop("organism")
265
            normalized.update(organism_data)
266
267
        return normalized
268
269
    # Handle both single dict and list of dicts
270
    if isinstance(data, list):
271
        return [normalize_single(item) for item in data]
272
    else:
273
        return normalize_single(data)
274
275
276
class EnsemblRest(unittest.TestCase):
277
    """A class to test EnsemblRest methods"""
278
279
    def setUp(self) -> None:
280
        """Create a EnsemblRest object"""
281
        self.EnsEMBL = pyensemblrest.EnsemblRest()
282
283
    def tearDown(self) -> None:
284
        """Sleep a while before doing next request"""
285
        time.sleep(WAIT)
286
287
288
class EnsemblRestHelper(EnsemblRest):
289
    """A class to deal with ensemblrest helper methods"""
290
291
    def test_compareNestedDict(self) -> None:
292
        reference = {
293
            "one": ["bar", "foo"],
294
            "two": ["test", "this"],
295
            "three": ["foo", "bar"],
296
            "four": ["this", "test"],
297
        }
298
299
        test = {
300
            "two": ["test", "this"],
301
            "four": ["this", "test"],
302
            "three": ["foo", "bar"],
303
            "one": ["bar", "foo"],
304
        }
305
306
        self.assertTrue(compareNested(reference, test))
307
308
    def test_compareNestedList(self) -> None:
309
        reference = [
310
            {
311
                "one": ["bar", "foo"],
312
                "two": ["test", "this"],
313
                "three": ["foo", "bar"],
314
                "four": ["this", "test"],
315
            },
316
            {
317
                "one": ["bar", "foo"],
318
                "two": ["test", "this"],
319
                "three": ["foo", "bar"],
320
                "four": ["this", "test"],
321
            },
322
        ]
323
324
        test = [
325
            {
326
                "two": ["test", "this"],
327
                "four": ["this", "test"],
328
                "three": ["foo", "bar"],
329
                "one": ["bar", "foo"],
330
            },
331
            {
332
                "two": ["test", "this"],
333
                "four": ["this", "test"],
334
                "three": ["foo", "bar"],
335
                "one": ["bar", "foo"],
336
            },
337
        ]
338
339
        self.assertTrue(compareNested(reference, test))
340
341
342
class EnsemblRestBase(EnsemblRest):
343
    """A class to deal with ensemblrest base methods"""
344
345
    @pytest.mark.live
346
    def test_setHeaders(self) -> None:
347
        """Testing EnsemblRest with no headers provided"""
348
349
        user_agent = ensembl_user_agent
350
        self.EnsEMBL = pyensemblrest.EnsemblRest(headers={})
351
        self.assertEqual(self.EnsEMBL.session.headers.get("User-Agent"), user_agent)
352
353
    @pytest.mark.live
354
    def test_mandatoryParameters(self) -> None:
355
        """Testing EnsemblRest with no mandatory parameters"""
356
357
        self.assertRaisesRegex(
358
            Exception,
359
            "mandatory param .* not specified",
360
            self.EnsEMBL.getArchiveById,
361
        )
362
363
    @pytest.mark.live
364
    def test_wait4request(self) -> None:
365
        """Simulating max request per second"""
366
367
        self.EnsEMBL.getArchiveById(id="ENSG00000157764")
368
        self.EnsEMBL.req_count = 15
369
        self.EnsEMBL.last_req += 2
370
        self.EnsEMBL.getArchiveById(id="ENSG00000157764")
371
372
        # check request count has reset to zero
373
        self.assertEqual(self.EnsEMBL.req_count, 0)
374
375
    @pytest.mark.live
376
    def test_methodNotImplemented(self) -> None:
377
        """Testing a not implemented method"""
378
379
        # Add a non supported method
380
        pyensemblrest.ensemblrest.ensembl_api_table["notImplemented"] = {
381
            "doc": "Uses the given identifier to return the archived sequence",
382
            "url": "/archive/id/{{id}}",
383
            "method": "HEAD",
384
            "content_type": "application/json",
385
        }
386
387
        # register this method
388
        self.EnsEMBL.__dict__["notImplemented"] = self.EnsEMBL.register_api_func(
389
            "notImplemented", pyensemblrest.ensembl_config.ensembl_api_table
390
        )
391
392
        # Set __doc__ for generic class method
393
        self.EnsEMBL.__dict__[
394
            "notImplemented"
395
        ].__doc__ = pyensemblrest.ensemblrest.ensembl_api_table["notImplemented"]["doc"]
396
397
        # add function name to the class methods
398
        self.EnsEMBL.__dict__["notImplemented"].__name__ = "notImplemented"
399
400
        # call the new function and deal with the exception
401
        self.assertRaises(
402
            NotImplementedError, self.EnsEMBL.notImplemented, id="ENSG00000157764"
403
        )
404
405
    def __something_bad(self, curl_cmd: str, last_response: Response) -> None:
406
        """A function to test 'something bad' message"""
407
408
        # execute the curl cmd and get data as a dictionary
409
        reference = jsonFromCurl(curl_cmd)
410
411
        # instantiate a fake response
412
        fakeResponse = FakeResponse(
413
            headers=last_response.headers,
414
            status_code=400,
415
            text="""{"error":"something bad has happened"}""",
416
        )
417
        test = self.EnsEMBL.parseResponse(fakeResponse)
418
419
        # testing values
420
        self.assertDictEqual(reference, test)
421
        self.assertGreaterEqual(self.EnsEMBL.last_attempt, 1)
422
423
    @pytest.mark.live
424
    def test_SomethingBad(self) -> None:
425
        """Deal with the {"error":"something bad has happened"} message"""
426
427
        # get the curl cmd from ensembl site:
428
        curl_cmd = "curl 'https://rest.ensembl.org/archive/id/ENSG00000157764?' -H 'Content-type:application/json'"
429
430
        # get a request
431
        self.EnsEMBL.getArchiveById(id="ENSG00000157764")
432
433
        # retrieve last_reponse
434
        last_response = self.EnsEMBL.last_response
435
436
        # call generic function
437
        self.__something_bad(curl_cmd, last_response)
438
439
    @pytest.mark.live
440
    def test_SomethingBadPOST(self) -> None:
441
        """Deal with the {"error":"something bad has happened"} message using a POST method"""
442
443
        curl_cmd = (
444
            """curl 'https://rest.ensembl.org/lookup/id' -H 'Content-type:application/json' """
445
            """-H 'Accept:application/json' -X POST -d '{ "ids" : ["ENSG00000157764", "ENSG00000248378"] }'"""
446
        )
447
448
        # execute EnsemblRest function
449
        self.EnsEMBL.getLookupByMultipleIds(ids=["ENSG00000157764", "ENSG00000248378"])
450
451
        # retrieve last_reponse
452
        last_response = self.EnsEMBL.last_response
453
454
        # call generic function
455
        self.__something_bad(curl_cmd, last_response)
456
457
    @pytest.mark.live
458
    def test_LDFeatureContainerAdaptor(self) -> None:
459
        """Deal with the {"error":"Something went wrong while fetching from LDFeatureContainerAdaptor"} message"""
460
461
        curl_cmd = (
462
            """curl 'https://rest.ensembl.org/ld/human/pairwise/rs6792369/"""
463
            """rs1042779?population_name=1000GENOMES:phase_3:KHV;r2=0.85' -H 'Content-type:application/json'"""
464
        )
465
466
        # execute the curl cmd an get data as a dictionary
467
        reference = jsonFromCurl(curl_cmd)
468
469
        # get a request
470
        self.EnsEMBL.getLdPairwise(
471
            species="human",
472
            id1="rs6792369",
473
            id2="rs1042779",
474
            population_name="1000GENOMES:phase_3:KHV",
475
            r2=0.85,
476
        )
477
478
        # retrieve last_reponse
479
        response = self.EnsEMBL.last_response
480
481
        # instantiate a fake response
482
        fakeResponse = FakeResponse(
483
            headers=response.headers,
484
            status_code=400,
485
            text="""{"error":"Something went wrong while fetching from LDFeatureContainerAdaptor"}""",
486
        )
487
        test = self.EnsEMBL.parseResponse(fakeResponse)
488
489
        # testing values
490
        self.assertEqual(reference, test)
491
        self.assertGreaterEqual(self.EnsEMBL.last_attempt, 1)
492
493
494
class EnsemblRestArchive(EnsemblRest):
495
    """A class to deal with ensemblrest archive methods"""
496
497
    @pytest.mark.live
498
    def test_getArchiveById(self) -> None:
499
        """Test archive GET endpoint"""
500
501
        # get the curl cmd from ensembl site:
502
        curl_cmd = "curl 'https://rest.ensembl.org/archive/id/ENSG00000157764?' -H 'Content-type:application/json'"
503
504
        # execute the curl cmd an get data as a dictionary
505
        reference = jsonFromCurl(curl_cmd)
506
507
        # execute EnsemblRest function
508
        test = self.EnsEMBL.getArchiveById(id="ENSG00000157764")
509
510
        # testing values
511
        self.assertDictEqual(reference, test)
512
513
    @pytest.mark.live
514
    def test_getXMLArchiveById(self) -> None:
515
        """text archive GET endpoint returning XML"""
516
517
        # get the curl cmd from ensembl site:
518
        curl_cmd = "curl 'https://rest.ensembl.org/archive/id/ENSG00000157764?' -H 'Content-type:text/xml'"
519
520
        # execute the curl cmd an get data as a dictionary
521
        reference = launch(curl_cmd)
522
523
        # execute EnsemblRest function
524
        test = self.EnsEMBL.getArchiveById(
525
            id="ENSG00000157764", content_type="text/xml"
526
        )
527
528
        # testing values
529
        self.assertEqual(reference, test)
530
531
    @pytest.mark.live
532
    def test_getArchiveByMultipleIds(self) -> None:
533
        """Test archive POST endpoint"""
534
535
        curl_cmd = (
536
            """curl 'https://rest.ensembl.org/archive/id' -H 'Content-type:application/json' """
537
            """-H 'Accept:application/json' -X POST -d '{ "id" : ["ENSG00000157764", "ENSG00000248378"] }'"""
538
        )
539
540
        # execute the curl cmd an get data as a dictionary
541
        reference = jsonFromCurl(curl_cmd)
542
543
        # execute EnsemblRest function
544
        test = self.EnsEMBL.getArchiveByMultipleIds(
545
            id=["ENSG00000157764", "ENSG00000248378"]
546
        )
547
548
        # testing values
549
        self.assertListEqual(reference, test)
550
551
552
class EnsemblRestComparative(EnsemblRest):
553
    """A class to deal with ensemblrest comparative genomics methods"""
554
555
    @pytest.mark.live
556
    def test_getCafeGeneTreeById(self) -> None:
557
        """Test genetree by id GET method"""
558
559
        curl_cmd = (
560
            """curl 'https://rest.ensembl.org/cafe/genetree/id/ENSGT00390000003602?' """
561
            """-H 'Content-type:application/json'"""
562
        )
563
564
        # execute the curl cmd an get data as a dictionary
565
        reference = jsonFromCurl(curl_cmd)
566
567
        # execute EnsemblRest function. Dealing with application/json is simpler,
568
        # since text/x-phyloxml+xml may change elements order
569
        test = self.EnsEMBL.getCafeGeneTreeById(
570
            id="ENSGT00390000003602", content_type="application/json"
571
        )
572
573
        # testing values
574
        self.assertTrue(compareNested(reference, test))
575
576
    @pytest.mark.live
577
    def test_getCafeGeneTreeMemberBySymbol(self) -> None:
578
        """Test genetree by symbol GET method"""
579
580
        curl_cmd = (
581
            """curl 'https://rest.ensembl.org/cafe/genetree/member/symbol/homo_sapiens/"""
582
            """BRCA2?prune_species=cow;prune_taxon=9526' -H 'Content-type:application/json'"""
583
        )
584
585
        # execute the curl cmd an get data as a dictionary
586
        reference = jsonFromCurl(curl_cmd)
587
588
        # execute EnsemblRest function. Dealing with application/json is simpler,
589
        # since text/x-phyloxml+xml may change elements order
590
        test = self.EnsEMBL.getCafeGeneTreeMemberBySymbol(
591
            species="human",
592
            symbol="BRCA2",
593
            prune_species="cow",
594
            prune_taxon=9526,
595
            content_type="application/json",
596
        )
597
598
        # testing values
599
        self.assertTrue(compareNested(reference, test))
600
601
    @pytest.mark.live
602
    def test_getCafeGeneTreeMemberById(self) -> None:
603
        """Test genetree by member id GET method"""
604
605
        curl_cmd = (
606
            """curl 'https://rest.ensembl.org/cafe/genetree/member/id/"""
607
            """homo_sapiens/ENSG00000157764?' -H 'Content-type:application/json'"""
608
        )
609
610
        # execute the curl cmd an get data as a dictionary
611
        reference = jsonFromCurl(curl_cmd)
612
613
        # Execute EnsemblRest function. Dealing with application/json is simpler,
614
        # since text/x-phyloxml+xml may change elements order
615
        test = self.EnsEMBL.getCafeGeneTreeMemberById(
616
            id="ENSG00000157764",
617
            species="homo_sapiens",
618
            content_type="application/json",
619
        )
620
621
        # Set self.maxDiff to None to see differences
622
        # self.maxDiff = None
623
624
        # testing values. Since json are nested dictionary and lists,
625
        # and they are not hashable, I need to order list before checking equality,
626
        # and I need to ensure that dictionaries have the same keys and values
627
        self.assertTrue(compareNested(reference, test))
628
629
    @pytest.mark.live
630
    def test_getGeneTreeById(self) -> None:
631
        """Test genetree by id GET method"""
632
633
        curl_cmd = (
634
            """curl 'https://rest.ensembl.org/genetree/id/ENSGT00390000003602?' """
635
            """-H 'Content-type:application/json'"""
636
        )
637
638
        # execute the curl cmd an get data as a dictionary
639
        reference = jsonFromCurl(curl_cmd)
640
641
        # execute EnsemblRest function. Dealing with application/json is simpler,
642
        # since text/x-phyloxml+xml may change elements order
643
        test = self.EnsEMBL.getGeneTreeById(
644
            id="ENSGT00390000003602", content_type="application/json"
645
        )
646
647
        # testing values
648
        self.assertTrue(compareNested(reference, test))
649
650
    @pytest.mark.live
651
    def test_getGeneTreeMemberBySymbol(self) -> None:
652
        """Test genetree by symbol GET method"""
653
654
        curl_cmd = (
655
            """curl 'https://rest.ensembl.org/genetree/member/symbol/homo_sapiens/"""
656
            """BRCA2?prune_species=cow;prune_taxon=9526' -H 'Content-type:application/json'"""
657
        )
658
659
        # execute the curl cmd an get data as a dictionary
660
        reference = jsonFromCurl(curl_cmd)
661
662
        # execute EnsemblRest function. Dealing with application/json is simpler,
663
        # since text/x-phyloxml+xml may change elements order
664
        test = self.EnsEMBL.getGeneTreeMemberBySymbol(
665
            species="human",
666
            symbol="BRCA2",
667
            prune_species="cow",
668
            prune_taxon=9526,
669
            content_type="application/json",
670
        )
671
672
        # testing values
673
        self.assertTrue(compareNested(reference, test))
674
675
    @pytest.mark.live
676
    def test_getGeneTreeMemberById(self) -> None:
677
        """Test genetree by member id GET method"""
678
679
        curl_cmd = (
680
            """curl 'https://rest.ensembl.org/genetree/member/id/"""
681
            """homo_sapiens/ENSG00000157764?' -H 'Content-type:application/json'"""
682
        )
683
684
        # execute the curl cmd an get data as a dictionary
685
        reference = jsonFromCurl(curl_cmd)
686
687
        # Execute EnsemblRest function. Dealing with application/json is simpler,
688
        # since text/x-phyloxml+xml may change elements order
689
        test = self.EnsEMBL.getGeneTreeMemberById(
690
            id="ENSG00000157764",
691
            species="homo_sapiens",
692
            content_type="application/json",
693
        )
694
695
        # Set self.maxDiff to None to see differences
696
        # self.maxDiff = None
697
698
        # testing values. Since json are nested dictionary and lists,
699
        # and they are not hashable, I need to order list before checking equality,
700
        # and I need to ensure that dictionaries have the same keys and values
701
        self.assertTrue(compareNested(reference, test))
702
703
    @pytest.mark.live
704
    def test_getAlignmentByRegion(self) -> None:
705
        """Test get genomic alignment region GET method"""
706
707
        curl_cmd = (
708
            """curl 'https://rest.ensembl.org/alignment/region/homo_sapiens/"""
709
            """X:1000000..1000100:1?species_set_group=mammals' -H 'Content-type:application/json'"""
710
        )
711
712
        # execute the curl cmd an get data as a dictionary
713
        reference = jsonFromCurl(curl_cmd)
714
715
        # execute EnsemblRest function. Dealing with application/json is simpler
716
        test = self.EnsEMBL.getAlignmentByRegion(
717
            species="homo_sapiens",
718
            region="X:1000000..1000100:1",
719
            species_set_group="mammals",
720
        )
721
722
        # testing values. Values in list can have different order
723
        self.assertTrue(compareNested(reference, test))
724
725
    @pytest.mark.live
726
    def test_getHomologyById(self) -> None:
727
        """test get homology by Id GET method"""
728
729
        curl_cmd = (
730
            """curl 'https://rest.ensembl.org/homology/id/homo_sapiens/ENSG00000157764?' """
731
            """-H 'Content-type:application/json'"""
732
        )
733
734
        # execute the curl cmd an get data as a dictionary
735
        reference = jsonFromCurl(curl_cmd)
736
737
        # execute EnsemblRest function. Dealing with application/json is simpler,
738
        #  since text/x-phyloxml+xml may change elements order
739
        test = self.EnsEMBL.getHomologyById(
740
            id="ENSG00000157764", species="homo_sapiens"
741
        )
742
743
        # testing values. Since json are nested dictionary and lists,
744
        # and they are not hashable, I need to order list before checking equality,
745
        # and I need to ensure that dictionaries have the same keys and values
746
        self.assertTrue(compareNested(reference, test))
747
748
    @pytest.mark.live
749
    def test_getHomologyBySymbol(self) -> None:
750
        """test get homology by symbol"""
751
752
        curl_cmd = """curl 'https://rest.ensembl.org/homology/symbol/human/BRCA2?' -H 'Content-type:application/json'"""
753
754
        # execute the curl cmd an get data as a dictionary
755
        reference = jsonFromCurl(curl_cmd)
756
757
        # execute EnsemblRest function. Dealing with application/json is simpler,
758
        # since text/x-phyloxml+xml may change elements order
759
        test = self.EnsEMBL.getHomologyBySymbol(species="human", symbol="BRCA2")
760
761
        # testing values. Since json are nested dictionary and lists, and they are not hashable,
762
        # I need to order list before checking equality,
763
        # and I need to ensure that dictionaries have the same keys and values
764
        self.assertTrue(compareNested(reference, test))
765
766
767
class EnsemblRestXref(EnsemblRest):
768
    """A class to deal with ensemblrest cross references methods"""
769
770
    @pytest.mark.live
771
    def test_getXrefsBySymbol(self) -> None:
772
        """Testing get XRef by Id GET method"""
773
774
        curl_cmd = (
775
            """curl 'https://rest.ensembl.org/xrefs/symbol/homo_sapiens/BRCA2?' """
776
            """-H 'Content-type:application/json'"""
777
        )
778
779
        # execute the curl cmd an get data as a dictionary
780
        reference = jsonFromCurl(curl_cmd)
781
782
        # execute EnsemblRest function
783
        test = self.EnsEMBL.getXrefsBySymbol(species="human", symbol="BRCA2")
784
785
        # testing values
786
        self.assertTrue(compareNested(reference, test))
787
788
    @pytest.mark.live
789
    def test_getXrefsById(self) -> None:
790
        """Testing get XRef by Id GET method"""
791
792
        curl_cmd = """curl 'https://rest.ensembl.org/xrefs/id/ENSG00000157764?' -H 'Content-type:application/json'"""
793
794
        # execute the curl cmd an get data as a dictionary
795
        reference = jsonFromCurl(curl_cmd)
796
797
        # execute EnsemblRest function
798
        test = self.EnsEMBL.getXrefsById(id="ENSG00000157764")
799
800
        # testing values
801
        self.assertTrue(compareNested(reference, test))
802
803
    @pytest.mark.live
804
    def test_getXrefsByName(self) -> None:
805
        """Testing get XRef by Id GET method"""
806
807
        curl_cmd = """curl 'https://rest.ensembl.org/xrefs/name/human/BRCA2?' -H 'Content-type:application/json'"""
808
809
        # execute the curl cmd an get data as a dictionary
810
        reference = jsonFromCurl(curl_cmd)
811
812
        # execute EnsemblRest function
813
        test = self.EnsEMBL.getXrefsByName(species="human", name="BRCA2")
814
815
        # testing values
816
        self.assertTrue(compareNested(reference, test))
817
818
819
class EnsemblRestInfo(EnsemblRest):
820
    """A class to deal with ensemblrest information methods"""
821
822
    @pytest.mark.live
823
    def test_getInfoAnalysis(self) -> None:
824
        """Testing Info analysis GET method"""
825
826
        curl_cmd = """curl 'https://rest.ensembl.org/info/analysis/homo_sapiens?' -H 'Content-type:application/json'"""
827
828
        # execute the curl cmd an get data as a dictionary
829
        reference = jsonFromCurl(curl_cmd)
830
831
        # execute EnsemblRest function
832
        test = self.EnsEMBL.getInfoAnalysis(species="homo_sapiens")
833
834
        # testing values
835
        self.assertTrue(compareNested(reference, test))
836
837
    @pytest.mark.live
838
    def test_getInfoAssembly(self) -> None:
839
        """Testing Info assembly GET method"""
840
841
        curl_cmd = """curl 'https://rest.ensembl.org/info/assembly/homo_sapiens?' -H 'Content-type:application/json'"""
842
843
        # execute the curl cmd an get data as a dictionary
844
        reference = jsonFromCurl(curl_cmd)
845
846
        # execute EnsemblRest function
847
        test = self.EnsEMBL.getInfoAssembly(species="homo_sapiens")
848
849
        # testing values
850
        self.assertTrue(compareNested(reference, test))
851
852
    @pytest.mark.live
853
    def test_getInfoAssemblyRegion(self) -> None:
854
        """Testing Info Assembly by region GET method"""
855
856
        curl_cmd = """curl 'https://rest.ensembl.org/info/assembly/homo_sapiens/X?' -H 'Content-type:application/json'"""
857
858
        # execute the curl cmd an get data as a dictionary
859
        reference = jsonFromCurl(curl_cmd)
860
861
        # execute EnsemblRest function
862
        test = self.EnsEMBL.getInfoAssemblyRegion(
863
            species="homo_sapiens", region_name="X"
864
        )
865
866
        # testing values
867
        self.assertTrue(compareNested(reference, test))
868
869
    # @pytest.mark.skip(reason="Keeps timing out - check if working here https://rest.ensembl.org/info/biotypes/homo_sapiens")
870
    @pytest.mark.live
871
    def test_getInfoBiotypes(self) -> None:
872
        """Testing Info BioTypes GET method"""
873
874
        curl_cmd = """curl 'https://rest.ensembl.org/info/biotypes/homo_sapiens?' -H 'Content-type:application/json'"""
875
876
        # execute the curl cmd an get data as a dictionary
877
        reference = jsonFromCurl(curl_cmd)
878
879
        # execute EnsemblRest function
880
        test = self.EnsEMBL.getInfoBiotypes(species="homo_sapiens")
881
882
        # testing values
883
        self.assertTrue(compareNested(reference, test))
884
885
    @pytest.mark.live
886
    def test_getInfoBiotypesByGroup(self) -> None:
887
        """Testing Info BioTypes by Group GET method"""
888
889
        curl_cmd = """curl 'https://rest.ensembl.org/info/biotypes/groups/coding/gene?' -H 'Content-type:application/json'"""
890
891
        # execute the curl cmd an get data as a dictionary
892
        reference = jsonFromCurl(curl_cmd)
893
894
        # execute EnsemblRest function
895
        test = self.EnsEMBL.getInfoBiotypesByGroup(group="coding", object_type="gene")
896
897
        # testing values
898
        self.assertTrue(compareNested(reference, test))
899
900
    @pytest.mark.live
901
    def test_getInfoBiotypesByName(self) -> None:
902
        """Testing Info BioTypes by Name GET method"""
903
904
        curl_cmd = """curl 'https://rest.ensembl.org/info/biotypes/name/protein_coding/gene?' -H 'Content-type:application/json'"""
905
906
        # execute the curl cmd an get data as a dictionary
907
        reference = jsonFromCurl(curl_cmd)
908
909
        # execute EnsemblRest function
910
        test = self.EnsEMBL.getInfoBiotypesByName(
911
            name="protein_coding", object_type="gene"
912
        )
913
914
        # testing values
915
        self.assertTrue(compareNested(reference, test))
916
917
    @pytest.mark.live
918
    def test_getInfoComparaMethods(self) -> None:
919
        """Testing Info Compara Methods GET method"""
920
921
        curl_cmd = """curl 'https://rest.ensembl.org/info/compara/methods/?' -H 'Content-type:application/json'"""
922
923
        # execute the curl cmd an get data as a dictionary
924
        reference = jsonFromCurl(curl_cmd)
925
926
        # execute EnsemblRest function
927
        test = self.EnsEMBL.getInfoComparaMethods()
928
929
        # testing values
930
        self.assertTrue(compareNested(reference, test))
931
932
    @pytest.mark.live
933
    def test_getInfoComparaSpeciesSets(self) -> None:
934
        """Testing Info Compara Species Sets GET method"""
935
936
        curl_cmd = (
937
            """curl 'https://rest.ensembl.org/info/compara/species_sets/EPO?' """
938
            """-H 'Content-type:application/json'"""
939
        )
940
941
        # execute the curl cmd an get data as a dictionary
942
        reference = jsonFromCurl(curl_cmd)
943
944
        # execute EnsemblRest function
945
        test = self.EnsEMBL.getInfoComparaSpeciesSets(methods="EPO")
946
947
        # testing values
948
        self.assertTrue(compareNested(reference, test))
949
950
    @pytest.mark.live
951
    def test_getInfoComparas(self) -> None:
952
        """Testing Info Compara GET method"""
953
954
        curl_cmd = """curl 'https://rest.ensembl.org/info/comparas?' -H 'Content-type:application/json'"""
955
956
        # execute the curl cmd an get data as a dictionary
957
        reference = jsonFromCurl(curl_cmd)
958
959
        # execute EnsemblRest function
960
        test = self.EnsEMBL.getInfoComparas()
961
962
        # testing values
963
        self.assertTrue(compareNested(reference, test))
964
965
    @pytest.mark.live
966
    def test_getInfoData(self) -> None:
967
        """Testing Info Data GET method"""
968
969
        curl_cmd = """curl 'https://rest.ensembl.org/info/data/?' -H 'Content-type:application/json'"""
970
971
        # execute the curl cmd an get data as a dictionary
972
        reference = jsonFromCurl(curl_cmd)
973
974
        # execute EnsemblRest function
975
        test = self.EnsEMBL.getInfoData()
976
977
        # testing values
978
        self.assertTrue(compareNested(reference, test))
979
980
    @pytest.mark.live
981
    def test_getInfoEgVersion(self) -> None:
982
        """Testing EgVersion GET method"""
983
984
        curl_cmd = """curl 'https://rest.ensembl.org/info/eg_version?' -H 'Content-type:application/json'"""
985
986
        # execute the curl cmd an get data as a dictionary
987
        reference = jsonFromCurl(curl_cmd)
988
989
        # execute EnsemblRest function
990
        test = self.EnsEMBL.getInfoEgVersion()
991
992
        # testing values
993
        self.assertTrue(compareNested(reference, test))
994
995
    @pytest.mark.live
996
    def test_getInfoExternalDbs(self) -> None:
997
        """Testing Info External Dbs GET method"""
998
999
        curl_cmd = (
1000
            """curl 'https://rest.ensembl.org/info/external_dbs/homo_sapiens?' """
1001
            """-H 'Content-type:application/json'"""
1002
        )
1003
1004
        # execute the curl cmd an get data as a dictionary
1005
        reference = jsonFromCurl(curl_cmd)
1006
1007
        # execute EnsemblRest function
1008
        test = self.EnsEMBL.getInfoExternalDbs(species="homo_sapiens")
1009
1010
        # testing values
1011
        self.assertTrue(compareNested(reference, test))
1012
1013
    @pytest.mark.live
1014
    def test_getInfoDivisions(self) -> None:
1015
        """Testing Info Divisions GET method"""
1016
1017
        curl_cmd = """curl 'https://rest.ensembl.org/info/divisions?' -H 'Content-type:application/json'"""
1018
1019
        # execute the curl cmd an get data as a dictionary
1020
        reference = jsonFromCurl(curl_cmd)
1021
1022
        # execute EnsemblRest function
1023
        test = self.EnsEMBL.getInfoDivisions()
1024
1025
        # testing values
1026
        self.assertTrue(compareNested(reference, test))
1027
1028
    @pytest.mark.live
1029
    def test_getInfoGenomesByName(self) -> None:
1030
        """Testing Info Genomes by Name GET method"""
1031
1032
        curl_cmd = (
1033
            """curl 'https://rest.ensembl.org/info/genomes/"""
1034
            """homo_sapiens?' -H 'Content-type:application/json'"""
1035
        )
1036
1037
        # execute the curl cmd an get data as a dictionary
1038
        reference = jsonFromCurl(curl_cmd)
1039
1040
        # execute EnsemblRest function
1041
        test = self.EnsEMBL.getInfoGenomesByName(name="homo_sapiens")
1042
1043
        # normalize both responses to handle inconsistent API formats
1044
        reference_normalized = normalize_genomes_response(reference)
1045
        test_normalized = normalize_genomes_response(test)
1046
1047
        # testing values
1048
        self.assertTrue(compareNested(reference_normalized, test_normalized))
1049
1050
    @pytest.mark.live
1051
    def test_getInfoGenomesByAccession(self) -> None:
1052
        """Testing Info Genomes by Accession GET method"""
1053
1054
        curl_cmd = (
1055
            """curl 'https://rest.ensembl.org/info/genomes/accession/U00096?' """
1056
            """-H 'Content-type:application/json'"""
1057
        )
1058
1059
        # execute the curl cmd an get data as a dictionary
1060
        reference = jsonFromCurl(curl_cmd)
1061
1062
        # execute EnsemblRest function
1063
        test = self.EnsEMBL.getInfoGenomesByAccession(accession="U00096")
1064
1065
        # normalize both responses to handle inconsistent API formats
1066
        reference_normalized = normalize_genomes_response(reference)
1067
        test_normalized = normalize_genomes_response(test)
1068
1069
        # testing values
1070
        self.assertTrue(compareNested(reference_normalized, test_normalized))
1071
1072
    @pytest.mark.live
1073
    def test_getInfoGenomesByAssembly(self) -> None:
1074
        """Testing Info Genomes by Assembly GET method"""
1075
1076
        curl_cmd = (
1077
            """curl 'https://rest.ensembl.org/info/genomes/assembly/GCA_902167145.1?' """
1078
            """-H 'Content-type:application/json'"""
1079
        )
1080
1081
        # execute the curl cmd an get data as a dictionary
1082
        reference = jsonFromCurl(curl_cmd)
1083
1084
        # execute EnsemblRest function
1085
        test = self.EnsEMBL.getInfoGenomesByAssembly(assembly_id="GCA_902167145.1")
1086
1087
        # normalize both responses to handle inconsistent API formats
1088
        reference_normalized = normalize_genomes_response(reference)
1089
        test_normalized = normalize_genomes_response(test)
1090
1091
        # testing values
1092
        self.assertTrue(compareNested(reference_normalized, test_normalized))
1093
1094
    @pytest.mark.live
1095
    def test_getInfoGenomesByDivision(self) -> None:
1096
        """Testing Info Genomes by Division GET method"""
1097
1098
        curl_cmd = (
1099
            """curl 'https://rest.ensembl.org/info/genomes/division/EnsemblPlants?' """
1100
            """-H 'Content-type:application/json'"""
1101
        )
1102
1103
        # execute the curl cmd an get data as a dictionary
1104
        reference = jsonFromCurl(curl_cmd)
1105
1106
        # execute EnsemblRest function
1107
        test = self.EnsEMBL.getInfoGenomesByDivision(division="EnsemblPlants")
1108
1109
        # normalize both responses to handle inconsistent API formats
1110
        reference_normalized = normalize_genomes_response(reference)
1111
        test_normalized = normalize_genomes_response(test)
1112
1113
        # testing values
1114
        self.assertTrue(compareNested(reference_normalized, test_normalized))
1115
1116
    @pytest.mark.live
1117
    def test_getInfoGenomesByTaxonomy(self) -> None:
1118
        """Testing Info Genomes by Taxonomy GET method"""
1119
1120
        curl_cmd = (
1121
            """curl 'https://rest.ensembl.org/info/genomes/taxonomy/Arabidopsis?' """
1122
            """-H 'Content-type:application/json'"""
1123
        )
1124
1125
        # execute the curl cmd an get data as a dictionary
1126
        reference = jsonFromCurl(curl_cmd)
1127
1128
        # execute EnsemblRest function
1129
        test = self.EnsEMBL.getInfoGenomesByTaxonomy(taxon_name="Arabidopsis")
1130
1131
        # normalize both responses to handle inconsistent API formats
1132
        reference_normalized = normalize_genomes_response(reference)
1133
        test_normalized = normalize_genomes_response(test)
1134
1135
        # testing values
1136
        self.assertTrue(compareNested(reference_normalized, test_normalized))
1137
1138
    @pytest.mark.live
1139
    def test_getInfoPing(self) -> None:
1140
        """Testing Info Ping GET method"""
1141
1142
        curl_cmd = """curl 'https://rest.ensembl.org/info/ping?' -H 'Content-type:application/json'"""
1143
1144
        # execute the curl cmd an get data as a dictionary
1145
        reference = jsonFromCurl(curl_cmd)
1146
1147
        # execute EnsemblRest function
1148
        test = self.EnsEMBL.getInfoPing()
1149
1150
        # testing values
1151
        self.assertTrue(compareNested(reference, test))
1152
1153
    @pytest.mark.live
1154
    def test_getInfoRest(self) -> None:
1155
        """Testing Info REST GET method"""
1156
1157
        curl_cmd = """curl 'https://rest.ensembl.org/info/rest?' -H 'Content-type:application/json'"""
1158
1159
        # execute the curl cmd an get data as a dictionary
1160
        reference = jsonFromCurl(curl_cmd)
1161
1162
        # execute EnsemblRest function
1163
        test = self.EnsEMBL.getInfoRest()
1164
1165
        # testing values
1166
        self.assertEqual(reference, test)
1167
1168
    @pytest.mark.live
1169
    def test_getInfoSoftware(self) -> None:
1170
        """Testing Info Software GET method"""
1171
1172
        curl_cmd = """curl 'https://rest.ensembl.org/info/software?' -H 'Content-type:application/json'"""
1173
1174
        # execute the curl cmd an get data as a dictionary
1175
        reference = jsonFromCurl(curl_cmd)
1176
1177
        # execute EnsemblRest function
1178
        test = self.EnsEMBL.getInfoSoftware()
1179
1180
        # testing values
1181
        self.assertTrue(compareNested(reference, test))
1182
1183
    @pytest.mark.live
1184
    def test_getInfoSpecies(self) -> None:
1185
        """Testing Info Species GET method"""
1186
1187
        curl_cmd = """curl 'https://rest.ensembl.org/info/species?division=ensembl' -H 'Content-type:application/json'"""
1188
1189
        # execute the curl cmd an get data as a dictionary
1190
        reference = jsonFromCurl(curl_cmd)
1191
1192
        # execute EnsemblRest function
1193
        test = self.EnsEMBL.getInfoSpecies(division="ensembl")
1194
1195
        self.assertTrue(compareNested(reference, test))
1196
1197
    @pytest.mark.live
1198
    def test_getInfoVariationBySpecies(self) -> None:
1199
        """Testing Info Variation by species GET method"""
1200
1201
        curl_cmd = """curl 'https://rest.ensembl.org/info/variation/homo_sapiens?' -H 'Content-type:application/json'"""
1202
1203
        # execute the curl cmd an get data as a dictionary
1204
        reference = jsonFromCurl(curl_cmd)
1205
1206
        # execute EnsemblRest function
1207
        test = self.EnsEMBL.getInfoVariationBySpecies(species="homo_sapiens")
1208
1209
        # testing values
1210
        self.assertTrue(compareNested(reference, test))
1211
1212
    @pytest.mark.live
1213
    def test_getInfoVariationConsequenceTypes(self) -> None:
1214
        """Testing Info Variation Consequence Types GET method"""
1215
1216
        curl_cmd = """curl 'https://rest.ensembl.org/info/variation/consequence_types?' -H 'Content-type:application/json'"""
1217
1218
        # execute the curl cmd an get data as a dictionary
1219
        reference = jsonFromCurl(curl_cmd)
1220
1221
        # execute EnsemblRest function
1222
        test = self.EnsEMBL.getInfoVariationConsequenceTypes()
1223
1224
        # testing values
1225
        self.assertTrue(compareNested(reference, test))
1226
1227
    @pytest.mark.live
1228
    def test_getInfoVariationPopulationIndividuals(self) -> None:
1229
        """Testing Info Variation Population Individuals GET method"""
1230
1231
        curl_cmd = (
1232
            """curl 'https://rest.ensembl.org/info/variation/populations/human/1000GENOMES:phase_3:ASW?' """
1233
            """-H 'Content-type:application/json'"""
1234
        )
1235
1236
        # execute the curl cmd an get data as a dictionary
1237
        reference = jsonFromCurl(curl_cmd)
1238
1239
        # execute EnsemblRest function
1240
        test = self.EnsEMBL.getInfoVariationPopulationIndividuals(
1241
            species="human",
1242
            population_name="1000GENOMES:phase_3:ASW",
1243
        )
1244
1245
        # testing values
1246
        self.assertTrue(compareNested(reference, test))
1247
1248
    @pytest.mark.live
1249
    def test_getInfoVariationPopulations(self) -> None:
1250
        """Testing Info Variation Populations GET method"""
1251
1252
        curl_cmd = (
1253
            """curl 'https://rest.ensembl.org/info/variation/populations/homo_sapiens?filter=LD' """
1254
            """-H 'Content-type:application/json'"""
1255
        )
1256
1257
        # execute the curl cmd an get data as a dictionary
1258
        reference = jsonFromCurl(curl_cmd)
1259
1260
        # execute EnsemblRest function
1261
        test = self.EnsEMBL.getInfoVariationPopulations(
1262
            species="homo_sapiens", filter="LD"
1263
        )
1264
1265
        # testing values
1266
        self.assertTrue(compareNested(reference, test))
1267
1268
1269
class EnsemblRestLinkage(EnsemblRest):
1270
    """A class to deal with ensemblrest linkage disequilibrium methods"""
1271
1272
    @pytest.mark.live
1273
    def test_getLdId(self) -> None:
1274
        """Testing get LD ID GET method"""
1275
1276
        curl_cmd = (
1277
            """curl 'https://rest.ensembl.org/ld/human/rs1042779/1000GENOMES:phase_3:KHV?"""
1278
            """window_size=10;d_prime=1.0' -H 'Content-type:application/json'"""
1279
        )
1280
1281
        # execute the curl cmd an get data as a dictionary
1282
        reference = jsonFromCurl(curl_cmd)
1283
1284
        # execute EnsemblRest function
1285
        test = self.EnsEMBL.getLdId(
1286
            species="human",
1287
            id="rs1042779",
1288
            population_name="1000GENOMES:phase_3:KHV",
1289
            window_size=10,
1290
            d_prime=1.0,
1291
        )
1292
1293
        # testing values
1294
        self.assertTrue(compareNested(reference, test))
1295
1296
    @pytest.mark.live
1297
    def test_getLdPairwise(self) -> None:
1298
        """Testing get LD pairwise GET method"""
1299
1300
        curl_cmd = (
1301
            """curl 'https://rest.ensembl.org/ld/human/pairwise/rs6792369/rs1042779?"""
1302
            """population_name=1000GENOMES:phase_3:KHV;r2=0.85' -H 'Content-type:application/json'"""
1303
        )
1304
1305
        # execute the curl cmd an get data as a dictionary
1306
        reference = jsonFromCurl(curl_cmd)
1307
1308
        # execute EnsemblRest function
1309
        test = self.EnsEMBL.getLdPairwise(
1310
            species="human",
1311
            id1="rs6792369",
1312
            id2="rs1042779",
1313
            population_name="1000GENOMES:phase_3:KHV",
1314
            r2=0.85,
1315
        )
1316
1317
        # testing values
1318
        self.assertTrue(compareNested(reference, test))
1319
1320
    @pytest.mark.live
1321
    def test_getLdRegion(self) -> None:
1322
        """Testing get LD region GET method"""
1323
1324
        curl_cmd = (
1325
            """curl 'https://rest.ensembl.org/ld/human/region/6:25837556..25843455/"""
1326
            """1000GENOMES:phase_3:KHV?r2=0.85:d_prime=1.0' -H 'Content-type:application/json'"""
1327
        )
1328
1329
        # execute the curl cmd an get data as a dictionary
1330
        reference = jsonFromCurl(curl_cmd)
1331
1332
        # execute EnsemblRest function
1333
        test = self.EnsEMBL.getLdRegion(
1334
            species="human",
1335
            region="6:25837556..25843455",
1336
            population_name="1000GENOMES:phase_3:KHV",
1337
            r2=0.85,
1338
            d_prime=1.0,
1339
        )
1340
1341
        self.assertTrue(compareNested(reference, test))
1342
1343
1344
class EnsemblRestLookUp(EnsemblRest):
1345
    """A class to deal with ensemblrest LookUp methods"""
1346
1347
    @pytest.mark.live
1348
    def test_getLookupById(self) -> None:
1349
        """Testing get lookup by id GET method"""
1350
1351
        curl_cmd = (
1352
            """curl 'https://rest.ensembl.org/lookup/id/ENSG00000157764?expand=1' """
1353
            """-H 'Content-type:application/json'"""
1354
        )
1355
1356
        # execute the curl cmd an get data as a dictionary
1357
        reference = jsonFromCurl(curl_cmd)
1358
1359
        # execute EnsemblRest function
1360
        test = self.EnsEMBL.getLookupById(id="ENSG00000157764", expand=1)
1361
1362
        # testing values
1363
        self.assertTrue(compareNested(reference, test))
1364
1365
    @pytest.mark.live
1366
    def test_getLookupByMultipleIds(self) -> None:
1367
        """Testing get lookup id POST method"""
1368
1369
        curl_cmd = (
1370
            """curl 'https://rest.ensembl.org/lookup/id' -H 'Content-type:application/json' """
1371
            """-H 'Accept:application/json' -X POST -d '{ "ids" : ["ENSG00000157764", "ENSG00000248378" ] }'"""
1372
        )
1373
1374
        # execute the curl cmd an get data as a dictionary
1375
        reference = jsonFromCurl(curl_cmd)
1376
1377
        # execute EnsemblRest function
1378
        test = self.EnsEMBL.getLookupByMultipleIds(
1379
            ids=["ENSG00000157764", "ENSG00000248378"]
1380
        )
1381
1382
        # testing values
1383
        self.assertTrue(compareNested(reference, test))
1384
1385
    @pytest.mark.live
1386
    def test_getLookupByMultipleIds_additional_arguments(self) -> None:
1387
        """Testing get lookup id POST method with additional arguments"""
1388
1389
        curl_cmd = (
1390
            """curl 'https://rest.ensembl.org/lookup/id?expand=1' -H 'Content-type:application/json' """
1391
            """-H 'Accept:application/json' -X POST -d '{ "ids" : ["ENSG00000157764", "ENSG00000248378"] }'"""
1392
        )
1393
1394
        # execute the curl cmd an get data as a dictionary
1395
        reference = jsonFromCurl(curl_cmd)
1396
1397
        # execute EnsemblRest function
1398
        test = self.EnsEMBL.getLookupByMultipleIds(
1399
            ids=["ENSG00000157764", "ENSG00000248378"], expand=1
1400
        )
1401
1402
        # testing values
1403
        self.assertTrue(compareNested(reference, test))
1404
1405
    @pytest.mark.live
1406
    def test_getLookupBySymbol(self) -> None:
1407
        """Testing get lookup by species GET method"""
1408
1409
        curl_cmd = (
1410
            """curl 'https://rest.ensembl.org/lookup/symbol/homo_sapiens/BRCA2?expand=1' """
1411
            """-H 'Content-type:application/json'"""
1412
        )
1413
1414
        # execute the curl cmd an get data as a dictionary
1415
        reference = jsonFromCurl(curl_cmd)
1416
1417
        # execute EnsemblRest function
1418
        test = self.EnsEMBL.getLookupBySymbol(
1419
            species="homo_sapiens", symbol="BRCA2", expand=1
1420
        )
1421
1422
        # testing values
1423
        self.assertTrue(compareNested(reference, test))
1424
1425
    @pytest.mark.live
1426
    def test_getLookupByMultipleSymbols(self) -> None:
1427
        """Testing get lookup by species POST method"""
1428
1429
        curl_cmd = (
1430
            """curl 'https://rest.ensembl.org/lookup/symbol/homo_sapiens' -H 'Content-type:application/json' """
1431
            """-H 'Accept:application/json' -X POST -d '{ "symbols" : ["BRCA2", "BRAF" ] }'"""
1432
        )
1433
1434
        # execute the curl cmd an get data as a dictionary
1435
        reference = jsonFromCurl(curl_cmd)
1436
1437
        # execute EnsemblRest function
1438
        test = self.EnsEMBL.getLookupByMultipleSymbols(
1439
            species="homo_sapiens", symbols=["BRCA2", "BRAF"]
1440
        )
1441
1442
        # testing values
1443
        self.assertTrue(compareNested(reference, test))
1444
1445
    @pytest.mark.live
1446
    def test_getLookupByMultipleSymbols_additional_arguments(self) -> None:
1447
        """Testing get lookup by species POST method  with additional arguments"""
1448
1449
        curl_cmd = (
1450
            """curl 'https://rest.ensembl.org/lookup/symbol/homo_sapiens?expand=1' """
1451
            """-H 'Content-type:application/json' -H 'Accept:application/json' """
1452
            """-X POST -d '{ "symbols" : ["BRCA2", "BRAF" ] }'"""
1453
        )
1454
1455
        # execute the curl cmd an get data as a dictionary
1456
        reference = jsonFromCurl(curl_cmd)
1457
1458
        # execute EnsemblRest function
1459
        test = self.EnsEMBL.getLookupByMultipleSymbols(
1460
            species="homo_sapiens", symbols=["BRCA2", "BRAF"], expand=1
1461
        )
1462
1463
        # testing values
1464
        self.assertTrue(compareNested(reference, test))
1465
1466
1467
class EnsemblRestMapping(EnsemblRest):
1468
    """A class to deal with ensemblrest mapping methods"""
1469
1470
    @pytest.mark.live
1471
    def test_getMapCdnaToRegion(self) -> None:
1472
        """Testing map CDNA to region GET method"""
1473
1474
        curl_cmd = (
1475
            """curl 'https://rest.ensembl.org/map/cdna/ENST00000288602/100..300?' """
1476
            """-H 'Content-type:application/json'"""
1477
        )
1478
1479
        # execute the curl cmd an get data as a dictionary
1480
        reference = jsonFromCurl(curl_cmd)
1481
1482
        # execute EnsemblRest function
1483
        test = self.EnsEMBL.getMapCdnaToRegion(id="ENST00000288602", region="100..300")
1484
1485
        # testing values
1486
        self.assertTrue(compareNested(reference, test))
1487
1488
    @pytest.mark.live
1489
    def test_getMapCdsToRegion(self) -> None:
1490
        """Testing map CDS to region GET method"""
1491
1492
        curl_cmd = (
1493
            """curl 'https://rest.ensembl.org/map/cds/ENST00000288602/1..1000?' """
1494
            """-H 'Content-type:application/json'"""
1495
        )
1496
1497
        # execute the curl cmd an get data as a dictionary
1498
        reference = jsonFromCurl(curl_cmd)
1499
1500
        # execute EnsemblRest function
1501
        test = self.EnsEMBL.getMapCdsToRegion(id="ENST00000288602", region="1..1000")
1502
1503
        # testing values
1504
        self.assertTrue(compareNested(reference, test))
1505
1506
    @pytest.mark.live
1507
    def test_getMapAssemblyOneToTwo(self) -> None:
1508
        """Testing converting coordinates between assemblies GET method"""
1509
1510
        curl_cmd = (
1511
            """curl 'https://rest.ensembl.org/map/human/GRCh37/X:1000000..1000100:1/GRCh38?' """
1512
            """-H 'Content-type:application/json'"""
1513
        )
1514
1515
        # execute the curl cmd an get data as a dictionary
1516
        reference = jsonFromCurl(curl_cmd)
1517
1518
        # execute EnsemblRest function
1519
        test = self.EnsEMBL.getMapAssemblyOneToTwo(
1520
            species="human",
1521
            asm_one="GRCh37",
1522
            region="X:1000000..1000100:1",
1523
            asm_two="GRCh38",
1524
        )
1525
1526
        # testing values
1527
        self.assertTrue(compareNested(reference, test))
1528
1529
    @pytest.mark.live
1530
    def test_getMapTranslationToRegion(self) -> None:
1531
        """Testing converting protein(traslation) to genomic coordinates GET method"""
1532
1533
        curl_cmd = (
1534
            """curl 'https://rest.ensembl.org/map/translation/ENSP00000288602/100..300?' """
1535
            """-H 'Content-type:application/json'"""
1536
        )
1537
1538
        # execute the curl cmd an get data as a dictionary
1539
        reference = jsonFromCurl(curl_cmd)
1540
1541
        # execute EnsemblRest function
1542
        test = self.EnsEMBL.getMapTranslationToRegion(
1543
            id="ENSP00000288602", region="100..300"
1544
        )
1545
1546
        # testing values
1547
        self.assertTrue(compareNested(reference, test))
1548
1549
1550
class EnsemblRestOT(EnsemblRest):
1551
    """A class to deal with ensemblrest ontologies and taxonomy methods"""
1552
1553
    @pytest.mark.live
1554
    def test_getAncestorsById(self) -> None:
1555
        """Testing get ancestors by id GET method"""
1556
1557
        curl_cmd = (
1558
            """curl 'https://rest.ensembl.org/ontology/ancestors/GO:0005667?' """
1559
            """-H 'Content-type:application/json'"""
1560
        )
1561
1562
        # execute the curl cmd an get data as a dictionary
1563
        reference = jsonFromCurl(curl_cmd)
1564
1565
        # execute EnsemblRest function
1566
        test = self.EnsEMBL.getAncestorsById(id="GO:0005667")
1567
1568
        # testing values
1569
        self.assertTrue(compareNested(reference, test))
1570
1571
    @pytest.mark.live
1572
    def test_getAncestorsChartById(self) -> None:
1573
        """Testing get ancestors chart by id GET method"""
1574
1575
        curl_cmd = (
1576
            """curl 'https://rest.ensembl.org/ontology/ancestors/chart/GO:0005667?' """
1577
            """-H 'Content-type:application/json'"""
1578
        )
1579
1580
        # execute the curl cmd an get data as a dictionary
1581
        reference = jsonFromCurl(curl_cmd)
1582
1583
        # execute EnsemblRest function
1584
        test = self.EnsEMBL.getAncestorsChartById(id="GO:0005667")
1585
1586
        # testing values
1587
        self.assertTrue(compareNested(reference, test))
1588
1589
    @pytest.mark.live
1590
    def test_getDescendantsById(self) -> None:
1591
        """Testing get descendants by id GET method"""
1592
1593
        curl_cmd = (
1594
            """curl 'https://rest.ensembl.org/ontology/descendants/GO:0005667?' """
1595
            """-H 'Content-type:application/json'"""
1596
        )
1597
1598
        # execute the curl cmd an get data as a dictionary
1599
        reference = jsonFromCurl(curl_cmd)
1600
1601
        # execute EnsemblRest function
1602
        test = self.EnsEMBL.getDescendantsById(id="GO:0005667")
1603
1604
        # testing values
1605
        self.assertTrue(compareNested(reference, test))
1606
1607
    @pytest.mark.live
1608
    def test_getOntologyById(self) -> None:
1609
        """Test get ontology by id GET method"""
1610
1611
        curl_cmd = """curl 'https://rest.ensembl.org/ontology/id/GO:0005667?' -H 'Content-type:application/json'"""
1612
1613
        # execute the curl cmd an get data as a dictionary
1614
        reference = jsonFromCurl(curl_cmd)
1615
1616
        # execute EnsemblRest function
1617
        test = self.EnsEMBL.getOntologyById(id="GO:0005667")
1618
1619
        # testing values
1620
        self.assertTrue(compareNested(reference, test))
1621
1622
    @pytest.mark.live
1623
    def test_getOntologyByName(self) -> None:
1624
        """Test get ontology by name GET method"""
1625
1626
        curl_cmd = (
1627
            """curl 'https://rest.ensembl.org/ontology/name/%s?' -H 'Content-type:application/json'"""
1628
            % (urllib.parse.quote("transcription factor complex"))
1629
        )
1630
1631
        # execute the curl cmd an get data as a dictionary
1632
        reference = jsonFromCurl(curl_cmd)
1633
1634
        # execute EnsemblRest function
1635
        test = self.EnsEMBL.getOntologyByName(name="transcription factor complex")
1636
1637
        # testing values
1638
        self.assertTrue(compareNested(reference, test))
1639
1640
    @pytest.mark.live
1641
    def test_getTaxonomyClassificationById(self) -> None:
1642
        """Testing get taxonomy classification by id GET method"""
1643
1644
        curl_cmd = """curl 'https://rest.ensembl.org/taxonomy/classification/9606?' -H 'Content-type:application/json'"""
1645
1646
        # execute the curl cmd an get data as a dictionary
1647
        reference = jsonFromCurl(curl_cmd)
1648
1649
        # execute EnsemblRest function
1650
        test = self.EnsEMBL.getTaxonomyClassificationById(id="9606")
1651
1652
        # testing values
1653
        self.assertTrue(compareNested(reference, test))
1654
1655
    @pytest.mark.live
1656
    def test_getTaxonomyById(self) -> None:
1657
        """Testing get Taxonomy by id GET method"""
1658
1659
        curl_cmd = """curl 'https://rest.ensembl.org/taxonomy/id/9606?' -H 'Content-type:application/json'"""
1660
1661
        # execute the curl cmd an get data as a dictionary
1662
        reference = jsonFromCurl(curl_cmd)
1663
1664
        # execute EnsemblRest function
1665
        test = self.EnsEMBL.getTaxonomyById(id="9606")
1666
1667
        # testing values. Since json are nested dictionary and lists, and they are not hashable,
1668
        # I need to order list before checking equality,
1669
        # and I need to ensure that dictionaries have the same keys and values
1670
        self.assertTrue(compareNested(reference, test))
1671
1672
    @pytest.mark.live
1673
    def test_getTaxonomyByName(self) -> None:
1674
        """Testing get taxonomy by name GET method"""
1675
1676
        curl_cmd = """curl 'https://rest.ensembl.org/taxonomy/name/human?' -H 'Content-type:application/json'"""
1677
1678
        # execute the curl cmd an get data as a dictionary
1679
        reference = jsonFromCurl(curl_cmd)
1680
1681
        # execute EnsemblRest function
1682
        test = self.EnsEMBL.getTaxonomyByName(name="human")
1683
1684
        # testing values. Since json are nested dictionary and lists, and they are not hashable,
1685
        # I need to order list before checking equality,
1686
        # and I need to ensure that dictionaries have the same keys and values
1687
        self.assertTrue(compareNested(reference, test))
1688
1689
1690
class EnsemblRestOverlap(EnsemblRest):
1691
    """A class to deal with ensemblrest overlap methods"""
1692
1693
    @pytest.mark.live
1694
    def test_getOverlapById(self) -> None:
1695
        """Testing get Overlap by ID GET method"""
1696
1697
        curl_cmd = (
1698
            """curl 'https://rest.ensembl.org/overlap/id/ENSG00000157764?feature=gene' """
1699
            """-H 'Content-type:application/json'"""
1700
        )
1701
1702
        # execute the curl cmd an get data as a dictionary
1703
        reference = jsonFromCurl(curl_cmd)
1704
1705
        # execute EnsemblRest function
1706
        test = self.EnsEMBL.getOverlapById(id="ENSG00000157764", feature="gene")
1707
1708
        # testing values
1709
        self.assertTrue(compareNested(reference, test))
1710
1711
    @pytest.mark.live
1712
    def test_getOverlapByRegion(self) -> None:
1713
        """Testing get Overlap by region GET method"""
1714
1715
        curl_cmd = (
1716
            """curl 'https://rest.ensembl.org/overlap/region/human/7:140424943-140624564?feature=gene;"""
1717
            """feature=transcript;feature=cds;feature=exon' -H 'Content-type:application/json'"""
1718
        )
1719
1720
        # execute the curl cmd an get data as a dictionary
1721
        reference = jsonFromCurl(curl_cmd)
1722
1723
        # execute EnsemblRest function
1724
        test = self.EnsEMBL.getOverlapByRegion(
1725
            species="human",
1726
            region="7:140424943-140624564",
1727
            feature=["gene", "transcript", "cds", "exon"],
1728
        )
1729
1730
        # testing values
1731
        self.assertTrue(compareNested(reference, test))
1732
1733
    @pytest.mark.live
1734
    def test_getOverlapByTranslation(self) -> None:
1735
        """Testing get Overlab by traslation GET method"""
1736
1737
        curl_cmd = (
1738
            """curl 'https://rest.ensembl.org/overlap/translation/ENSP00000288602?type=Superfamily' """
1739
            """-H 'Content-type:application/json'"""
1740
        )
1741
1742
        # execute the curl cmd an get data as a dictionary
1743
        reference = jsonFromCurl(curl_cmd)
1744
1745
        # execute EnsemblRest function
1746
        test = self.EnsEMBL.getOverlapByTranslation(
1747
            id="ENSP00000288602", type="SuperFamily"
1748
        )
1749
1750
        # testing values
1751
        self.assertTrue(compareNested(reference, test))
1752
1753
1754
class EnsemblRestPhenotypeAnnotations(EnsemblRest):
1755
    """A class to deal with ensemblrest phenotype annotations methods"""
1756
1757
    @pytest.mark.live
1758
    def test_getPhenotypeByAccession(self) -> None:
1759
        """Testing get phenotype by accession GET method"""
1760
1761
        curl_cmd = (
1762
            """curl 'https://rest.ensembl.org/phenotype/accession/human/EFO:0003900?' """
1763
            """-H 'Content-type:application/json'"""
1764
        )
1765
1766
        # execute the curl cmd an get data as a dictionary
1767
        reference = jsonFromCurl(curl_cmd)
1768
1769
        # execute EnsemblRest function
1770
        test = self.EnsEMBL.getPhenotypeByAccession(
1771
            species="human", accession="EFO:0003900"
1772
        )
1773
1774
        # testing values
1775
        self.assertTrue(compareNested(reference, test))
1776
1777
    @pytest.mark.live
1778
    def test_getPhenotypeByGene(self) -> None:
1779
        """Testing get phenotype by gene GET method"""
1780
1781
        curl_cmd = (
1782
            """curl 'https://rest.ensembl.org/phenotype/gene/human/ENSG00000157764?' """
1783
            """-H 'Content-type:application/json'"""
1784
        )
1785
1786
        # execute the curl cmd an get data as a dictionary
1787
        reference = jsonFromCurl(curl_cmd)
1788
1789
        # execute EnsemblRest function
1790
        test = self.EnsEMBL.getPhenotypeByGene(species="human", gene="ENSG00000157764")
1791
1792
        # testing values
1793
        self.assertTrue(compareNested(reference, test))
1794
1795
    @pytest.mark.live
1796
    def test_getPhenotypeByRegion(self) -> None:
1797
        """Testing get phenotype by region GET method"""
1798
1799
        curl_cmd = (
1800
            """curl 'https://rest.ensembl.org/phenotype/region/human/9:22125500-22136000:1?' """
1801
            """-H 'Content-type:application/json'"""
1802
        )
1803
1804
        # execute the curl cmd an get data as a dictionary
1805
        reference = jsonFromCurl(curl_cmd)
1806
1807
        # execute EnsemblRest function
1808
        test = self.EnsEMBL.getPhenotypeByRegion(
1809
            species="human", region="9:22125500-22136000:1"
1810
        )
1811
1812
        # testing values
1813
        self.assertTrue(compareNested(reference, test))
1814
1815
    @pytest.mark.live
1816
    def test_getPhenotypeByTerm(self) -> None:
1817
        """Testing get phenotype by term GET method"""
1818
1819
        curl_cmd = (
1820
            """curl 'https://rest.ensembl.org/phenotype/term/human/coffee%20consumption?' """
1821
            """-H 'Content-type:application/json'"""
1822
        )
1823
1824
        # execute the curl cmd an get data as a dictionary
1825
        reference = jsonFromCurl(curl_cmd)
1826
1827
        # execute EnsemblRest function
1828
        test = self.EnsEMBL.getPhenotypeByTerm(
1829
            species="human", term="coffee consumption"
1830
        )
1831
1832
        # testing values
1833
        self.assertTrue(compareNested(reference, test))
1834
1835
1836
class EnsemblRestRegulation(EnsemblRest):
1837
    """A class to deal with ensemblrest regulation methods"""
1838
1839
    @pytest.mark.live
1840
    def test_getRegulationBindingMatrix(self) -> None:
1841
        """Testing get regulation binding matrix GET method"""
1842
1843
        curl_cmd = (
1844
            """curl 'https://rest.ensembl.org/species/human/binding_matrix/ENSPFM0001?' """
1845
            """-H 'Content-type:application/json'"""
1846
        )
1847
1848
        # execute the curl cmd an get data as a dictionary
1849
        reference = jsonFromCurl(curl_cmd)
1850
1851
        # execute EnsemblRest function
1852
        test = self.EnsEMBL.getRegulationBindingMatrix(
1853
            species="human", binding_matrix="ENSPFM0001"
1854
        )
1855
1856
        # testing values
1857
        self.assertTrue(compareNested(reference, test))
1858
1859
1860
class EnsemblRestSequence(EnsemblRest):
1861
    """A class to deal with ensemblrest sequence methods"""
1862
1863
    @pytest.mark.live
1864
    def test_getSequenceById(self) -> None:
1865
        """Testing get sequence by ID GET method"""
1866
1867
        curl_cmd = (
1868
            """curl 'https://rest.ensembl.org/sequence/id/CCDS5863.1?object_type=transcript;"""
1869
            """db_type=otherfeatures;type=cds;species=human' -H 'Content-type:application/json'"""
1870
        )
1871
1872
        # execute the curl cmd an get data as a dictionary
1873
        reference = jsonFromCurl(curl_cmd)
1874
1875
        # execute EnsemblRest function
1876
        test = self.EnsEMBL.getSequenceById(
1877
            id="CCDS5863.1",
1878
            object_type="transcript",
1879
            db_type="otherfeatures",
1880
            type="cds",
1881
            species="human",
1882
        )
1883
1884
        # testing values
1885
        self.assertTrue(compareNested(reference, test))
1886
1887
    @pytest.mark.live
1888
    def test_getSequenceByMultipleIds(self) -> None:
1889
        """Testing get sequence by ID POST method"""
1890
1891
        curl_cmd = (
1892
            """curl 'https://rest.ensembl.org/sequence/id' -H 'Content-type:application/json' """
1893
            """-H 'Accept:application/json' -X POST -d '{ "ids" : ["ENSG00000157764", "ENSG00000248378"]}'"""
1894
        )
1895
1896
        # execute the curl cmd an get data as a dictionary
1897
        reference = jsonFromCurl(curl_cmd)
1898
1899
        # execute EnsemblRest function
1900
        test = self.EnsEMBL.getSequenceByMultipleIds(
1901
            ids=["ENSG00000157764", "ENSG00000248378"]
1902
        )
1903
1904
        # testing values
1905
        self.assertTrue(compareNested(reference, test))
1906
1907
    @pytest.mark.live
1908
    def test_getSequenceByMultipleIds_additional_arguments(self) -> None:
1909
        """Testing getSequenceByMultipleIds with mask="soft" and expand_3prime=100"""
1910
1911
        curl_cmd = (
1912
            """curl 'https://rest.ensembl.org/sequence/id?mask=soft;expand_3prime=100' """
1913
            """-H 'Content-type:application/json' -H 'Accept:application/json' """
1914
            """-X POST -d '{ "ids" : ["ENSG00000157764", "ENSG00000248378" ] }'"""
1915
        )
1916
1917
        # execute the curl cmd an get data as a dictionary
1918
        reference = jsonFromCurl(curl_cmd)
1919
1920
        # execute EnsemblRest function
1921
        test = self.EnsEMBL.getSequenceByMultipleIds(
1922
            ids=["ENSG00000157764", "ENSG00000248378"], expand_3prime=100, mask="soft"
1923
        )
1924
1925
        # testing values
1926
        self.assertTrue(compareNested(reference, test))
1927
1928
    @pytest.mark.live
1929
    def test_getSequenceByRegion(self) -> None:
1930
        """Testing get sequence by region GET method"""
1931
1932
        curl_cmd = (
1933
            """curl 'https://rest.ensembl.org/sequence/region/human/X:1000000..1000100:1?' """
1934
            """-H 'Content-type:application/json'"""
1935
        )
1936
1937
        # execute the curl cmd an get data as a dictionary
1938
        reference = jsonFromCurl(curl_cmd)
1939
1940
        # execute EnsemblRest function
1941
        test = self.EnsEMBL.getSequenceByRegion(
1942
            species="human", region="X:1000000..1000100:1"
1943
        )
1944
1945
        # testing values
1946
        self.assertTrue(compareNested(reference, test))
1947
1948
    @pytest.mark.live
1949
    def test_getSequenceByMultipleRegions(self) -> None:
1950
        """Testing get sequence by region POST method"""
1951
1952
        curl_cmd = (
1953
            """curl 'https://rest.ensembl.org/sequence/region/human' -H 'Content-type:application/json' """
1954
            """-H 'Accept:application/json' -X POST """
1955
            """-d '{ "regions" : ["X:1000000..1000100:1", "ABBA01004489.1:1..100"] }'"""
1956
        )
1957
1958
        # execute the curl cmd an get data as a dictionary
1959
        reference = jsonFromCurl(curl_cmd)
1960
1961
        # execute EnsemblRest function
1962
        test = self.EnsEMBL.getSequenceByMultipleRegions(
1963
            species="human", regions=["X:1000000..1000100:1", "ABBA01004489.1:1..100"]
1964
        )
1965
1966
        # testing values
1967
        self.assertTrue(compareNested(reference, test))
1968
1969
    @pytest.mark.live
1970
    def test_getSequenceByMultipleRegions_additional_arguments(self) -> None:
1971
        """Testing get sequence by region POST method with mask="soft" and expand_3prime=100"""
1972
1973
        curl_cmd = (
1974
            """curl 'https://rest.ensembl.org/sequence/region/human?mask=soft;expand_3prime=100' """
1975
            """-H 'Content-type:application/json' -H 'Accept:application/json' -X POST """
1976
            """-d '{ "regions" : ["X:1000000..1000100:1", "ABBA01004489.1:1..100"] }'"""
1977
        )
1978
1979
        # execute the curl cmd an get data as a dictionary
1980
        reference = jsonFromCurl(curl_cmd)
1981
1982
        # execute EnsemblRest function
1983
        test = self.EnsEMBL.getSequenceByMultipleRegions(
1984
            species="human",
1985
            regions=["X:1000000..1000100:1", "ABBA01004489.1:1..100"],
1986
            expand_3prime=100,
1987
            mask="soft",
1988
        )
1989
1990
        # testing values
1991
        self.assertTrue(compareNested(reference, test))
1992
1993
1994
class EnsemblRestHaplotype(EnsemblRest):
1995
    """A class to deal with ensemblrest transcript haplotypes methods"""
1996
1997
    @pytest.mark.live
1998
    def test_getTranscriptHaplotypes(self) -> None:
1999
        """Testing get transcripts Haplotypes GET method"""
2000
2001
        curl_cmd = (
2002
            """curl 'https://rest.ensembl.org/transcript_haplotypes/homo_sapiens/ENST00000288602?' """
2003
            """-H 'Content-type:application/json'"""
2004
        )
2005
2006
        # execute the curl cmd an get data as a dictionary
2007
        reference = jsonFromCurl(curl_cmd)
2008
2009
        # execute EnsemblRest function
2010
        test = self.EnsEMBL.getTranscriptHaplotypes(
2011
            species="homo_sapiens", id="ENST00000288602"
2012
        )
2013
2014
        # testing values
2015
        self.assertTrue(compareNested(reference, test))
2016
2017
2018
class EnsemblRestVEP(EnsemblRest):
2019
    """A class to deal with ensemblrest Variant Effect Predictor methods"""
2020
2021
    @pytest.mark.live
2022
    def test_getVariantConsequencesByHGVSNotation(self) -> None:
2023
        """Testing get Variant Consequences by HFVS notation GET method"""
2024
2025
        curl_cmd = """curl 'https://rest.ensembl.org/vep/human/hgvs/ENST00000366667:c.803C>T?' -H 'Content-type:application/json'"""
2026
2027
        # execute the curl cmd an get data as a dictionary
2028
        reference = jsonFromCurl(curl_cmd)
2029
2030
        # execute EnsemblRest function
2031
        test = self.EnsEMBL.getVariantConsequencesByHGVSNotation(
2032
            species="human", hgvs_notation="ENST00000366667:c.803C>T"
2033
        )
2034
2035
        # testing values
2036
        self.assertTrue(compareNested(reference, test))
2037
2038
    @pytest.mark.live
2039
    def test_getVariantConsequencesByMultipleHGVSnotations(self) -> None:
2040
        """Testing get variant consequences by multiple HFVS notations POST method"""
2041
2042
        curl_cmd = (
2043
            """curl -X POST 'https://rest.ensembl.org/vep/human/hgvs' """
2044
            """-d '{ "hgvs_notations" : ["ENST00000366667:c.803C>T", "9:g.22125504G>C"] }' """
2045
            """-H 'Content-type:application/json' -H 'Accept:application/json'"""
2046
        )
2047
2048
        # execute the curl cmd an get data as a dictionary
2049
        reference = jsonFromCurl(curl_cmd)
2050
2051
        # execute EnsemblRest function
2052
        test = self.EnsEMBL.getVariantConsequencesByMultipleHGVSNotations(
2053
            species="human",
2054
            hgvs_notations=["ENST00000366667:c.803C>T", "9:g.22125504G>C"],
2055
        )
2056
2057
        # testing values
2058
        self.assertTrue(compareNested(reference, test))
2059
2060
    @pytest.mark.live
2061
    def test_getVariantConsequencesById(self) -> None:
2062
        """Testing get variant Consequences by id GET method"""
2063
2064
        curl_cmd = """curl 'https://rest.ensembl.org/vep/human/id/COSM476?' -H 'Content-type:application/json'"""
2065
2066
        # execute the curl cmd an get data as a dictionary
2067
        reference = jsonFromCurl(curl_cmd)
2068
2069
        # execute EnsemblRest function
2070
        test = self.EnsEMBL.getVariantConsequencesById(species="human", id="COSM476")
2071
2072
        # testing values
2073
        self.assertTrue(compareNested(reference, test))
2074
2075
    @pytest.mark.live
2076
    def test_getVariantConsequencesByMultipleIds(self) -> None:
2077
        """Testing get variant Consequences by id POST method"""
2078
2079
        curl_cmd = (
2080
            """curl 'https://rest.ensembl.org/vep/human/id' -H 'Content-type:application/json' """
2081
            """-H 'Accept:application/json' -X POST -d '{ "ids" : ["rs56116432", "COSM476" ] }'"""
2082
        )
2083
2084
        # execute the curl cmd an get data as a dictionary
2085
        reference = jsonFromCurl(curl_cmd)
2086
2087
        # execute EnsemblRest function
2088
        test = self.EnsEMBL.getVariantConsequencesByMultipleIds(
2089
            species="human", ids=["rs56116432", "COSM476"]
2090
        )
2091
2092
        # testing values
2093
        self.assertTrue(compareNested(reference, test))
2094
2095
    @pytest.mark.live
2096
    def test_getVariantConsequencesByMultipleIds_additional_arguments(self) -> None:
2097
        """Testing get variant Consequences by id POST method using Blosum62=1, CSN=1"""
2098
2099
        curl_cmd = (
2100
            """curl 'https://rest.ensembl.org/vep/human/id?Blosum62=1;CSN=1' """
2101
            """-H 'Content-type:application/json' -H 'Accept:application/json' """
2102
            """-X POST -d '{ "ids" : ["rs56116432", "COSM476" ] }'"""
2103
        )
2104
2105
        # execute the curl cmd an get data as a dictionary
2106
        reference = jsonFromCurl(curl_cmd)
2107
2108
        # execute EnsemblRest function
2109
        test = self.EnsEMBL.getVariantConsequencesByMultipleIds(
2110
            species="human", ids=["rs56116432", "COSM476"], Blosum62=1, CSN=1
2111
        )
2112
2113
        # testing values
2114
        self.assertTrue(compareNested(reference, test))
2115
2116
    @pytest.mark.live
2117
    def test_getVariantConsequencesByRegion(self) -> None:
2118
        """Testing get variant consequences by Region GET method"""
2119
2120
        curl_cmd = (
2121
            """curl 'https://rest.ensembl.org/vep/human/region/9:22125503-22125502:1/C?' """
2122
            """-H 'Content-type:application/json'"""
2123
        )
2124
2125
        # execute the curl cmd an get data as a dictionary
2126
        reference = jsonFromCurl(curl_cmd)
2127
2128
        # execute EnsemblRest function
2129
        test = self.EnsEMBL.getVariantConsequencesByRegion(
2130
            species="human", region="9:22125503-22125502:1", allele="C"
2131
        )
2132
2133
        # testing values
2134
        self.assertTrue(compareNested(reference, test))
2135
2136
    @pytest.mark.live
2137
    def test_getVariantConsequencesByMultipleRegions(self) -> None:
2138
        """Testing get variant consequences by Region POST method"""
2139
2140
        curl_cmd = (
2141
            """curl 'https://rest.ensembl.org/vep/homo_sapiens/region' -H 'Content-type:application/json' """
2142
            """-H 'Accept:application/json' -X POST -d '{ "variants" : """
2143
            """["21 26960070 rs116645811 G A . . .", "21 26965148 rs1135638 G A . . ." ] }'"""
2144
        )
2145
2146
        # execute the curl cmd an get data as a dictionary
2147
        reference = jsonFromCurl(curl_cmd)
2148
2149
        # execute EnsemblRest function
2150
        test = self.EnsEMBL.getVariantConsequencesByMultipleRegions(
2151
            species="human",
2152
            variants=[
2153
                "21 26960070 rs116645811 G A . . .",
2154
                "21 26965148 rs1135638 G A . . .",
2155
            ],
2156
        )
2157
2158
        # testing values
2159
        self.assertTrue(compareNested(reference, test))
2160
2161
    @pytest.mark.live
2162
    def test_getVariantConsequencesByMultipleRegions_additional_arguments(self) -> None:
2163
        """Testing get variant consequences by Region POST method Blosum62=1, CSN=1"""
2164
2165
        curl_cmd = (
2166
            """curl 'https://rest.ensembl.org/vep/homo_sapiens/region?Blosum62=1;CSN=1' """
2167
            """-H 'Content-type:application/json' -H 'Accept:application/json' -X POST -d """
2168
            """'{ "variants" : ["21 26960070 rs116645811 G A . . .", "21 26965148 rs1135638 G A . . ." ] }'"""
2169
        )
2170
2171
        # execute the curl cmd an get data as a dictionary
2172
        reference = jsonFromCurl(curl_cmd)
2173
2174
        # execute EnsemblRest function
2175
        test = self.EnsEMBL.getVariantConsequencesByMultipleRegions(
2176
            species="human",
2177
            variants=[
2178
                "21 26960070 rs116645811 G A . . .",
2179
                "21 26965148 rs1135638 G A . . .",
2180
            ],
2181
            Blosum62=1,
2182
            CSN=1,
2183
        )
2184
2185
        # testing values
2186
        self.assertTrue(compareNested(reference, test))
2187
2188
2189
class EnsemblRestVariation(EnsemblRest):
2190
    """A class to deal with ensemblrest variation methods"""
2191
2192
    @pytest.mark.live
2193
    def test_getVariantRecoderById(self) -> None:
2194
        """Testing get variant recoder by id GET method"""
2195
2196
        curl_cmd = """curl 'https://rest.ensembl.org/variant_recoder/human/rs56116432?' -H 'Content-type:application/json'"""
2197
2198
        # execute the curl cmd an get data as a dictionary
2199
        reference = jsonFromCurl(curl_cmd)
2200
2201
        # execute EnsemblRest function
2202
        test = self.EnsEMBL.getVariationRecoderById(id="rs56116432", species="human")
2203
2204
        # testing values
2205
        self.assertTrue(compareNested(reference, test))
2206
2207
    @pytest.mark.live
2208
    def test_getVariantRecoderByMultipleIds(self) -> None:
2209
        """Testing get variant recoder by multiple ids POST method"""
2210
2211
        curl_cmd = (
2212
            """curl -X POST 'https://rest.ensembl.org/variant_recoder/human' """
2213
            """-d '{ "ids" : ["rs56116432", "rs1042779" ] }' """
2214
            """-H 'Content-type:application/json' -H 'Accept:application/json' """
2215
        )
2216
2217
        # execute the curl cmd an get data as a dictionary
2218
        reference = jsonFromCurl(curl_cmd)
2219
2220
        # execute EnsemblRest function
2221
        test = self.EnsEMBL.getVariationRecoderByMultipleIds(
2222
            ids=["rs56116432", "rs1042779"], species="human"
2223
        )
2224
2225
        # testing values
2226
        self.assertTrue(compareNested(reference, test))
2227
2228
    @pytest.mark.live
2229
    def test_getVariationById(self) -> None:
2230
        """Testing get variation by id GET method"""
2231
2232
        curl_cmd = """curl 'https://rest.ensembl.org/variation/human/rs56116432?' -H 'Content-type:application/json'"""
2233
2234
        # execute the curl cmd an get data as a dictionary
2235
        reference = jsonFromCurl(curl_cmd)
2236
2237
        # execute EnsemblRest function
2238
        test = self.EnsEMBL.getVariationById(id="rs56116432", species="homo_sapiens")
2239
2240
        # testing values
2241
        self.assertTrue(compareNested(reference, test))
2242
2243
    @pytest.mark.live
2244
    def test_getVariationByPMCID(self) -> None:
2245
        """Testing get variation by pmcid GET method"""
2246
2247
        curl_cmd = """curl 'https://rest.ensembl.org/variation/human/pmcid/PMC5002951?' -H 'Content-type:application/json'"""
2248
2249
        # execute the curl cmd an get data as a dictionary
2250
        reference = jsonFromCurl(curl_cmd)
2251
2252
        # execute EnsemblRest function
2253
        test = self.EnsEMBL.getVariationByPMCID(pmcid="PMC5002951", species="human")
2254
2255
        # testing values
2256
        self.assertTrue(compareNested(reference, test))
2257
2258
    @pytest.mark.live
2259
    def test_getVariationByPMID(self) -> None:
2260
        """Testing get variation by pmid GET method"""
2261
2262
        curl_cmd = """curl 'https://rest.ensembl.org/variation/human/pmid/26318936?' -H 'Content-type:application/json'"""
2263
2264
        # execute the curl cmd an get data as a dictionary
2265
        reference = jsonFromCurl(curl_cmd)
2266
2267
        # execute EnsemblRest function
2268
        test = self.EnsEMBL.getVariationByPMID(pmid="26318936", species="human")
2269
2270
        # testing values
2271
        self.assertTrue(compareNested(reference, test))
2272
2273
    @pytest.mark.live
2274
    def test_getVariationByMultipleIds(self) -> None:
2275
        """Testing get variation by id POST method"""
2276
2277
        curl_cmd = (
2278
            """curl 'https://rest.ensembl.org/variation/homo_sapiens' -H 'Content-type:application/json' """
2279
            """-H 'Accept:application/json' -X POST -d '{ "ids" : ["rs56116432", "COSM476" ] }'"""
2280
        )
2281
2282
        # execute the curl cmd an get data as a dictionary
2283
        reference = jsonFromCurl(curl_cmd)
2284
2285
        # execute EnsemblRest function
2286
        test = self.EnsEMBL.getVariationByMultipleIds(
2287
            ids=["rs56116432", "COSM476"], species="homo_sapiens"
2288
        )
2289
2290
        # testing values
2291
        self.assertTrue(compareNested(reference, test))
2292
2293
    @pytest.mark.live
2294
    def test_getVariationByMultipleIds_additional_arguments(self) -> None:
2295
        """Testing get variation by id POST method with genotypes=1"""
2296
2297
        curl_cmd = (
2298
            """curl 'https://rest.ensembl.org/variation/homo_sapiens?genotypes=1' """
2299
            """-H 'Content-type:application/json' -H 'Accept:application/json' """
2300
            """-X POST -d '{ "ids" : ["rs56116432", "COSM476" ] }'"""
2301
        )
2302
2303
        # execute the curl cmd an get data as a dictionary
2304
        reference = jsonFromCurl(curl_cmd)
2305
2306
        # execute EnsemblRest function
2307
        test = self.EnsEMBL.getVariationByMultipleIds(
2308
            ids=["rs56116432", "COSM476"], species="homo_sapiens", genotypes=1
2309
        )
2310
2311
        # testing values
2312
        self.assertTrue(compareNested(reference, test))
2313
2314
2315
class EnsemblRestVariationGA4GH(EnsemblRest):
2316
    """A class to deal with ensemblrest variation GA4GH methods"""
2317
2318
    @pytest.mark.live
2319
    def test_getGA4GHBeacon(self) -> None:
2320
        """Testing get GA4GH beacon GET method"""
2321
2322
        curl_cmd = """curl 'https://rest.ensembl.org/ga4gh/beacon?' -H 'Content-type:application/json' """
2323
2324
        # execute the curl cmd an get data as a dictionary
2325
        reference = jsonFromCurl(curl_cmd)
2326
2327
        # execute EnsemblRest function
2328
        test = self.EnsEMBL.getGA4GHBeacon()
2329
2330
        # testing values
2331
        self.assertTrue(compareNested(reference, test))
2332
2333
    @pytest.mark.live
2334
    def test_getGA4GHBeaconQuery(self) -> None:
2335
        """Testing get GA4GH beacon query GET method"""
2336
2337
        curl_cmd = (
2338
            """curl 'http://rest.ensembl.org/ga4gh/beacon/query?referenceBases=G;"""
2339
            """alternateBases=C;referenceName=9;assemblyId=GRCh38;start=22125503' """
2340
            """-H 'Content-type:application/json' """
2341
        )
2342
2343
        # execute the curl cmd an get data as a dictionary
2344
        reference = jsonFromCurl(curl_cmd)
2345
2346
        # execute EnsemblRest function
2347
        test = self.EnsEMBL.getGA4GHBeaconQuery(
2348
            referenceBases="G",
2349
            alternateBases="C",
2350
            referenceName=9,
2351
            assemblyId="GRCh38",
2352
            start=22125503,
2353
        )
2354
2355
        # testing values
2356
        self.assertTrue(compareNested(reference, test))
2357
2358
    @pytest.mark.live
2359
    def test_postGA4GHBeaconQuery(self) -> None:
2360
        """Testing get GA4GH beacon query POST method"""
2361
2362
        curl_cmd = (
2363
            """curl -X POST 'http://rest.ensembl.org/ga4gh/beacon/query' """
2364
            """-H 'Content-type:application/json' -H 'Accept:application/json' """
2365
            """-d '{ "referenceName": "9", "start": 22125503, "referenceBases": "G", """
2366
            """"alternateBases": "C", "assemblyId": "GRCh38"}'"""
2367
        )
2368
2369
        # execute the curl cmd an get data as a dictionary
2370
        reference = jsonFromCurl(curl_cmd)
2371
2372
        # execute EnsemblRest function
2373
        test = self.EnsEMBL.postGA4GHBeaconQuery(
2374
            referenceBases="G",
2375
            alternateBases="C",
2376
            referenceName=9,
2377
            assemblyId="GRCh38",
2378
            start=22125503,
2379
        )
2380
2381
        # testing values
2382
        self.assertTrue(compareNested(reference, test))
2383
2384
    @pytest.mark.live
2385
    def test_getGA4GHFeatures(self) -> None:
2386
        """Testing get GA4GH features GET method"""
2387
2388
        curl_cmd = """curl 'https://rest.ensembl.org/ga4gh/features/ENST00000408937.7?' -H 'Content-type:application/json' """
2389
2390
        # execute the curl cmd an get data as a dictionary
2391
        reference = jsonFromCurl(curl_cmd)
2392
2393
        # execute EnsemblRest function
2394
        test = self.EnsEMBL.getGA4GHFeaturesById(id="ENST00000408937.7")
2395
2396
        # testing values
2397
        self.assertTrue(compareNested(reference, test))
2398
2399
    @pytest.mark.live
2400
    def test_searchGA4GHFeatures(self) -> None:
2401
        """Testing GA4GH features search POST method"""
2402
2403
        curl_cmd = (
2404
            """curl 'https://rest.ensembl.org/ga4gh/features/search' -H 'Content-type:application/json' """
2405
            """-H 'Accept:application/json' -X POST -d '{ "start":39657458, "end": 39753127, """
2406
            """"referenceName":"20", "featureSetId": "", "parentId": "ENSG00000176515.1" }'"""
2407
        )
2408
2409
        # execute the curl cmd an get data as a dictionary
2410
        reference = jsonFromCurl(curl_cmd)
2411
2412
        # execute EnsemblRest function
2413
        test = self.EnsEMBL.searchGA4GHFeatures(
2414
            referenceName="20",
2415
            start=39657458,
2416
            end=39753127,
2417
            featureSetId="",
2418
            parentId="ENSG00000176515.1",
2419
        )
2420
2421
        # testing values
2422
        self.assertTrue(compareNested(reference, test))
2423
2424
    @pytest.mark.live
2425
    def test_searchGA4GHCallset(self) -> None:
2426
        """Testing GA4GH callset search POST method"""
2427
2428
        curl_cmd = (
2429
            """curl 'https://rest.ensembl.org/ga4gh/callsets/search' -H 'Content-type:application/json' """
2430
            """-H 'Accept:application/json' -X POST -d '{ "variantSetId": 1, "pageSize": 2  }'"""
2431
        )
2432
2433
        # execute the curl cmd an get data as a dictionary
2434
        reference = jsonFromCurl(curl_cmd)
2435
2436
        # execute EnsemblRest function
2437
        test = self.EnsEMBL.searchGA4GHCallset(variantSetId=1, pageSize=2)
2438
2439
        # testing values
2440
        self.assertTrue(compareNested(reference, test))
2441
2442
    @pytest.mark.live
2443
    def test_getGA4GHCallsetById(self) -> None:
2444
        """Testing get GA4GH callset by Id GET method"""
2445
2446
        curl_cmd = """curl 'https://rest.ensembl.org/ga4gh/callsets/1:NA19777?' -H 'Content-type:application/json'"""
2447
2448
        # execute the curl cmd an get data as a dictionary
2449
        reference = jsonFromCurl(curl_cmd)
2450
2451
        # execute EnsemblRest function
2452
        test = self.EnsEMBL.getGA4GHCallsetById(id="1:NA19777")
2453
2454
        # testing values
2455
        self.assertTrue(compareNested(reference, test))
2456
2457
    @pytest.mark.live
2458
    def test_searchGA4GHDatasets(self) -> None:
2459
        """Testing GA4GH search dataset POST method"""
2460
2461
        curl_cmd = (
2462
            """curl 'https://rest.ensembl.org/ga4gh/datasets/search' -H 'Content-type:application/json' """
2463
            """-H 'Accept:application/json' -X POST -d '{ "pageSize": 3 }'"""
2464
        )
2465
2466
        # execute the curl cmd an get data as a dictionary
2467
        reference = jsonFromCurl(curl_cmd)
2468
2469
        # execute EnsemblRest function
2470
        test = self.EnsEMBL.searchGA4GHDatasets(pageSize=3)
2471
2472
        # testing values
2473
        self.assertTrue(compareNested(reference, test))
2474
2475
    @pytest.mark.live
2476
    def test_getGA4GHDatasetsById(self) -> None:
2477
        """Testing GA4GH get dataset by Id GET method"""
2478
2479
        curl_cmd = (
2480
            """curl 'https://rest.ensembl.org/ga4gh/datasets/6e340c4d1e333c7a676b1710d2e3953c?' """
2481
            """-H 'Content-type:application/json'"""
2482
        )
2483
2484
        # execute the curl cmd an get data as a dictionary
2485
        reference = jsonFromCurl(curl_cmd)
2486
2487
        # execute EnsemblRest function
2488
        test = self.EnsEMBL.getGA4GHDatasetsById(id="6e340c4d1e333c7a676b1710d2e3953c")
2489
2490
        # testing values
2491
        self.assertTrue(compareNested(reference, test))
2492
2493
    @pytest.mark.live
2494
    def test_searchGA4GHFeatureset(self) -> None:
2495
        """Testing GA4GH featureset search POST method"""
2496
2497
        curl_cmd = (
2498
            """curl 'https://rest.ensembl.org/ga4gh/featuresets/search' -H 'Content-type:application/json' """
2499
            """-H 'Accept:application/json' -X POST -d '{ "datasetId": "Ensembl" }'"""
2500
        )
2501
2502
        # execute the curl cmd an get data as a dictionary
2503
        reference = jsonFromCurl(curl_cmd)
2504
2505
        # execute EnsemblRest function
2506
        test = self.EnsEMBL.searchGA4GHFeaturesets(
2507
            datasetId="Ensembl",
2508
        )
2509
2510
        # testing values
2511
        self.assertTrue(compareNested(reference, test))
2512
2513
    @pytest.mark.live
2514
    def test_getGA4GHFeaturesetById(self) -> None:
2515
        """Testing get GA4GH featureset GET method"""
2516
2517
        curl_cmd = """curl 'https://rest.ensembl.org/ga4gh/featuresets/Ensembl?' -H 'Content-type:application/json' """
2518
2519
        # execute the curl cmd an get data as a dictionary
2520
        reference = jsonFromCurl(curl_cmd)
2521
2522
        # execute EnsemblRest function
2523
        test = self.EnsEMBL.getGA4GHFeaturesetsById(id="Ensembl")
2524
2525
        # testing values
2526
        self.assertTrue(compareNested(reference, test))
2527
2528
    @pytest.mark.live
2529
    def test_getGA4GHVariantsById(self) -> None:
2530
        """Testing GA4GH get variant by Id GET method"""
2531
2532
        curl_cmd = """curl 'https://rest.ensembl.org/ga4gh/variants/1:rs61752113?' -H 'Content-type:application/json'"""
2533
2534
        # execute the curl cmd an get data as a dictionary
2535
        reference = jsonFromCurl(curl_cmd)
2536
2537
        # execute EnsemblRest function
2538
        test = self.EnsEMBL.getGA4GHVariantsById(id="1:rs61752113")
2539
2540
        # testing values
2541
        self.assertTrue(compareNested(reference, test))
2542
2543
    @pytest.mark.live
2544
    def test_searchGA4GHVariantAnnotations(self) -> None:
2545
        """Testing GA4GH variant annotations search POST method"""
2546
2547
        curl_cmd = (
2548
            """curl 'https://rest.ensembl.org/ga4gh/variantannotations/search' -H 'Content-type:application/json' """
2549
            """-H 'Accept:application/json' -X POST -d '{ "variantAnnotationSetId": "Ensembl", "referenceName": "22", """
2550
            """"start": 25000000 , "end": 25194457, "pageSize": 2}'"""
2551
        )
2552
2553
        # execute the curl cmd an get data as a dictionary
2554
        reference = jsonFromCurl(curl_cmd)
2555
2556
        # execute EnsemblRest function
2557
        test = self.EnsEMBL.searchGA4GHVariantAnnotations(
2558
            variantAnnotationSetId="Ensembl",
2559
            referenceName=22,
2560
            start=25000000,
2561
            end=25194457,
2562
            pageSize=2,
2563
        )
2564
2565
        # testing values
2566
        self.assertTrue(compareNested(reference, test))
2567
2568
    @pytest.mark.live
2569
    def test_searchGA4GHVariants(self) -> None:
2570
        """Testing GA4GH search variants POST method"""
2571
2572
        curl_cmd = (
2573
            """curl 'https://rest.ensembl.org/ga4gh/variants/search' -H 'Content-type:application/json' """
2574
            """-H 'Accept:application/json' -X POST -d '{ "variantSetId": 1, "referenceName": 22,"""
2575
            """"start": 17190024, "end": 17671934, "callSetIds":["1:NA19777", "1:HG01242", "1:HG01142"],"""
2576
            """"pageToken":"", "pageSize": 1 }'"""
2577
        )
2578
2579
        # execute the curl cmd an get data as a dictionary
2580
        reference = jsonFromCurl(curl_cmd)
2581
2582
        # execute EnsemblRest function
2583
        test = self.EnsEMBL.searchGA4GHVariants(
2584
            variantSetId=1,
2585
            referenceName=22,
2586
            start=17190024,
2587
            end=17671934,
2588
            callSetIds=["1:NA19777", "1:HG01242", "1:HG01142"],
2589
            pageToken="",
2590
            pageSize=1,
2591
        )
2592
2593
        # testing values
2594
        self.assertTrue(compareNested(reference, test))
2595
2596
    @pytest.mark.live
2597
    def test_searchGA4GHVariantsets(self) -> None:
2598
        """Testing GA4GH search variantset POST method"""
2599
2600
        curl_cmd = (
2601
            """curl 'https://rest.ensembl.org/ga4gh/variantsets/search' -H 'Content-type:application/json' """
2602
            """-H 'Accept:application/json' -X POST -d """
2603
            """'{ "datasetId": "6e340c4d1e333c7a676b1710d2e3953c","pageToken": "", "pageSize": 2 }'"""
2604
        )
2605
2606
        # execute the curl cmd an get data as a dictionary
2607
        reference = jsonFromCurl(curl_cmd)
2608
2609
        # execute EnsemblRest function
2610
        test = self.EnsEMBL.searchGA4GHVariantsets(
2611
            datasetId="6e340c4d1e333c7a676b1710d2e3953c", pageToken="", pageSize=2
2612
        )
2613
2614
        # testing values
2615
        self.assertTrue(compareNested(reference, test))
2616
2617
    @pytest.mark.live
2618
    def test_getGA4GHVariantsetsById(self) -> None:
2619
        """Testing GA4GH get variantset by Id GET method"""
2620
2621
        curl_cmd = """curl 'https://rest.ensembl.org/ga4gh/variantsets/1?' -H 'Content-type:application/json'"""
2622
2623
        # execute the curl cmd an get data as a dictionary
2624
        reference = jsonFromCurl(curl_cmd)
2625
2626
        # execute EnsemblRest function
2627
        test = self.EnsEMBL.getGA4GHVariantsetsById(id=1)
2628
2629
        # testing values
2630
        self.assertTrue(compareNested(reference, test))
2631
2632
    @pytest.mark.live
2633
    def test_searchGA4GHReferences(self) -> None:
2634
        """Testing GA4GH search references POST method"""
2635
2636
        curl_cmd = (
2637
            """curl 'https://rest.ensembl.org/ga4gh/references/search' """
2638
            """-H 'Content-type:application/json' -H 'Accept:application/json' """
2639
            """-X POST -d '{ "referenceSetId": "GRCh38", "pageSize": 10 }'"""
2640
        )
2641
2642
        # execute the curl cmd an get data as a dictionary
2643
        reference = jsonFromCurl(curl_cmd)
2644
2645
        # execute EnsemblRest function
2646
        test = self.EnsEMBL.searchGA4GHReferences(referenceSetId="GRCh38", pageSize=10)
2647
2648
        # testing values
2649
        self.assertTrue(compareNested(reference, test))
2650
2651
    @pytest.mark.live
2652
    def test_getGA4GHReferencesById(self) -> None:
2653
        """Testing GA4GH get references by Id GET method"""
2654
2655
        curl_cmd = (
2656
            """curl 'https://rest.ensembl.org/ga4gh/references/9489ae7581e14efcad134f02afafe26c?' """
2657
            """-H 'Content-type:application/json'"""
2658
        )
2659
2660
        # execute the curl cmd an get data as a dictionary
2661
        reference = jsonFromCurl(curl_cmd)
2662
2663
        # execute EnsemblRest function
2664
        test = self.EnsEMBL.getGA4GHReferencesById(
2665
            id="9489ae7581e14efcad134f02afafe26c"
2666
        )
2667
2668
        # testing values
2669
        self.assertTrue(compareNested(reference, test))
2670
2671
    @pytest.mark.live
2672
    def test_searchGA4GHReferencesets(self) -> None:
2673
        """Testing GA4GH search reference sets POST method"""
2674
2675
        curl_cmd = (
2676
            """curl 'https://rest.ensembl.org/ga4gh/referencesets/search' """
2677
            """-H 'Content-type:application/json' -H 'Accept:application/json' """
2678
            """-X POST -d '{   }'"""
2679
        )
2680
2681
        # execute the curl cmd an get data as a dictionary
2682
        reference = jsonFromCurl(curl_cmd)
2683
2684
        # execute EnsemblRest function
2685
        test = self.EnsEMBL.searchGA4GHReferencesets()
2686
2687
        # testing values
2688
        self.assertTrue(compareNested(reference, test))
2689
2690
    @pytest.mark.live
2691
    def test_getGA4GHReferenceSetsById(self) -> None:
2692
        """Testing GA4GH get reference set by Id GET method"""
2693
2694
        curl_cmd = """curl 'https://rest.ensembl.org/ga4gh/referencesets/GRCh38?' -H 'Content-type:application/json'"""
2695
2696
        # execute the curl cmd an get data as a dictionary
2697
        reference = jsonFromCurl(curl_cmd)
2698
2699
        # execute EnsemblRest function
2700
        test = self.EnsEMBL.getGA4GHReferencesetsById(id="GRCh38")
2701
2702
        # testing values
2703
        self.assertTrue(compareNested(reference, test))
2704
2705
    @pytest.mark.live
2706
    def test_searchGA4GHVariantAnnotationsets(self) -> None:
2707
        """Testing GA4GH variant annotation sets search POST method"""
2708
2709
        curl_cmd = (
2710
            """curl 'https://rest.ensembl.org/ga4gh/variantannotationsets/search' -H 'Content-type:application/json' """
2711
            """-H 'Accept:application/json' -X POST -d '{ "variantSetId": "Ensembl"}'"""
2712
        )
2713
2714
        # execute the curl cmd an get data as a dictionary
2715
        reference = jsonFromCurl(curl_cmd)
2716
2717
        # execute EnsemblRest function
2718
        test = self.EnsEMBL.searchGA4GHVariantAnnotationsets(
2719
            variantSetId="Ensembl",
2720
        )
2721
2722
        # testing values
2723
        self.assertTrue(compareNested(reference, test))
2724
2725
    @pytest.mark.live
2726
    def test_getGA4GHVariantAnnotationsets(self) -> None:
2727
        """Testing get GA4GH variant annotation sets GET method"""
2728
2729
        curl_cmd = """curl 'https://rest.ensembl.org/ga4gh/variantannotationsets/Ensembl' -H 'Content-type:application/json'"""
2730
2731
        # execute the curl cmd an get data as a dictionary
2732
        reference = jsonFromCurl(curl_cmd)
2733
2734
        # execute EnsemblRest function
2735
        test = self.EnsEMBL.getGA4GHVariantAnnotationsetsById(
2736
            id="Ensembl",
2737
        )
2738
2739
        # testing values
2740
        self.assertTrue(compareNested(reference, test))
2741
2742
2743
if __name__ == "__main__":
2744
    unittest.main()
2745