def get_similarity_network(self): plot = None try: cwd = os.path.abspath(os.path.dirname(__file__)) query_path = os.path.join(cwd, self.queries_file) project_cypher = query_utils.read_queries(query_path) query = query_utils.get_query(project_cypher, query_id="projects_subgraph") list_projects = [] driver = connector.getGraphDatabaseConnectionConfiguration() if "other_id" in self.similar_projects: list_projects = self.similar_projects[ "other_id"].values.tolist() list_projects.append(self.identifier) list_projects = ",".join(['"{}"'.format(i) for i in list_projects]) query = query.replace("LIST_PROJECTS", list_projects) path = connector.sendQuery(driver, query, parameters={}).data() G = acore_utils.neo4j_path_to_networkx(path, key='path') args = {} style, layout = self.get_similarity_network_style() args['stylesheet'] = style args['layout'] = layout args['title'] = "Projects subgraph" net, mouseover = acore_utils.networkx_to_cytoscape(G) plot = viz.get_cytoscape_network(net, "projects_subgraph", args) except Exception as err: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] logger.error( "Error: {}. Reading queries from file {}: {}, file: {},line: {}" .format(err, query_path, sys.exc_info(), fname, exc_tb.tb_lineno)) return plot
def get_project_information(driver, project_id): query_name = 'project_graph' queries = [] data = [] res = [] try: query = '' data_upload_cypher = get_data_upload_queries() for section in data_upload_cypher[query_name]: code = section['query'] queries.extend( code.replace("PROJECTID", project_id).split(';')[0:-1]) for query in queries: result = connector.sendQuery(driver, query + ";")[0] data.append(result) except Exception as err: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] logger.error( "Error: {}. Creating analytical samples: Query name ({}) - Query ({}), error info: {}, file: {},line: {}" .format(err, query_name, query, sys.exc_info(), fname, exc_tb.tb_lineno)) if data: for i, j in enumerate(data): df = pd.DataFrame([data[i]], columns=data[i].keys()) header = '_'.join(df.columns[0].split('_', 1)[1:]).capitalize() df.rename(columns={df.columns[0]: 'project'}, inplace=True) res.append( viz.get_table(df, identifier='new_project_{}'.format(header), args={ 'title': '{} data uploaded for project {}'.format( header, project_id) })) else: res = None logger.error( "Error: No data was uploaded for project: {}. Review your experimental design and data files and the logs for errors." .format(project_id)) return res
def remove_project(self, host="localhost", port=7687, user="******", password="******"): try: cwd = os.path.abspath(os.path.dirname(__file__)) query_path = os.path.join(cwd, self.queries_file) project_cypher = query_utils.read_queries(query_path) query = query_utils.get_query(project_cypher, query_id="remove_project") driver = connector.connectToDB(host, port, user, password) queries = query.replace("PROJECTID", self.identifier) for query in queries.split(';')[:-1]: result = connector.sendQuery(driver, query + ';', parameters={}).data() except Exception as err: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] logger.error( "Error removing project {}. Query file: {},line: {}, error: {}" .format(self.identifier, fname, exc_tb.tb_lineno, err))
def get_db_schema(): """ Retrieves the database schema :return: network with all the database nodes and how they are related """ style = [{ 'selector': 'node', 'style': { 'label': 'data(name)', 'background-color': 'data(color)', 'text-valign': 'center', 'text-halign': 'center', 'border-color': 'gray', 'border-width': '1px', 'width': 55, 'height': 55, 'opacity': 0.8, 'font-size': '14' } }, { 'selector': 'edge', 'style': { 'label': 'data(label)', 'curve-style': 'bezier', 'opacity': 0.7, 'width': 0.4, 'font-size': '5' } }] layout = { 'name': 'cose', 'idealEdgeLength': 100, 'nodeOverlap': 20, 'refresh': 20, 'randomize': False, 'componentSpacing': 100, 'nodeRepulsion': 400000, 'edgeElasticity': 100, 'nestingFactor': 5, 'gravity': 80, 'numIter': 1000, 'initialTemp': 200, 'coolingFactor': 0.95, 'minTemp': 1.0 } query_name = 'db_schema' cypher = get_query() if query_name in cypher: if 'query' in cypher[query_name]: query = cypher[query_name]['query'] path = connector.sendQuery(driver, query, parameters={}).data() G = utils.neo4j_schema_to_networkx(path) args = {'height': '1000px'} args['stylesheet'] = style args['layout'] = layout args['title'] = "Database Schema" net, mouseover = utils.networkx_to_cytoscape(G) plot = viz.get_cytoscape_network(net, "db_schema", args) return plot