def main_library_gmt(args): filter_map = None if args.filter is not None: filter_map = {} handle = open(args.filter) for line in handle: filter_map[line.rstrip()] = True handle.close() for path_dir in glob(os.path.join(args.library, "*")): if os.path.isdir(path_dir): path_name = os.path.basename(path_dir) spf_path = os.path.join(path_dir, "graph.spf") handle = open(spf_path) gr = network_convert.read_spf(handle, strict=False) handle.close() if args.organism is None or gr.graph.get('organism', args.organism) == args.organism: if filter_map is None: out = gr.node.keys() else: out = [] for a in gr.node.keys(): if a in filter_map: out.append(a) if not args.skip_empty or len(out): print "%s\t%s" % (path_name, "\t".join(out))
def check_project(self, project): handle = open(os.path.join(self.repo, project, "INFO")) conf = yaml.load(handle.read()) handle.close() errors = [] if 'PID' not in conf: errors.append(Exception("Missing required PID field")) if 'DESC' not in conf: errors.append(Exception("Missing required DESC description field")) if 'SOURCE' not in conf: errors.append(Exception("Missing required SOURCE field")) handle = open(os.path.join(self.repo, project, "graph")) gr = network_convert.read_spf(handle) handle.close() if self.hugo_map is not None: for node in gr.node: if gr.node[node]['type'] == 'protein': if node not in self.hugo_map: errors.append(Exception("Gene Symbol not found:\t%s" % (node))) if self.dogma is not None: for node in gr.node: ntype = gr.node[node]['type'] if self.dogma.get_dogma(ntype) == None: errors.append(Exception("No dogma for node %s type %s" % (node, ntype))) return errors
paths = None if args.r: paths = [] for a in start_paths: paths += list(scan_dir(a, args.filter)) else: paths = start_paths for file_path in paths: gr = None if args.spf: handle = open(file_path) gr = network_convert.read_spf(handle, strict=False) handle.close() else: handle = open(file_path) gr = network_convert.read_xgmml(handle) handle.close() if gr is not None: found = [] if args.property is None: for t in terms: if t in gr.node: found = [ t ] else: for node in gr.node:
def read(self): handle = open(self.path) cur_gr = network_convert.read_spf(handle, strict=False) handle.close() return cur_gr
def maxCC(ccs): max = 0 for cc in ccs: if len(cc) > max: max = len(cc) return max graph = None if opts.network.endswith(".sif"): graph = convert.read_sif(open(opts.network)) else: graph = convert.read_spf(open(opts.network)) heats = parseHeats(opts.heats) if opts.cut_graph and not opts.node_attributes: cut_val = None try: cutoff = float(opts.cut_graph) except: raise Exception( "Error: value supplied to cut_graph must be a positive number") cutG = cutGraph(graph, heats, cutoff) convert.write_sif(cutG, sys.stdout) sys.exit(0) if opts.node_attributes:
#!/usr/bin/env python import sys import os from pathway_tools import convert import yaml if __name__ == "__main__": handle = open(sys.argv[1]) gr = convert.read_spf(handle, strict=False) handle.close() name_tab = {} handle = open(sys.argv[2]) for line in handle: tmp = line.rstrip().split("\t") name_tab[tmp[0]] = tmp[1:] outdir = sys.argv[3] i = 1 for pathid in name_tab: print pathid pathdir = os.path.join(outdir, pathid) if not os.path.exists(pathdir): os.mkdir(pathdir) config = {"DESC" : str(pathid)} #if path in name_tab: # config["PID"] = int(name_tab[path][0]) # config["SOURCE"] = str(name_tab[path][1])
if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--src-spf', help="Source SimplePathwayFile") parser.add_argument('--dst-spf', help="Dest SimplePathwayFile") parser.add_argument('--src-xgmml', help="Source XGMML File") parser.add_argument('--dst-xgmml', help="Dest XGMML File") args = parser.parse_args() gr1 = None gr2 = None if args.src_spf: handle1 = open(args.src_spf) gr1 = network_convert.read_spf(handle1, strict=False) handle1.close() if args.src_xgmml: handle1 = open(args.src_xgmml) gr1 = network_convert.read_xgmml(handle1) handle1.close() if args.dst_spf: handle2 = open(args.dst_spf) gr2 = network_convert.read_spf(handle2, strict=False) handle2.close() if args.src_xgmml: handle1 = open(args.dst_xgmml) gr2 = network_convert.read_xgmml(handle1) handle1.close()
default=None) parser.add_argument('--target-xgmml', help="Search Target in XGMML graph format", default=None) parser.add_argument('--query-pathattr', default="pid") parser.add_argument('--target-pathattr', default="pid") parser.add_argument("--query-nodetype", default=None) parser.add_argument("--target-nodetype", default=None) parser.add_argument("--min", "-m", type=int, default=1) parser.add_argument("--top", type=int, default=None) args = parser.parse_args() if args.query_spf: handle = open(args.query_spf) query_net = convert.read_spf(handle) if args.query_xgmml: handle = open(args.query_xgmml) query_net = convert.read_xgmml(handle) if args.target_spf: handle = open(args.target_spf) target_net = convert.read_spf(handle) if args.target_xgmml: handle = open(args.target_xgmml) target_net = convert.read_xgmml(handle) target_pathways = {} for n in target_net.node:
import networkx from pathway_tools import convert if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--spf', help="SimplePathwayFormat File") parser.add_argument('--xgmml', help="XGMML File") parser.add_argument('--top', help="Top Count", type=int, default=10) args = parser.parse_args() gr = None if args.spf: handle = open(args.spf) gr = convert.read_spf(handle, strict=False) handle.close() if args.xgmml: handle = open(args.xgmml) gr = convert.read_xgmml(handle) handle.close() type_count = {} for node in gr.node: if 'type' in gr.node[node]: node_type = gr.node[node]['type'] type_count[node_type] = type_count.get(node_type, 0) + 1 print("Node Count: %d" % (len(gr.nodes()))) print("Edge Count: %d" % (len(gr.edges()))) print("Connected Components: %d" %
return nodes def maxCC(ccs): max = 0 for cc in ccs: if len(cc) > max: max = len(cc) return max graph = None if opts.network.endswith(".sif"): graph = convert.read_sif(open(opts.network)) else: graph = convert.read_spf(open(opts.network)) heats = parseHeats(opts.heats) if opts.cut_graph and not opts.node_attributes: cut_val = None try: cutoff = float(opts.cut_graph) except: raise Exception("Error: value supplied to cut_graph must be a positive number") cutG = cutGraph(graph, heats, cutoff) convert.write_sif(cutG, sys.stdout) sys.exit(0) if opts.node_attributes: if not opts.cut_graph:
parser.add_argument('--query-spf', help="Input query in simple pathway format", default=None) parser.add_argument('--query-xgmml', help="Input query in XGMML graph format", default=None) parser.add_argument('--target-sfp', help="Search Target in Simple Pathway Format", default=None) parser.add_argument('--target-xgmml', help="Search Target in XGMML graph format", default=None) parser.add_argument('--query-pathattr', default="pid") parser.add_argument('--target-pathattr', default="pid") parser.add_argument("--query-nodetype", default=None) parser.add_argument("--target-nodetype", default=None) parser.add_argument("--min", "-m", type=int, default=1) parser.add_argument("--top", type=int, default=None) args = parser.parse_args() if args.query_spf: handle = open(args.query_spf) query_net = convert.read_spf(handle) if args.query_xgmml: handle = open(args.query_xgmml) query_net = convert.read_xgmml(handle) if args.target_spf: handle = open(args.target_spf) target_net = convert.read_spf(handle) if args.target_xgmml: handle = open(args.target_xgmml) target_net = convert.read_xgmml(handle) target_pathways = {}