Ejemplo n.º 1
0
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}
Ejemplo n.º 2
0
def admin_get_genes():
    """ Gets all the genes in the database to display them in the admin tab

    Returns
    -------

    json
        error : Boolean
        errorMessage : str
        genes : List
    """
    dataInstance = Data(ca, session)
    gene_list = dataInstance.get_all_positions()
    result = {'error': False, 'errorMessage': "", 'genes': gene_list}
    return result
Ejemplo n.º 3
0
def remove_all_genes_from_db():
    """Remove all genes from de db

    Return
    ------
    json
        error : Boolean
        errorMessage: str
    """
    dataInstance = Data(ca, session)
    gene_list = dataInstance.get_all_positions()

    db = ca.mongo.db
    fs = gridfs.GridFS(db, collection="genes")

    for element in gene_list:
        fs.delete(element['_id'])

    result = {
        'error': False,
        'errorMessage': "",
    }
    return result