Ejemplo n.º 1
0
 def add_node_if_not_drawn(element_set, element, flux):
     if element.id not in element_set:
         n = element.name[4:]
         name = met_name_by_kegg_id[n] if n in met_name_by_kegg_id else None
         Kegg._add_node(data,
                        element,
                        int(flux),
                        name=name,
                        show_compound_img=None)
         element_set.add(element.id)
Ejemplo n.º 2
0
 def add_node(elements):
     for e in elements:
         e_name = e.name
         if e_name in UNDESIRABLES:
             continue
         e_id = e.id
         if e_name not in added_node:
             added_node.add(e_name)
             id_by_name[e_name] = e_id
             Kegg._add_node(data,
                            e_id,
                            'metabolites',
                            e.name, None,
                            '#000000')
Ejemplo n.º 3
0
def get_kgml():
    pathway_id = request.args.get("pathway_id")
    if pathway_id is None:
        return []
    cytoscape_formatted = Kegg.get_kgml_network(pathway_id)
    j = json.dumps(cytoscape_formatted)
    return j
Ejemplo n.º 4
0
def test_unique_kegg_names():
    kegg_list = Kegg.get_org_list()
    from collections import Counter
    l = []
    d = csv.DictReader(kegg_list.split('\n'), delimiter='\t', fieldnames=('code', 'org', 'tax'))
    for row in d:
        code, org, tax = row['code'], row['org'], row['tax']
        l.append(tax)
    c = Counter(l)
    max_val = max(c.values())
    print "Max val:", max_val
    while max_val > 1:
        print "#", max_val, " count:", len([v for v in c.values() if v == max_val])
        max_val -= 1
Ejemplo n.º 5
0
def get_kgml(username):
    """
    main function to visualize network
    return json encoded graph
    """

    pathway_id = request.args.get('pathway_id')
    if pathway_id is None:
        return json.dumps([])

    analysis_id = request.args.get('analysis_id')
    analysis = Analysis.query.filter(Analysis.id == analysis_id).first_or_404()

    # retrieve file data from s3
    filename = '{}/{}/{}'.format(username, analysis.project_id, analysis_id)
    try:
        resp = requests.get(S3_URL + filename)
    except ConnectionError:
        return render_template('errors/server_error.html', form=LoginForm())
    # return error code if request failed
    if resp.status_code != 200:
        return render_template('errors/server_error.html', form=LoginForm())

    # load fba analysis results
    results = json.loads(resp.text)

    # get the sbml model
    model = analysis.model.get_cobra_model()
    if model is None:
        return render_template('errors/server_error.html')

    if pathway_id == 'whole':
        # whole drawing requested
        cytoscape_formatted = _build_genome_scale_network(model, results)

    else:
        kegg_model = Kegg.get_kgml_obj(pathway_id)

        if model is None or kegg_model is None:
            return render_template('errors/page_not_found.html', form=LoginForm())

        kegg_model_name = request.args.get('pathway_name')
        cytoscape_formatted = build_kegg_network_mixed(kegg_model,
                                                       kegg_model_name,
                                                       model,
                                                       results)
    return json.dumps(cytoscape_formatted)
Ejemplo n.º 6
0
def initdb():
    """Creates the database."""
    db.create_all()

    logging.info('Getting kegg organism list...')
    kegg_list = Kegg.get_org_list()

    # use only get memory error otherwise
    # print BiomodelMongo.objects.only('organism', 'name').all()
    mongo_list = dict(
        (b.organism, b.name)
        for b in BiomodelMongo.objects.only('organism', 'name').all()
        )

    mongo_orgs = set(mongo_list.keys())

    # to prevent insertion porting the same name
    kegg_names = set()

    logging.info('Insertion begins...')
    d = csv.DictReader(kegg_list.split('\n'), delimiter='\t', fieldnames=('code', 'org', 'tax'))
    for row in d:
        code, org, tax = row['code'], row['org'], row['tax']
        if org in mongo_orgs:
            if tax not in kegg_names:
                o = Organism(row['code'], row['org'], row['tax'])
                o.save()
                b = Biomodel(name=tax, kegg_org=org)
                b.save()
                # finally tax to the set
                kegg_names.add(tax)

    # insert user
    u = User(username='******', email='*****@*****.**', password='******')
    u.save()

    logging.info('Done !')
Ejemplo n.º 7
0
def visualize_fba_analysis(username, analysis_id):
    """
    main endpoint to visualize flux balance analysis

    """
    analysis = Analysis.query.filter(Analysis.id == analysis_id).first_or_404()

    # retrieve file data from s3
    filename = '{}/{}/{}'.format(username, analysis.project_id, analysis_id)
    resp = requests.get(S3_URL + filename)

    # return error code if request failed
    if resp.status_code != 200:
        return render_template('errors/server_error.html'), 500

    orgs = Organism.query.order_by(Organism.tax).all()

    model = analysis.model
    model_name = model.name
    pathways = Kegg.get_pathways_list(org=model.kegg_org)
    return render_template('user/fba_analysis.html',
                           analysis=analysis, organisms=orgs,
                           model_name=model_name, pathways=pathways,
                           display_sidebar=False)
Ejemplo n.º 8
0
def get_pathways():
    org = request.args.get("org", "hsa")  # the default will be the human.
    pathways = Kegg.get_pathways_list(org)
    data = json.dumps(pathways)
    return data
Ejemplo n.º 9
0
def get_kegg_pathways(username):
    org = request.args.get('org', 'hsa')  # the default will be the human.
    pathways = Kegg.get_pathways_list(org)
    data = json.dumps(pathways)
    return data