def test_query_biomart_38_xml(ensembl_biomart_xml_query):
    """Prepare a test xml document for the biomart service build 38
    and query the service using it
    """
    # GIVEN client with a xml query for a gene
    build = "38"
    # percent encode query before concatenating with url
    url = "".join(
        [ensembl_rest_clients.BIOMART_38,
         quote(ensembl_biomart_xml_query)])
    response = (b"ACTR3\tENST00000263238\n"
                b"ACTR3\tENST00000443297\n"
                b"ACTR3\tENST00000415792\n"
                b"ACTR3\tENST00000446821\n"
                b"ACTR3\tENST00000535589\n"
                b"ACTR3\tENST00000489779\n"
                b"ACTR3\tENST00000484165\n"
                b"ACTR3\tENST00000478928\n"
                b"[success]")
    responses.add(responses.GET, url, body=response, status=200)
    # WHEN querying ensembl
    client = ensembl_rest_clients.EnsemblBiomartClient(
        build=build, xml=ensembl_biomart_xml_query, header=False)

    # THEN assert that the result is correct
    for line in client:
        # THEN assert that either the correct gene is fetched or that an
        assert "ACTR3" in line
Ejemplo n.º 2
0
def test_test_query_biomart_38_xml():
    """Prepare a test xml document for the biomart service build 38 and query the service using it"""
    ## GIVEN a xml file in biomart format
    build = "38"
    xml = """<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE Query>
    <Query  virtualSchemaName = "default" formatter = "TSV" header = "0" uniqueRows = "0" count = "" datasetConfigVersion = "0.6" completionStamp = "1">
    	<Dataset name = "hsapiens_gene_ensembl" interface = "default" >
    		<Filter name = "ensembl_gene_id" value = "ENSG00000115091"/>
    		<Attribute name = "hgnc_symbol" />
    		<Attribute name = "ensembl_transcript_id" />
    	</Dataset>
    </Query>
    """

    ## WHEN querying ensembl
    client = eracs.EnsemblBiomartClient(build="38", xml=xml, header=False)

    ## THEN assert that the result is correct
    i = 0
    for i, line in enumerate(client, 1):
        ## THEN assert that either the correct gene is fetched or that an HTML page is returned (if the service is down)
        assert ("ACTR3" in line or line == "<!doctype html>"
                or "BioMart::Exception::Database" in line)
        break
Ejemplo n.º 3
0
def test_xml_attributes():
    """test method that creates attribute lines for the biomart xml file"""

    ## Given a list of  biomart attributes
    name = ["test_name"]
    client = eracs.EnsemblBiomartClient()
    ## WHEN creating the xml attribute lines
    attribute_lines = client._xml_attributes(name)

    ## THEN make sure that attributes lines are formatted as they should
    assert attribute_lines == ['<Attribute name = "test_name" />']
Ejemplo n.º 4
0
def test_xml_filters():
    """test method that creates filter lines for the biomart xml file"""

    ## GIVEN a dictionary of biomart filters
    filters = {
        'string_filter': 'string_value',
        'list_filter': ['1', 'X', 'MT'],
    }

    client = eracs.EnsemblBiomartClient()
    xml_lines = client._xml_filters(filters)

    # make sure lines are formatted as they should
    assert '<Filter name = "{0}" value = "{1}"/>'.format(
        'string_filter', 'string_value') in xml_lines
    assert '<Filter name = "{0}" value = "{1}"/>'.format(
        'list_filter', '1,X,MT') in xml_lines
Ejemplo n.º 5
0
def test_xml_filters():
    """test method that creates filter lines for the biomart xml file"""

    ## GIVEN a dictionary of biomart filters
    filters = {
        "string_filter": "string_value",
        "list_filter": ["1", "X", "MT"]
    }

    client = eracs.EnsemblBiomartClient()
    xml_lines = client._xml_filters(filters)

    # make sure lines are formatted as they should
    assert ('<Filter name = "{0}" value = "{1}"/>'.format(
        "string_filter", "string_value") in xml_lines)
    assert ('<Filter name = "{0}" value = "{1}"/>'.format(
        "list_filter", "1,X,MT") in xml_lines)
Ejemplo n.º 6
0
def test_test_query_biomart_37_no_xml():
    """Prepare a test xml document for the biomart service build 37 and query the service using it"""
    ## GIVEN defined biomart filters and attributes
    build = '37'
    filters = {'ensembl_gene_id': 'ENSG00000115091'}
    attributes = ['hgnc_symbol', 'ensembl_transcript_id']

    ## WHEN querying ensembl
    client = eracs.EnsemblBiomartClient(build='38',
                                        filters=filters,
                                        attributes=attributes,
                                        header=False)

    i = 0
    for i, line in enumerate(client):
        ## THEN assert the correct gene is fetched
        assert 'ACTR3' in line
    ## THEN assert there was a result
    assert i > 0
Ejemplo n.º 7
0
def test_test_query_biomart_37_no_xml():
    """Prepare a test xml document for the biomart service build 37 and query the service using it"""
    ## GIVEN defined biomart filters and attributes
    build = "37"
    filters = {"ensembl_gene_id": "ENSG00000115091"}
    attributes = ["hgnc_symbol", "ensembl_transcript_id"]

    ## WHEN querying ensembl
    client = eracs.EnsemblBiomartClient(build="38",
                                        filters=filters,
                                        attributes=attributes,
                                        header=False)

    i = 0

    for i, line in enumerate(client):
        ## THEN assert that either the correct gene is fetched or that an HTML page is returned (if the service is down)
        assert ("ACTR3" in line or line == "<!doctype html>"
                or "BioMart::Exception::Database" in line)
        break
def test_query_biomart_38_no_xml():
    """Prepare a test xml document for the biomart service build 38 and
    query the service using it
    """
    # GIVEN defined biomart filters and attributes
    filters = {"ensembl_gene_id": "ENSG00000115091"}
    attributes = ["hgnc_symbol", "ensembl_transcript_id"]

    query = '<?xml version="1.0" encoding="UTF-8"?>\
<!DOCTYPE Query>\
<Query  virtualSchemaName = "default" formatter = "TSV" header = "0" uniqueRows = "0" count = "" \
datasetConfigVersion = "0.6" completionStamp = "1">\
\t<Dataset name = "hsapiens_gene_ensembl" interface = "default" >\
\t\t<Filter name = "ensembl_gene_id" value = "ENSG00000115091"/>\
\t\t<Attribute name = "hgnc_symbol" />\
\t\t<Attribute name = "ensembl_transcript_id" />\
\t</Dataset>\
</Query>'

    # percent encode query before concatenating with url
    url = "".join([ensembl_rest_clients.BIOMART_38, quote(query)])

    response = (b"ACTR3\tENST00000263238\n"
                b"ACTR3\tENST00000443297\n"
                b"ACTR3\tENST00000415792\n"
                b"ACTR3\tENST00000446821\n"
                b"ACTR3\tENST00000535589\n"
                b"ACTR3\tENST00000489779\n"
                b"ACTR3\tENST00000484165\n"
                b"ACTR3\tENST00000478928\n"
                b"[success]")
    responses.add(responses.GET, url, body=response, status=200)
    # WHEN querying ensembl
    client = ensembl_rest_clients.EnsemblBiomartClient(build="38",
                                                       filters=filters,
                                                       attributes=attributes,
                                                       header=False)

    for line in client:
        # THEN assert that either the correct gene is fetched or that an
        assert "ACTR3" in line
Ejemplo n.º 9
0
def test_test_query_biomart_38_xml():
    """Prepare a test xml document for the biomart service build 38 and query the service using it"""
    ## GIVEN a xml file in biomart format
    build = '38'
    xml = """<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE Query>
    <Query  virtualSchemaName = "default" formatter = "TSV" header = "0" uniqueRows = "0" count = "" datasetConfigVersion = "0.6" completionStamp = "1">
			
    	<Dataset name = "hsapiens_gene_ensembl" interface = "default" >
    		<Filter name = "ensembl_gene_id" value = "ENSG00000115091"/>
    		<Attribute name = "hgnc_symbol" />
    		<Attribute name = "ensembl_transcript_id" />
    	</Dataset>
    </Query>
    """

    ## WHEN querying ensembl
    client = eracs.EnsemblBiomartClient(build='38', xml=xml, header=False)

    ## THEN assert that the result is correct
    i = 0
    for i, line in enumerate(client, 1):
        assert 'ACTR3' in line
    assert i > 0
Ejemplo n.º 10
0
def ensembl_biomart_client_37():
    """Return a client to the ensembl biomart, build 37"""
    return ensembl_rest_clients.EnsemblBiomartClient("37")