def annotation_start(): """Selects a gene in MongoDB and imports it in the Annotation track Returns ------- json url: url for the apollo window, centered on the gene position attributes: chromosome on which the gene is """ DataInstance = Data(ca, session) current_gene = DataInstance.get_current_annotation( session["user"]["username"]) if not current_gene: all_positions = DataInstance.get_all_positions() level = DataInstance.get_user_level(session["user"]["username"]) restrict_positions = DataInstance.select_genes(level, all_positions) # FIXME error if no gene in db selected_item = Utils.get_random_items(1, restrict_positions)[0] ca.logger.info("Selected gene: {}".format(selected_item)) db = ca.mongo.db fs = gridfs.GridFS( db, collection="genes" ) # FIXME not sure we really need gridfs (small chunks of gff) gff_file = fs.get(selected_item["_id"]) gff_str = StringIO() gff_str.write(gff_file.read().decode()) gff_str.seek(0) ca.logger.info("Loading gff: {}".format(gff_str.read())) gff_str.seek(0) apollo = ApolloInstance(ca.apollo_url, ca.apollo_admin_email, ca.apollo_admin_password) apollo.annotations.load_gff3( "%s_%s" % (ca.apollo_org_id, session["user"]["email"]), gff_str) time.sleep(1) url = "%s/annotator/loadLink?loc=%s:%s..%s&organism=%s_%s" % ( ca.apollo_url_ext, selected_item["chromosome"], selected_item["start"], selected_item["end"], ca.apollo_org_id, session["user"]["email"]) DataInstance.update_current_annotation(session["user"]["username"], selected_item) else: selected_item = DataInstance.get_current_annotation( session["user"]["username"]) url = "%s/annotator/loadLink?loc=%s:%s..%s&organism=%s_%s" % ( ca.apollo_url_ext, selected_item["chromosome"], selected_item["start"], selected_item["end"], ca.apollo_org_id, session["user"]["email"]) return {'url': url}
def cli(ctx, url=None, api_key=None, admin=False, **kwds): """Help initialize global configuration (in home directory) """ # TODO: prompt for values someday. click.echo("""Welcome to Apollo's Arrow!""") if os.path.exists(config.global_config_path()): info( "Your arrow configuration already exists. Please edit it instead: %s" % config.global_config_path()) return 0 while True: apollo_url = click.prompt("Please entry your Apollo's URL") apollo_username = click.prompt("Please entry your Apollo Username") apollo_password = click.prompt("Please entry your Apollo Password", hide_input=True) info("Testing connection...") try: ai = ApolloInstance(apollo_url, apollo_username, apollo_password) try: ai.metrics.get_metrics() # Ok, success info("Ok! Everything looks good.") break except Exception as e: print(e) warn( "Error, we could not access the configuration data for your instance." ) should_break = click.prompt( "Continue despite inability to contact this Apollo Instance? [y/n]" ) if should_break in ('Y', 'y'): break except Exception as e: warn( "Error, we could not access the configuration data for your instance." ) should_break = click.prompt( "Continue despite inability to contact this Apollo Instance? [y/n]" ) if should_break in ('Y', 'y'): break config_path = config.global_config_path() if os.path.exists(config_path): warn("File %s already exists, refusing to overwrite." % config_path) return -1 with open(config_path, "w") as f: f.write( CONFIG_TEMPLATE % { 'url': apollo_url, 'username': apollo_username, 'password': apollo_password, }) info(SUCCESS_MESSAGE)
def validation(): """Selects a gene from the answers and imports it in the Annotation track Returns ------- json url: url for the apollo window, centered on the gene position attributes: chromosome on which the gene is gene_id : current gene id """ DataInstance = Data(ca, session) all_positions = DataInstance.get_not_validated() # FIXME error if no gene in db selected_item = all_positions[0] ca.logger.info("Selected gene: {}".format(selected_item)) db = ca.mongo.db fs = gridfs.GridFS( db, collection="answers" ) # FIXME not sure we really need gridfs (small chunks of gff) gff_file = fs.get(selected_item["_id"]) gff_str = StringIO() gff_str.write(gff_file.read().decode()) gff_str.seek(0) ca.logger.info("Loading gff: {}".format(gff_str.read())) gff_str.seek(0) apollo = ApolloInstance(ca.apollo_url, ca.apollo_admin_email, ca.apollo_admin_password) apollo.organisms.delete_features( "%s_%s" % (ca.apollo_org_id, session["user"]["email"])) apollo.annotations.load_gff3( "%s_%s" % (ca.apollo_org_id, session["user"]["email"]), gff_str) time.sleep(1) url = "%s/annotator/loadLink?loc=%s:%s..%s&organism=%s_%s" % ( ca.apollo_url_ext, selected_item["chromosome"], selected_item["start"], selected_item["end"], ca.apollo_org_id, session["user"]["email"]) DataInstance.update_current_annotation(session["user"]["username"], selected_item) return {'url': url, 'gene_id': selected_item["_id"]}
class Config(object): if not (os.environ.get('APOLLO_USER') and os.environ.get('APOLLO_PASSWORD') and os.environ.get('APOLLO_URL')): raise Exception( "Missing either APOLLO_USER, APOLLO_PASSWORD or APOLLO_URL env variable" ) APOLLO_USER = os.environ.get('APOLLO_USER') APOLLO_PASSWORD = os.environ.get('APOLLO_PASSWORD') APOLLO_URL = os.environ.get('APOLLO_URL') PROXY_HEADER = os.environ.get("PROXY_HEADER", "REMOTE_USER") USER_AUTOCOMPLETE = os.environ.get('USER_AUTOCOMPLETE', "FALSE") CRON_SYNC = os.environ.get('CRON_SYNC', "FALSE") PROXY_PREFIX = os.environ.get('PROXY_PREFIX') APOLLO_INSTANCE = ApolloInstance(APOLLO_URL, APOLLO_USER, APOLLO_PASSWORD) SECRET_KEY = os.urandom(32) CACHE_TYPE = "simple" CACHE_DEFAULT_TIMEOUT = 3600
def get_permissions(self): ai = ApolloInstance(os.environ['APOLLO_URL'], os.environ['APOLLO_USER'], os.environ['APOLLO_PASS']) groups = ai.groups.get_groups() orgs_by_user = {} for group in groups: for org in group['organismPermissions']: for group_user in group['users']: if self.split_users: user_name = re.sub(r"^(.+)@[a-zA-Z0-9]+$", r"\1", group_user['email']) else: user_name = group_user['email'] if user_name not in orgs_by_user: orgs_by_user[user_name] = [] orgs_by_user[user_name].append(org['organism']) return orgs_by_user
def annotation_end(): """gets the new annotation and saves it in mongodb""" DataInstance = Data(ca, session) current_gene = DataInstance.get_current_annotation( session["user"]["username"]) apollo = ApolloInstance(ca.apollo_url, ca.apollo_admin_email, ca.apollo_admin_password) features = apollo.annotations.get_features( organism="%s_%s" % (ca.apollo_org_id, session["user"]["email"]), sequence=current_gene["chromosome"])["features"] gff_file = apollo.annotations.get_gff3( features[0]["uniquename"], "%s_%s" % (ca.apollo_org_id, session["user"]["email"])) DataInstance.store_answers_from_user(session["user"]["username"], gff_file) apollo.organisms.delete_features( "%s_%s" % (ca.apollo_org_id, session["user"]["email"])) return {'error': False, 'errorMessage': 'no error'}
def __init__(self): self.wa = ApolloInstance(ca.apollo_url, ca.apollo_admin_email, ca.apollo_admin_password)
def get_apollo_instance(instance_name=None): conf = get_instance(instance_name=instance_name) return ApolloInstance(conf['url'], conf['username'], conf['password'])
other_id = "%s %s %s %s %s %s" % (f.qualifiers['Name'][0], f.type, rec.id, feat_strand, f.location.start, f.location.end) if other_id in other_attrs: print( "Found multiple other feat with same id '%s'!! Aborting" % other_id) sys.exit() other_attrs[other_id] = {'gene': f.qualifiers} #print(mrnas_attrs) #print(other_attrs) org_common_name = "genus_species" wa = ApolloInstance('http://*****:*****@xxxxxxxxxx', 'password...') def apply_attrs(feature_id, attrs): if 'symbol' in attrs: wa.annotations.set_symbol(feature_id, attrs['symbol'][0]) if 'description' in attrs: wa.annotations.set_description(feature_id, attrs['description'][0]) if 'Name' in attrs: wa.annotations.set_name(feature_id, attrs['Name'][0]) if 'Dbxref' in attrs: for dbx in attrs['Dbxref']: dbx = dbx.split(':') if len(dbx) == 2: wa.annotations.add_dbxref(feature_id, dbx[0], dbx[1]) if 'Note' in attrs:
from __future__ import print_function import os import random import re import string import sys import time from apollo import ApolloInstance import ldap wa = ApolloInstance(os.environ['APOLLO_URL'], os.environ['APOLLO_ADMIN'], os.environ['APOLLO_PASSWORD']) admin_users = [os.environ['APOLLO_ADMIN']] fake_email = os.environ['FAKE_EMAIL'] use_fake_email = fake_email and fake_email.startswith('@') default_group = os.environ['DEFAULT_GROUP'] ldap_user_filter = '(mail=*)' if 'LDAP_USER_FILTER' in os.environ and os.environ['LDAP_USER_FILTER']: ldap_user_filter = os.environ['LDAP_USER_FILTER'] ldap_group_filter = "(cn=*)" if 'LDAP_GROUP_FILTER' in os.environ and os.environ['LDAP_GROUP_FILTER']: ldap_group_filter = os.environ['LDAP_GROUP_FILTER'] ldap_conf = {