def derived_from_file(filename, depth): '''search specified attributes and labels, custom query as POST''' if request.method == 'GET': #get filenames relations at depth msg = '' if filename: msg += 'Searching for {}'.format(filename) if depth: try: depth = int(depth) #make sure depth is int except ValueError: logger.error('Depth provided was not int') raise msg += ' at depth {}'.format(depth) logger.info(msg) with cpool.get_session() as session: #get session from driver statement = 'MATCH (n {name:{filename}})<-[:DERIVED_FROM*1..' if depth: statement += '{}'.format(depth) statement += ']-(m) return distinct m' #give me unique nodes return_me = [] logger.debug(statement) #if necessary for r in session.run(statement, {'filename': filename}): logger.info(r[0].properties) #testing return_me.append(r[0].properties) #format this later return jsonify(return_me), 200 #maybe 204 if empty... think still 200
def all_nodes(): '''Get All Nodes''' if request.method == 'GET': #get filenames relations at depth with cpool.get_session() as session: #get session from driver statement = 'MATCH (n)' statement += ' return distinct n' #give me unique nodes return_me = [] logger.debug(statement) #if necessary seen = {} for r in session.run(statement): logger.info(r[0].properties) #testing return_me.append(r[0].properties) #format this later return jsonify({'data': return_me }), 200 #maybe 204 if empty... think still 200
def parents_by_name(query): '''Get All parents for a given node''' if request.method == 'GET': #get filenames relations at depth with cpool.get_session() as session: #get session from driver statement = 'MATCH (n {name:{filename}})-[:CHILD_OF]->(m)' statement += ' return distinct m' #give me unique nodes return_me = [] logger.debug(statement) #if necessary seen = {} for r in session.run(statement, {'filename': query}): logger.info(r[0].properties) #testing return_me.append(r[0].properties) #format this later return jsonify({'data': return_me }), 200 #maybe 204 if empty... think still 200
def parents_by_name_post(): '''Get All parents for a given node by passing a list''' if request.method == 'POST': #get filenames relations at depth return_me = [] posted_data = request.get_json(force=True) if not posted_data: return 'You must post a list called data containing filenames', 400 for d in posted_data: with cpool.get_session() as session: #get session from driver statement = 'MATCH (n {name:{filename}})-[:CHILD_OF]->(m)' statement += ' return distinct m' #give me unique nodes # return_me = [] logger.debug(statement) #if necessary # seen = {} my_obj = {d: {'parents': []}} for r in session.run(statement, {'filename': d}): logger.info(r[0].properties) #testing my_obj[d]['parents'].append( r[0].properties) #attach parent return_me.append(my_obj) return jsonify({'data': return_me}), 200 #maybe 204 if empty...
def taxonomoy_list(genus): '''search specified attributes and labels, custom query as POST''' if request.method == 'GET': #get filenames relations at depth msg = '' with cpool.get_session() as session: #get session from driver statement = 'MATCH (n:fasta' if genus: genus = genus.lower() statement += ':{}'.format(genus) statement += ') return n' #give me unique nodes return_me = [] logger.debug(statement) #if necessary seen = {} for r in session.run(statement): target = r[0].properties['genus'] if genus: target = r[0].properties['species'] if target in seen: continue seen[target] = 1 logger.info(target) #testing return_me.append(target) #format this later return jsonify({'data': return_me }), 200 #maybe 204 if empty... think still 200
def visualize_paths(filename): '''Get all data from parent assembly for visualization returns a list of url and name tuples ''' if request.method == 'GET': # get fasta and then get all others msg = '' count = 0 if filename: msg += 'Searching for {}'.format(filename) logger.info(msg) with cpool.get_session() as session: # get session from driver statement = 'MATCH (n {name:{filename}})-[:DERIVED_FROM*1..' statement += ']->(m:fasta) return distinct m' # give me unique nodes return_me = [] logger.debug(statement) # if necessary for r in session.run(statement, {'filename': filename}): if count == 1: logger.warning('Multiple fasta for {}'.format(filename)) count += 1 logger.info(r[0].properties) # testing return_me.append(r[0].properties) # get dictionary if not return_me: statement = 'MATCH (n:fasta {name:{filename}}) return n' return_me = [] for r in session.run(statement, {'filename': filename}): return_me.append(r[0].properties) if not return_me: logger.error('No fasta found for {}'.format(filename)) return jsonify([]), 200 fasta = return_me[0]['name'] statement = 'MATCH p=(n {name:{filename}})-[:DERIVED_FROM*1..]-(m) return distinct m;' # should be one line fix later return_me = [] for r in session.run(statement, {'filename': fasta}): return_me.append(r[0].properties) # get dictionary return jsonify(return_me), 200 # maybe 204 if empty... think still 200