CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
NodeCut.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # go to the vertex file and pick a specific function or group of functions
4 # with hits less then cutoff. then go to the path file and get all the
5 # paths that contain the functions. produce a new path file from this.
6 
7 import sys
8 
9 class Int:
10  def __init__(self):
11  self.value = 1
12  def inc(self):
13  self.value+=1
14  def __repr__(self):
15  return str(self.value)
16 
17 class NameLine:
18  def __init__(self,line):
19  self.attr = line.split()
20  self.seen = int(self.attr[4])
21  self.hits = int(self.attr[3])
22  self.id = int(self.attr[0])
23  def hits(self): return self.hits
24  def seen(self): return self.seen
25  def id(self): return self.id
26  def name(self): return self.attr[2]
27 
28 class PathLine:
29  def __init__(self,line):
30  self.attr = line.split()
31  self.hits = int(self.attr[1])
32  self.id = int(self.attr[0])
33  def hits(self): return self.hits
34  def seen(self): return self.hits
35  def id(self): return self.id
36 
37 class MatchId:
38  def __init__(self,id):
39  self.id = id
40  def match(self,nline):
41  return self.id == nline.id()
42 
44  def __init__(self,count):
45  self.count = count
46  def match(self,nline):
47  return self.count < nline.attr[4]
48 
50  def __init__(self,count):
51  self.count = count
52  def match(self,nline):
53  return self.count < nline.attr[3]
54 
55 class MatchIdSet:
56  def __init__(self,idset):
57  self.idset = idset
58  def match(self,nline):
59  return self.idset.get(nline.attr[0])!=None
60 
61 class Match
62 
63 class Parse:
64  def __init__(self, pre_in, pre_out):
65  self.in_names = pre_in + "names"
66  self.in_paths = pre_in + "paths"
67  self.out_names = pre_in + "names"
68  self.out_paths = pre_in + "paths"
69  self.out_edges = pre_out + "edges"
70  self.out_totals = pre_out + "totals"
71 
72  def cut(matcher):
73  fin_names = open(self.in_names,'r')
74  fout_names = open(self.out_names,'w')
75  names = []
76  for line in fin.names.xreadlines():
77  n = NameLine(line)
78  b = matcher(n)
79  if b<0: break
80  if b:
81  names[n.id()]
82  fout.write(line)
83  return names
84 
85  def selectOneName(value):
86  fin_names = open(self.in_names,'r')
87  fout_names = open(self.out_names,'w')
88  names = {}
89  for line in fin.names.xreadlines():
90  a=line.split()
91  if int(a[3])==value: break
92  names[int(a[0])]=1
93  fout.write(line)
94  return names
95 
96  def trimNames(cutoff):
97  fin_names = open(self.in_names,'r')
98  fout_names = open(self.out_names,'w')
99  names = []
100  for line in fin.names.xreadlines():
101  a=line.split()
102  if int(a[3])<cuttoff: break
103  names[int(a[0])]
104  fout.write(line)
105  return names
106 
107  def selectManyNames(ids):
108  fin_names = open(self.in_names,'r')
109  fout_names = open(self.out_names,'w')
110  names = {}
111  for line in fin.names.xreadlines():
112  a=line.split()
113  if ids.get(int(a[0]))!=None:
114  fout.write(line)
115 
116  def trimPaths(cutoff):
117  fin_paths = open(self.in_paths,'r')
118  fout_paths = open(self.out_paths,'w')
119  self.tot_paths
120 
121  def pathContaining(id):
122  pass
123 
124 def runme(in_nodefile, in_treefile, out_treefile, cutoff, cuttype)
125  fin_nodes = open(in_nodefile,'r')
126  fin_paths = open(in_treefile,'r')
127  fout = open(out_treefile,'w')
128  tree = {}
129 
130  for line in fin.xreadlines():
131  a = line.split()
132  id = int(a.pop(0))
133  tot = int(a.pop(0))
134  if tot < cutoff:
135  print tot
136  continue
137  head = int(a.pop(0))
138 
139  for node in a:
140  val = int(node)
141  key = (head,val)
142  n = tree.get(key)
143  if n == None:
144  tree[key] = Int()
145  else:
146  n.inc()
147  head = val
148 
149  for node in tree.items():
150  # print node
151  print >>fout, node[1], ' ', node[0][0], ' ', node[0][1]
152 
153 if __name__ == "__main__":
154  if len(sys.argv) < 5:
155  print "usage: ", sys.argv[0], " in_prefix out_prefix cutoff type"
156  print " type = 0 means accept one exact match for cutoff value"
157  print " type = 1 means accept anything >= cutoff value"
158  sys.exit(1)
159 
160  in_nodefile = sys.argv[1]
161  in_treefile = sys.argv[2]
162  out_treefile = sys.argv[3]
163  cutoff = int(sys.argv[4])
164  cuttype = int(sys.argv[5])
165 
166  runme(in_nodefile, in_treefile, out_treefile, cutoff, cuttype)
def selectOneName
Definition: NodeCut.py:85
def __repr__
Definition: NodeCut.py:14
def __init__
Definition: NodeCut.py:64
def trimPaths
Definition: NodeCut.py:116
def __init__
Definition: NodeCut.py:10
def selectManyNames
Definition: NodeCut.py:107
def inc
Definition: NodeCut.py:12
def trimNames
Definition: NodeCut.py:96
def pathContaining
Definition: NodeCut.py:121