Example #1
0
 def _expected_norm_array_name(self):
     """Returns the name that an accumulation array should have, if it
     exists in the file system. This is based on the original filename and
     a hash of the transformation matrix."""
     transform_string=''.join([struct.pack('<d', x) 
                               for x in self.transform])
     the_hash=hashlib.md5(transform_string).hexdigest()
     return os.path.join(cache.path(), 
                         '%s.%s' % (os.path.basename(self._matrix_file.name),
                                    the_hash))
Example #2
0
 def _expected_norm_array_name(self):
     """Returns the name that an accumulation array should have, if it
     exists in the file system. This is based on the original filename and
     a hash of the transformation matrix."""
     transform_string = ''.join(
         [struct.pack('<d', x) for x in self.transform])
     the_hash = hashlib.md5(transform_string).hexdigest()
     return os.path.join(
         cache.path(),
         '%s.%s' % (os.path.basename(self._matrix_file.name), the_hash))
Example #3
0
import sys
import os
import web
import cPickle as pickle
import traceback
import urllib2
from urllib import urlencode
from MEDRank.file.disk_backed_dict import StringDBDict, DatabaseError
from MEDRank.utility.logger import logging, ULTRADEBUG
from MEDRank.utility import cache
from Bio import (Entrez, Medline)

urls = ("/(\d+)", "PubmedRecord")
app = web.application(urls, globals())
DEFAULT_CACHE_NAME = os.path.join(cache.path(), "pubmed_cache.db")
DEFAULT_CACHE_PORT = 8081
DEFAULT_CACHE_HOST = "http://127.0.0.1:%d" % DEFAULT_CACHE_PORT

# Replace your email address below!
Entrez.email = "*****@*****.**"


class PubmedRecord(object):
    """Serves PubMed records via a RESTful API"""
    def __init__(self):
        try:
            self._cache_location = sys.argv[2]
        except IndexError:
            self._cache_location = DEFAULT_CACHE_NAME
        self._cache = StringDBDict(self._cache_location, file_mode="c")
# encoding: utf-8
"""
infer_relation_direction.py

Uses MRREL to infer a relation's directionality, given two CUIs.

Created by Jorge Herskovic on 2008-06-24.
Copyright (c) 2008 Jorge Herskovic. All rights reserved.
"""
import os.path
import operator
import sys
from MEDRank.utility import cache
from MEDRank.utility.logger import logging, ULTRADEBUG
#from MEDRank.file.mrrel import (MRRELTable, MRRELLine)
_DEFAULT_FILE_NAME=os.path.join(cache.path(), 
                                   "direction_inference.p.bz2")


class RelationDirectionInferrer(dict):
    def build_from_mrrel_file_and_stype_table(self, mrrel_table,
                                              semantic_types):
        """Builds a relationship dictionary and stores a semantic type 
        table."""
        count=0
        self._stypes=semantic_types
        for l in mrrel_table:
            if l.original_direction:
                if l.cui1==l.cui2: # Relationships of a concept to itself are
                                   # not interesting to us.
                    continue
Example #5
0
import sys
import os
import web
import cPickle as pickle
import traceback
import urllib2
from urllib import urlencode
from MEDRank.file.disk_backed_dict import StringDBDict, DatabaseError
from MEDRank.utility.logger import logging, ULTRADEBUG
from MEDRank.utility import cache
from Bio import (Entrez, Medline)

urls=("/(\d+)", "PubmedRecord")
app = web.application(urls, globals())
DEFAULT_CACHE_NAME=os.path.join(cache.path(), "pubmed_cache.db")
DEFAULT_CACHE_PORT=8081
DEFAULT_CACHE_HOST="http://127.0.0.1:%d" % DEFAULT_CACHE_PORT

# Replace your email address below!
Entrez.email="*****@*****.**"

class PubmedRecord(object):
    """Serves PubMed records via a RESTful API"""
    def __init__(self):
        try:
            self._cache_location=sys.argv[2]
        except IndexError:
            self._cache_location=DEFAULT_CACHE_NAME
        self._cache=StringDBDict(self._cache_location, file_mode="c")
        
Example #6
0
current_element = None
current_article = None
current_cuis = None
current_names = None
current_nodes = None
current_relations = None
current_strengths = None
current_links = None
current_content = []
article_handler = re.compile(r"\<\s*article\s*pmid\s*\=\s*(\w+)\s*\>",
                             re.IGNORECASE)
known_opening_tags = re.compile(r"\<(cuis|names|connectivities|relations)\>",
                                re.IGNORECASE)
known_closing_tags = re.compile(r"\</(cuis|names|connectivities|relations)\>",
                                re.IGNORECASE)
SEMPRED_CACHE = os.path.join(cache.path(), "sempred")


def predication_filename(pubmed_id):
    p = list(str(pubmed_id))
    p, last_two = p[:-2], p[-2:]
    ptuple = tuple(['_%s' % x for x in p])
    if ptuple == ():
        fn = ''.join(last_two)
    else:
        fn = os.path.join(os.path.join(*ptuple), ''.join(last_two))
    logging.debug("Predication filename for %r=%s", pubmed_id, fn)
    return fn


def predications_name_and_path(pubmed_id, path):
Example #7
0
current_element=None
current_article=None
current_cuis=None
current_names=None
current_nodes=None
current_relations=None
current_strengths=None
current_links=None
current_content=[]
article_handler=re.compile(r"\<\s*article\s*pmid\s*\=\s*(\w+)\s*\>",
                           re.IGNORECASE)
known_opening_tags=re.compile(r"\<(cuis|names|connectivities|relations)\>",
                              re.IGNORECASE)
known_closing_tags=re.compile(r"\</(cuis|names|connectivities|relations)\>",
                              re.IGNORECASE)
SEMPRED_CACHE=os.path.join(cache.path(), "sempred")

def predication_filename(pubmed_id):
    p=list(str(pubmed_id))
    p, last_two=p[:-2], p[-2:]
    ptuple=tuple(['_%s' % x for x in p])
    if ptuple==():
        fn=''.join(last_two)
    else:
        fn=os.path.join(os.path.join(*ptuple), ''.join(last_two))
    logging.debug("Predication filename for %r=%s", pubmed_id, fn)
    return fn

def predications_name_and_path(pubmed_id, path):
    filename=os.path.join(path, "%s.pickle.bz2" %
                                 predication_filename(pubmed_id))