예제 #1
0
def check_cyrest(port):
    print('start supervisord client')
    try:
        subprocess.run([
            "/usr/bin/supervisord", "-c",
            "/etc/supervisor/conf.d/supervisord.conf"
        ],
                       check=True)
    except subprocess.CalledProcessError as e:
        print('an error has occurred while trying to run TPS\n\n' + str(e))

    connection = False
    while not connection:
        try:
            print(f"try port {port}")
            cytoscape = cyrest.cyclient(host='localhost', port=port)
            status = _status(cytoscape, 'localhost', port)
            if not isinstance(status, requests.models.Response):
                time.sleep(4)
            else:
                if status.ok and status.status_code == 200:
                    connection = True
                    print('connection successful, exiting script')
                else:
                    print(f"{status.status_code}")
                    sys.exit()
        except ConnectionError as e:
            print(e)
            sys.exit()
예제 #2
0
파일: runner.py 프로젝트: gitter-lab/tps
    def __visualize_outputs(self):
        _annot_file = os.path.abspath(self.annotations.out_annot_file)
        _style_file = os.path.abspath(self.annotations.out_style_file)

        cyclient = cyrest.cyclient()
        cy = CyRestClient()
        #cy.session.delete()
        cy.network.create_from(self.runner.output_files['network-file'])
        time.sleep(2)
        style = cyclient.vizmap.load_file(_style_file)
        cyclient.vizmap.apply(style[0])
        cyclient.table.import_file(afile=_annot_file,
                                   firstRowAsColumnNames=True,
                                   keyColumnIndex='1',
                                   startLoadRow='0',
                                   dataTypeList=self.data_types)
        cyclient.session.save_as(session_file=self.save_file)
예제 #3
0
        G_full.remove_edges_from(loops)
        for node1, node2, idx in G_full.edges:
            G_full[node1][node2][idx]['predictions'] = 1
        # print(G_full is None)
        G_full, statistics = preprocess_network(G_full, G_full)
        pickle.dump(G_full, open(graph_file, 'wb'))
        pickle.dump(statistics, open(statistics_file, 'wb'))
    else:
        G_full = pickle.load(open(graph_file, 'rb'))
        statistics = pickle.load(open(statistics_file, 'rb'))

    # print(statistics)
    statistics['impact_factor'] = impact_factor['genes_max']
    # statistics['impact_factor_color'] =
    G_full = add_impact_factor(G_full, impact_factor['genes_max'])
    cytoscape = cyrest.cyclient()

    for key in modules.keys():
        if 'Dermatitis, Occupational' not in key:
            continue
        out_fname = 'disease-figures/{}.pdf'.format(key)
        print(out_fname)
        # if os.path.isfile(out_fname):
        #    continue
        print(modules[key])
        print(G_full.nodes)
        G_module = prune_network(deepcopy(G_full), ['name'], [modules[key]],
                                 [], [],
                                 hub_threshold=10000,
                                 affect_neighbors=True)
        G_module = color_nodes(G_module, modules[key], 'red')
## Prerequisites
In addition to the RCy3 package, you will need the latest version of Cytoscape, which can be downloaded from http://www.cytoscape.org/download.php. Simply follow the installation instructions on screen.

## Getting started
First, launch Cytoscape and keep it running whenever using py2cytoscape. Confirm that you have everything installed and running:
"""

import handout
doc = handout.Handout('html_documents/py/differentially-expressed-genes')

import io
from contextlib import redirect_stdout

from py2cytoscape import cyrest
HOST = "localhost"
cytoscape = cyrest.cyclient(host=HOST)
f = io.StringIO()
with redirect_stdout(f):
    cytoscape.status()
    cytoscape.version()
s = f.getvalue()
doc.add_text(s)
doc.show()
"""
# Differentially Expressed Genes Network Analysis

This protocol describes a network analysis workflow in Cytoscape for a set of differentially expressed genes. Points covered:

- Retrieving relevant networks from public databases
- Network functional enrichment analysis
- Integration and visualization of experimental data
예제 #5
0
import os
import sys
from time import sleep
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
from py2cytoscape import cyrest
from IPython.display import Image


cytoscape=cyrest.cyclient(host="localhost", port=8081, version="V1")
cytoscape.version()
예제 #6
0
variants = []

# reading the variants from file
with open(variant_file, 'r') as f:
    for line in f:
        variants.append(line.strip())

# retrieving the gene ids by variant ids using biomart attributes
genes_by_var = dataset.query(
    attributes=['refsnp_id', 'ensembl_gene_stable_id'],
    filters={'snp_filter': variants})
#print (dataset.attributes)

# Step 2
# create cytoscape client (make sure app is running)
cy = cyclient()
# create a new empty network
cy.network.create_empty(name=network_name)

# add variants to the network as nodes
for snp in variants:
    cy.network.add_node(network=network_name, name=snp)

# getting keys (names) of the two columns
k_snp, k_gen = genes_by_var.keys()
# add genes given by biomart taking unique gene names
for gene in set(genes_by_var[k_gen]):
    cy.network.add_node(network=network_name, name=gene)

# add edges to the network using the dataframe given by biomart query
for index, row in genes_by_var.iterrows():