示例#1
0
def main(query, p, download_cad):
    """
    Look up Akkadian words in the CAD and other dictionaries. query should be
    an akkadian word. Diacritics on consonants count. Diacritics on vowels, not
    so much.
    """
    import configparser
    import shutil

    if download_cad:
        from akkdict.fetchcad import download

        download()
        exit()
    if not query:
        print("missing argument [query].", file=sys.stderr)
        exit(1)
    if p:
        print(lookup("cad", query))
        exit()
    cfg = configparser.ConfigParser()
    if not cfg.read(home + "/.akkdictrc"):
        print("Oops! you don't have a config file yet!", "Creating ~/.akkdictrc...", file=sys.stderr)
        from pkg_resources import ResourceManager

        rm = ResourceManager()
        shutil.copy(rm.resource_filename("akkdict", "conf.ini"), home + "/.akkdictrc")
        print("Now, go edit ~/.akkdictrc for your local setup and then try", "the command again!", file=sys.stderr)
        exit(1)
    else:
        opendictionaries(query, cfg["dicts"], cfg["conf"]["command"])
示例#2
0
文件: xmla.py 项目: sir-Gollum/olap
import zope.interface
from connection import XMLAConnection
import olap.xmla.interfaces as oxi
import olap.interfaces as ooi

from pkg_resources import ResourceManager
rm = ResourceManager()
defaultwsdl = "file://"+rm.resource_filename(__name__, "vs.wsdl")



class TREE_OP(object):
    CHILDREN = 0x01
    SIBLINGS = 0x02
    PARENT = 0x04
    SELF = 0x08
    DESCENDANTS = 0x10
    ANCESTORS = 0x20
    

class XMLAProvider(object):
    
    zope.interface.implements(ooi.IProvider)
    
    def connect(self, url=defaultwsdl, location=None, username=None, 
                password=None, spn=None, sslverify=True, **kwargs):
        return XMLASource(url, location, username, password, spn, sslverify, **kwargs)


class XMLAClass(object):
    zope.interface.implements(ooi.IOLAPSchemaElement)
示例#3
0
import zope.interface
from connection import XMLAConnection
import olap.xmla.interfaces as oxi
import olap.interfaces as ooi

from pkg_resources import ResourceManager
rm = ResourceManager()
defaultwsdl = "file://" + rm.resource_filename(__name__, "vs.wsdl")


class TREE_OP(object):
    CHILDREN = 0x01
    SIBLINGS = 0x02
    PARENT = 0x04
    SELF = 0x08
    DESCENDANTS = 0x10
    ANCESTORS = 0x20


class XMLAProvider(object):

    zope.interface.implements(ooi.IProvider)

    def connect(self,
                url=defaultwsdl,
                location=None,
                username=None,
                password=None,
                spn=None,
                sslverify=True):
        return XMLASource(url, location, username, password, spn, sslverify)
示例#4
0
def get_contact_distance_map(structure_directory=INFO_DIRECTORY, westhof_vector=None, force_rebuild=False):
    """
    Returns contact distance map

    The contact distance map is cached it in the user directory and updated when newer files are found.

    :param structure_directory: directory to look up structure information text files
    :param westhof_vector: list of factors to apply different weights to the bonding family classes (defaults to ``[1, 1, ... ]``)
    :param force_rebuild: force rebuilding the distance map
    """
    # default: same weight for all families
    if not westhof_vector:
        westhof_vector = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

    nucleotides = ["A", "U", "G", "C"]

    # build a dict of filenames
    # if a local file is present in the user directory it will take precedence over the system wide shipped version
    structure_filenames = {}
    resource_manager = ResourceManager()
    for nt1 in nucleotides:
        for nt2 in nucleotides:
            ntpair = "%s-%s" % (nt1, nt2)
            local_file = structure_directory + os.sep + ntpair + ".txt"
            if os.path.isfile(local_file):
                structure_filenames[ntpair] = local_file
            else:
                structure_filenames[ntpair] = resource_manager.resource_filename(__name__, "structure_info/%s.txt" % ntpair)

    # try to use a cached version of the distance map if found and recent and force_rebuild is False
    if not force_rebuild:
        try:
            cache_ok = True
            if os.path.isfile(CACHE_DISTANCEMAP):
                cache_timestamp = os.path.getmtime(CACHE_DISTANCEMAP)
                for d in structure_filenames.itervalues():
                    if os.path.getmtime(d) > cache_timestamp:
                        cache_ok = False
                        print "Contact map cache out of date. Rebuilding..."
                        break
                if cache_ok:
                    with open(CACHE_DISTANCEMAP, "r") as f:
                        return pickle.load(f)
        except (IOError, pickle.PickleError, AttributeError, EOFError, IndexError):
            print "Contact map cache broken. Rebuilding..."

    print "Building contact distance map:"

    pdb_structure_dict = {}
    distance_map = {}
    for nt1 in nucleotides:
        for nt2 in nucleotides:

            distance_map_res_pair = {}

            pdb_codes = []
            residues = []

            # read the structures for the 12 edge-to-edge bonding families
            for line in utils.read_file_line_by_line(structure_filenames[nt1 + '-' + nt2]):
                fields = line.split(" ")
                if fields[0] != "-":
                    pdb_codes.append(fields[0].upper())
                    residues.append((int(fields[1]), int(fields[2])))
                else:
                    pdb_codes.append(None)
                    residues.append(None)

            # loop over all pdbcodes and their index in the list (0-11)
            for index, pdb_code in enumerate(pdb_codes):
                # skip if we don't have any entry for this family
                if pdb_code is None:
                    continue

                # download pdb if necessary
                if pdb_code not in pdb_structure_dict:
                    pdb_structure_dict[pdb_code] = pdbtools.parse_pdb(pdb_code, pdbtools.get_pdb_by_code(pdb_code))

                # extract model from pdb
                model = pdb_structure_dict[pdb_code][0]

                # try to find the residue contact specified. this is done by looping over all chains in the model,
                # and checking if the residue is in there and is the correct nucleotide
                def find_res(res, resname):
                    for chain in model:
                        try:
                            if chain[res].get_resname().strip() == resname:
                                return chain[res]
                        except KeyError:
                            pass
                    return None

                res1 = find_res(residues[index][0], nt1)
                res2 = find_res(residues[index][1], nt2)

                if not res1 or not res2:
                    raise Exception("Could not find residue contact in pdb file: %s-%s %s %s %s" % (nt1, nt2, pdb_code, residues[index][0], residues[index][1]))

                print "%s-%s %s %s %s" % (nt1, nt2, pdb_code, residues[index][0], residues[index][1])

                # add all atom-atom contacts to the distance map for the current residue pair
                for atom1 in res1:
                    for atom2 in res2:
                        if not (atom1.name.startswith('H') or atom2.name.startswith('H')):
                            contact_key = str(atom1.name) + '-' + str(atom2.name)
                            distance = westhof_vector[index] * (atom1 - atom2)
                            if contact_key not in distance_map_res_pair:
                                distance_map_res_pair[contact_key] = [distance]
                            else:
                                distance_map_res_pair[contact_key].append(distance)

            distance_map[nt1 + nt2] = distance_map_res_pair

    # save distance map in cache
    utils.mkdir_p(CACHE_DIRECTORY)
    with open(CACHE_DISTANCEMAP, "w") as f:
        pickle.dump(distance_map, f)

    return distance_map