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 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"]}