def test_v2_tnrs_no_fuzzy():
    cfg = get_test_config()
    taxo = APIWrapper(config=cfg).taxomachine
    resp = taxo.TNRS(names, context_name="All life", fuzzy_matching=False)
    print resp
    assert len(resp['matched_name_ids']) == 3
    assert 'H**o sapphire' in resp['unmatched_name_ids']
    assert 'Pan trodlogytes' in resp['unmatched_name_ids']
def test_v1_tnrs():
    cfg = get_test_config({'apis': {'api_version': '1'}})
    taxo = APIWrapper(config=cfg).taxomachine
    names = [
        'Pan trodlogytes',
        'H**o sapphire',
        'Plantago',
        'Morpho peleides',
        'Eleocharis',
    ]
    resp = taxo.TNRS(names, context_name="All life")
    assert len(resp['matched_name_ids']) == 4
    assert resp['unmatched_name_ids'] == [u'H**o sapphire']
def test_v2_tnrs_fuzzy():
    cfg = get_test_config()
    taxo = APIWrapper(config=cfg).taxomachine
    names = [
        'Pan trodlogytes',
        'H**o sapphire',
        'Plantago',
        'Morpho peleides',
        'Eleocharis',
    ]
    resp = taxo.TNRS(names, context_name="All life", fuzzy_matching=True)
    print resp
    assert len(resp['matched_name_ids']) == 4
    assert resp['unmatched_name_ids'] == [u'H**o sapphire']
Esempio n. 4
0
def _populate_globals():
    global treemachine, oti, phylesystem_api, taxomachine
    from peyotl.api import APIWrapper
    api_wrapper = APIWrapper()
    treemachine = api_wrapper.treemachine
    oti = api_wrapper.oti
    taxomachine = api_wrapper.taxomachine
    phylesystem_api = api_wrapper.phylesystem_api
Esempio n. 5
0
def _populate_globals():
    global treemachine, oti, phylesystem_api, taxomachine, tnrs, taxonomy, tree_of_life, graph_of_life, studies
    from peyotl.api import APIWrapper
    api_wrapper = APIWrapper()
    treemachine = api_wrapper.treemachine
    oti = api_wrapper.oti
    taxomachine = api_wrapper.taxomachine
    phylesystem_api = api_wrapper.phylesystem_api
    tnrs = api_wrapper.tnrs
    taxonomy = api_wrapper.taxonomy
    tree_of_life = api_wrapper.tree_of_life
    graph_of_life = api_wrapper.graph
    studies = api_wrapper.studies
Esempio n. 6
0
def _populate_globals():
    global treemachine, oti, phylesystem_api, collections_api, amendments_api, taxomachine, tnrs, \
        taxonomy, tree_of_life, graph_of_life, studies
    from peyotl.api import APIWrapper
    api_wrapper = APIWrapper()
    treemachine = api_wrapper.treemachine
    oti = api_wrapper.oti
    taxomachine = api_wrapper.taxomachine
    phylesystem_api = api_wrapper.phylesystem_api
    collections_api = api_wrapper.collections_api
    # amendments_api = api_wrapper.amendments_api
    # global favorites_api
    # favorites_api = api_wrapper.favorites_api
    tnrs = api_wrapper.tnrs
    taxonomy = api_wrapper.taxonomy
    tree_of_life = api_wrapper.tree_of_life
    graph_of_life = api_wrapper.graph
    studies = api_wrapper.studies
Esempio n. 7
0
File: sync.py Progetto: rvosa/peyotl
    def __init__(self,
                 cfg_file_paths,
                 lock_policy=None,
                 api_wrapper=None,
                 sleep_between_downloads=None):
        '''Configures an object for controlling the
        synchronization between phylografter and the NexSON Document Store API.

        `cfg_file_paths` should be a dict with:
            'nexson_dir': directory that will be the parent of the nexson files
             'nexson_state_db': a JSON file to hold the state of the phylografter <-> API interaction
        `to_download` can be a list of study IDs (if the state is not to be preserved). If this call
            uses the history in `cfg_file_paths['nexson_state_db']` then this should be None.
        `lock_policy` can usually be None, it specifies how the nexson_state_db is to be locked for thread safety
        `api_wrapper` will be the default APIWrapper() if None
        `sleep_between_downloads` is the number of seconds to sleep between calls (to avoid stressing phylografter.)

        env vars:
            SLEEP_BETWEEN_DOWNLOADS_TIME, SLEEP_FOR_LOCK_TIME, and MAX_NUM_SLEEP_IN_WAITING_FOR_LOCK are checked
            if lock_policy and sleep_between_downloads
        '''
        self._cfg = cfg_file_paths
        if api_wrapper is None:
            from peyotl.api import APIWrapper
            api_wrapper = APIWrapper(
                phylesystem_api_kwargs={'get_from': 'api'})
        self.phylografter = api_wrapper.phylografter
        self.phylesystem_api = api_wrapper.phylesystem_api
        if sleep_between_downloads is None:
            sleep_between_downloads = float(
                os.environ.get('SLEEP_BETWEEN_DOWNLOADS_TIME', 0.5))
        self.sleep_between_downloads = sleep_between_downloads
        if lock_policy is None:
            from peyotl.utility.simple_file_lock import LockPolicy
            lock_policy = LockPolicy(
                sleep_time=float(os.environ.get('SLEEP_FOR_LOCK_TIME', 0.05)),
                max_num_sleep=int(
                    os.environ.get('MAX_NUM_SLEEP_IN_WAITING_FOR_LOCK', 100)))
        self.lock_policy = lock_policy
        self.log = {}
Esempio n. 8
0
#!/usr/bin/env python
import sys
from dendropy import Tree, DnaCharacterMatrix
from peyotl import gen_otu_dict, iter_node
from peyotl.manip import iter_trees, iter_otus
from peyotl.api.phylesystem_api import PhylesystemAPI
from peyotl.sugar import tree_of_life, taxonomy
from peyotl.nexson_syntax import extract_tree_nexson, get_subtree_otus, PhyloSchema
from peyotl.api import APIWrapper
api_wrapper = APIWrapper()
from Bio.Blast import NCBIWWW, NCBIXML
from Bio.Blast.Applications import NcbiblastxCommandline
from Bio import SeqIO, Entrez
import re
import os
import subprocess
import time
import datetime
import glob
import configparser
import json



'''
study_id=sys.argv[1]
tree_id=sys.argv[2]
seqaln=sys.argv[3]
mattype=sys.argv[4]
runname=sys.argv[5]
'''
Esempio n. 9
0
#!/usr/bin/env python
from peyotl.api import APIWrapper
taxo = APIWrapper().taxomachine
print(taxo.valid_contexts)
print(taxo.TNRS(['sorex montereyensis'], context_name='Mammals'))
print(taxo.TNRS(['sorex montereyensis']))
Esempio n. 10
0
 def setUp(self):
     d = get_test_ot_service_domains()
     self.ot = APIWrapper(d)
Esempio n. 11
0
from dendropy.utility import container
from peyotl.api import APIWrapper
from cStringIO import StringIO
import codecs
import dateutil.parser
import dendropy
import json
import math
import os
import random
import shutil
import string
import sys
import time
import unittest
TAXOMACHINE = APIWrapper().taxomachine
TREEMACHINE = APIWrapper().tree_of_life
SCRIPT_NAME = os.path.split(sys.argv[0])[1]
class Reason(object):
    NO_INC_DESIGNATORS_IN_TREE = 0
    SUCCESS = 1
    MRCA_HAS_EXCLUDED = 2
    ERROR_CHECK_FAILED = 3
    def to_str(c):
        if c == Reason.SUCCESS:
            return 'success'
        if c == Reason.ERROR_CHECK_FAILED:
            return 'an error check failed'
        if c == Reason.NO_INC_DESIGNATORS_IN_TREE:
            return 'no specifiers to be included were in the tree'
        if c == Reason.MRCA_HAS_EXCLUDED:
Esempio n. 12
0
#!/usr/bin/env python
from peyotl.api import APIWrapper

ps = APIWrapper().phylesystem_api
studies = ps.get_study_list()
print(studies[0])
blob = ps.get(studies[0])
nexson = blob['data']['nexml']
print(nexson['^ot:studyId'], ':', nexson['^ot:studyPublicationReference'])
Esempio n. 13
0
        result = func(*valist, **kwargs)
        end_t = time.time()
        return report_results(tag, end_t - start_t, expected_fn, result)
    except HTTPError as x:
        end_t = time.time()
        return report_error(tag, end_t - start_t, x)


if __name__ == '__main__':
    from peyotl.api import APIWrapper
    from requests import HTTPError
    import datetime

    timestamp = datetime.datetime.utcnow()

    otwrap = APIWrapper(phylesystem_api_kwargs={'get_from': 'api'})
    summary_list = []

    summary = _ot_call('treemachine/getSyntheticTree',
                       'curl-versions/getSyntheticTree.json',
                       lambda: otwrap.treemachine.synthetic_tree,
                       'otol.draft.22',
                       format='arguson',
                       node_id=3534540,
                       max_depth=3)
    summary_list.append(summary)

    summary = _ot_call('treemachine/getDraftTreeSubtreeForNodes',
                       'curl-versions/getDraftTreeSubtreeForNodes.json',
                       otwrap.treemachine.get_synth_tree_pruned,
                       ott_ids=[
Esempio n. 14
0
import json
import cPickle as pickle
from cStringIO import StringIO
import os
from trees.data import load
from tqdm import tqdm
from peyotl.api import APIWrapper
from Bio import Phylo
from trees import TreeNode, TreeLeaf, Tree
api = APIWrapper()


def correct(a):
    return a


CONVERSION = {
    'aardvark': 'Orycteropus afer',
    'boar': 'Sus scrofa',
    'bass': 'Micropterus salmoides',
    'bear': 'Ursidae',
    'calf': 'Bos taurus',
    'cheetah': 'Acinonyx jubatus',
    'chicken': 'Gallus gallus domesticus',
    'chub': 'Leuciscus cephalus',
    'crab': 'Brachyura',
    'catfish': 'Siluriformes',
    'crayfish': 'Astacoidea',
    'buffalo': 'Syncerus caffer',
    'clam': 'Bivalvia',
    'cavy': 'Caviidae',
Esempio n. 15
0
#!/usr/bin/env python
from __future__ import print_function
from peyotl.api import APIWrapper
oti = APIWrapper().oti
print(oti.study_search_term_set)
print(oti.tree_search_term_set)

print(oti.find_trees({'ot:ottTaxonName': 'Aponogeton ulvaceus'}))
print(oti.find_trees(ottTaxonName='Aponogeton ulvaceus'))
Esempio n. 16
0
import sys
from peyotl.api import APIWrapper
#NB: This will only work with v3 of the API's requires update of peyotl

infi = open("VTO_taxa_without_ncbiids.txt")

ofi = open('alltaxa_VTO_mapping.txt', 'w')
ofi.write("{},{},{}\n".format('VTO', 'taxname', 'ottid'))

mmfi = open('multi_matched', 'w')
mmfi.write("{},{}\n".format('VTO', 'taxname'))

unfi = open('unmatched', 'w')
unfi.write("{},{}\n".format('VTO', 'taxname'))

wrap = APIWrapper()
tm = wrap.taxomachine

for lin in infi:
    lii = lin.split("\t")
    taxname = lii[0]
    VTO = lii[1].strip()
    tnrs = tm.TNRS(taxname, "Animals")
    if len(tnrs[u'results']) == 0:
        unfi.write("{},{}\n".format(VTO, taxname))
    if len(tnrs[u'results']) == 1:
        try:
            ott_id = tnrs[u'results'][0][u'matches'][0][u'taxon'][u'ott_id']
        except KeyError:
            sys.stderr.write(
                "Requires running on V3 of the OpenTree apis! update peyotl config."
Esempio n. 17
0
#!/usr/bin/env python
from peyotl.api import APIWrapper
oti = APIWrapper().oti
print(oti.study_search_term_set)
print(oti.tree_search_term_set))
print(oti.find_trees({'ot:ottTaxonName': 'Aponogeton ulvaceus'}))
print(oti.find_trees(ottTaxonName='Aponogeton ulvaceus'))
Esempio n. 18
0
# Get the OpenTreeeOfLife identifier from a named clade

from peyotl.api import APIWrapper

import sys

input = sys.argv[1]
tx = APIWrapper().taxomachine
context = None

nms = tx.TNRS([input])
for i in nms['results']:
    for j in i['matches']:
        print j[u'taxon'][u'name']
        print j[u'taxon'][u'ott_id']
#!/usr/bin/env python
from peyotl.api import APIWrapper
ps = APIWrapper().phylesystem_api
studies = ps.get_study_list()
print(studies[0])
blob = ps.get(studies[0])
nexson = blob['data']['nexml']
print(nexson['^ot:studyId'], ':', nexson['^ot:studyPublicationReference'])

Esempio n. 20
0
#!/usr/bin/env python
from peyotl.api import APIWrapper
from peyotl.utility.input_output import read_as_json, write_as_json
from peyotl.nexson_syntax import get_nexml_el

a = APIWrapper(phylesystem_api_kwargs={'get_from': 'local'})
pa = a.phylesystem_api
p = pa.phylesystem_obj
for sid, fp in p.iter_study_filepaths():
    blob = read_as_json(fp)
    nex = get_nexml_el(blob)
    x = nex.get('^ot:studyId')
    if x != sid:
        nex['^ot:studyId'] = sid
        write_as_json(blob, fp)
        print(x, sid)
Esempio n. 21
0
#!/usr/bin/env
from peyotl.api import APIWrapper
tm = APIWrapper().treemachine
tax = APIWrapper().taxomachine

# Get info about synthesis
info = tm.get_synthetic_tree_info()

# Get tree ID
tid = info['tree_id']

# Get the OTT IDs from taxomachine
human, gorilla = tax.names_to_ott_ids_perfect(
    ['h**o sapiens', 'Gorilla gorilla'])

mrca_info = tm.mrca(ott_ids=[human, gorilla])
mrca_node_id = mrca_info['mrca_node_id']

# fetch a few levels of the tree:
newick = tm.get_synthetic_tree(tid, format="newick",
                               node_id=mrca_node_id)['newick']

# pruned is silly for just 2 leaves, but...
newick = tm.get_synth_tree_pruned(ott_ids=[human, gorilla])['subtree']

# Get list of dicts describing the version of each input tree
inputs = tm.get_synthetic_tree_id_list()
Esempio n. 22
0
#!/usr/bin/env
from peyotl.api import APIWrapper
tm = APIWrapper().treemachine
tax = APIWrapper().taxomachine

# Get info about synthesis
info = tm.get_synthetic_tree_info()

# Get tree ID
tid = info['tree_id']

# Get the OTT IDs from taxomachine
human, gorilla = tax.names_to_ott_ids_perfect(['h**o sapiens', 'Gorilla gorilla'])

mrca_info = tm.mrca(ott_ids=[human, gorilla])
mrca_node_id = mrca_info['mrca_node_id']

# fetch a few levels of the tree:
newick = tm.get_synthetic_tree(tid, format="newick", node_id=mrca_node_id)['newick']

# pruned is silly for just 2 leaves, but...
newick = tm.get_synth_tree_pruned(ott_ids=[human, gorilla])['subtree']

# Get list of dicts describing the version of each input tree
inputs = tm.get_synthetic_tree_id_list()
Esempio n. 23
0
#!/usr/bin/env python
from peyotl.api import APIWrapper
ot = APIWrapper()
r = ot.tnrs.match_names(
    [  #'Canis lupus familiaris',
        'Canidae', 'Vulpes vulpes', 'Equus', 'Dasypus novemcinctus'
        #'Mammalia',
    ],
    context_name='Animals')
print(r)
ot_ids = [i['matches'][0]['ot:ottId'] for i in r['results']]
print(ot_ids)
print(ot.tree_of_life.induced_subtree(ott_ids=ot_ids))
Esempio n. 24
0
#!/usr/bin/env python
from peyotl.api import APIWrapper
taxo = APIWrapper().taxomachine
print(taxo.subtree(770319))