Esempio n. 1
0
    def test_configurable_cachedir(self):
        """ Test that `cachedir` keyword argument is fully supported in modes:

        cachedir == 'default'   <-- assumed working since other tests use this.
        cachedir is None
        cachedir is 'some/path'
        cachedir is '~/path'
        """

        cachedir = TEST_CACHEDIR
        # start with cachedir==None; test that no cachedir is created.
        fetch = MedGenFetcher(cachedir=None)
        assert not os.path.exists(cachedir)

        fetch = MedGenFetcher(cachedir=cachedir)
        assert os.path.exists(cachedir)

        os.unlink(fetch._cache_path)
        os.rmdir(cachedir)

        fetch = MedGenFetcher(cachedir='~/testcachedir')
        assert os.path.exists(os.path.expanduser('~/testcachedir'))

        os.unlink(fetch._cache_path)
        os.rmdir(os.path.expanduser('~/testcachedir'))
Esempio n. 2
0
class TestMedGenFetcher(unittest.TestCase):
    def setUp(self):
        self.fetch = MedGenFetcher()

    def tearDown(self):
        pass

    def test_fetch_concepts_for_known_gene(self):
        hugo = 'ACVRL1'
        result = self.fetch.uids_by_term(hugo + '[gene]')
        assert result is not None
        assert result[0] == '324960'

    def test_fetch_concepts_for_incorrect_term(self):
        term = 'AVCRL'
        result = self.fetch.uids_by_term(term + '[gene]')
        assert result == []

    def test_configurable_cachedir(self):
        """ Test that `cachedir` keyword argument is fully supported in modes:

        cachedir == 'default'   <-- assumed working since other tests use this.
        cachedir is None
        cachedir is 'some/path'
        cachedir is '~/path'
        """

        cachedir = TEST_CACHEDIR
        # start with cachedir==None; test that no cachedir is created.
        fetch = MedGenFetcher(cachedir=None)
        assert not os.path.exists(cachedir)

        fetch = MedGenFetcher(cachedir=cachedir)
        assert os.path.exists(cachedir)

        os.unlink(fetch._cache_path)
        os.rmdir(cachedir)

        fetch = MedGenFetcher(cachedir='~/testcachedir')
        assert os.path.exists(os.path.expanduser('~/testcachedir'))

        os.unlink(fetch._cache_path)
        os.rmdir(os.path.expanduser('~/testcachedir'))
Esempio n. 3
0
import unittest, os

from metapub import MedGenFetcher

hugos = ['ACVRL1', 'FOXP3', 'ATM']

TEST_CACHEDIR = 'tests/testcachedir'

fetch = MedGenFetcher()


class TestMedGenFetcher(unittest.TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_fetch_concepts_for_known_gene(self):
        hugo = 'ACVRL1'
        result = fetch.uids_by_term(hugo + '[gene]')
        assert result is not None
        assert result[0] == '324960'

    def test_fetch_concepts_for_incorrect_term(self):
        term = 'AVCRL'
        result = fetch.uids_by_term(term + '[gene]')
        assert result == []

    def test_attributes_on_medgen_concept(self):
        concept = fetch.concept_by_uid(324960)
from __future__ import absolute_import, print_function, unicode_literals

import sys

from metapub import MedGenFetcher

# example of CUID: C0000039

try:
    cui = sys.argv[1]
except IndexError:
    print('Supply a ConceptID (CUI) to this script as its argument.')
    sys.exit()

####
import logging
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("eutils").setLevel(logging.WARNING)
####

fetch = MedGenFetcher()
uid = fetch.uid_for_cui(cui)
print(uid)

from __future__ import absolute_import, print_function, unicode_literals

import sys

from metapub import MedGenFetcher
from metapub import PubMedFetcher

try:
    cui = sys.argv[1]
except IndexError:
    print("Supply CUI (Concept ID) as argument to this script.")
    sys.exit()

pmfetch = PubMedFetcher()
fetch = MedGenFetcher()

concept = fetch.concept_by_cui(cui)
print("#### CUI: %s" % cui)
print("# %s" % concept.title)
print("#")
print("#")

pmids = fetch.pubmeds_for_cui(cui)

for pmid in pmids:
    print("#### %s" % pmid)
    pma = pmfetch.article_by_pmid(pmid)
    print(pma.year, pma.title, pma.journal)
    print("")
Esempio n. 6
0
 def setUp(self):
     self.fetch = MedGenFetcher()
HAS_GENES_ONLY = False

try:
    term = sys.argv[1]
except IndexError:
    print('Supply a Hugo gene name to this script as its argument.')
    sys.exit()

####
import logging
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("eutils").setLevel(logging.INFO)
####

fetch = MedGenFetcher()
uids = fetch.uids_by_term(term)
print('Found %i Medgen concepts for term "%s"' % (len(uids), term))

# TODO: Term Hierarchy Children (only 1 tier below), Term Hierarchy Parents (only 1 tier above)

headers = ['CUI', 'Title', 'Semantic Type', 'MedGenUID', 
           'OMIM ID', 'Modes of Inheritance', 'Assoc Genes', 'PMIDS' ]

table = []

def _join_or_NA(some_list, select=None, joiner=','):
    'returns a joined string or NA if empty'
    if some_list and select:
        return joiner.join(item[select] for item in some_list)
    elif some_list:
Esempio n. 8
0
try:
    term = sys.argv[1]
except IndexError:
    print(
        'Supply a disease/syndrome/condition name in quotation marks as the argument to this script.'
    )
    sys.exit()

####
import logging

logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("eutils").setLevel(logging.INFO)
####

fetch = MedGenFetcher()
uids = fetch.uids_by_term(term)
print(uids)

headers = [
    'CUI',
    'Title',
    'Semantic Type',
    'MedGenUID',
    'OMIM ID',
    'Modes of Inheritance',
    'Assoc Genes',
]

table = []
from tabulate import tabulate
from metapub import MedGenFetcher

try:
    input_gene = sys.argv[1]
except IndexError:
    print('Supply a Hugo gene name to this script as its argument.')
    sys.exit()

####
import logging
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("eutils").setLevel(logging.INFO)
####

fetch = MedGenFetcher()
uids = fetch.uids_by_term(input_gene + '[gene]')
print(uids)

# TODO: Term Hierarchy Children (only 1 tier below), Term Hierarchy Parents (only 1 tier above)

headers = [
    'CUI',
    'Hugo',
    'Title',
    'Semantic Type',
    'MedGenUID',
    'OMIM ID',
    'Modes of Inheritance',
    'Assoc Genes',
]