[Bio] / FigKernelScripts / make_maps_from_sub.py Repository:
ViewVC logotype

Annotation of /FigKernelScripts/make_maps_from_sub.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download) (as text)

1 : olson 1.1 from FigKernelPackages.FIG2 import FIG
2 :     import FIG_Config
3 :     import re
4 :     import os, sys, string
5 :    
6 :     IN_DIR = "%s/SubsystemDiagrams/" % FIG_Config.data
7 :     OUT_DIR = "%s/MAP_SUPPORT/Maps/" % FIG_Config.data
8 :    
9 :     def add_to_index(id, name):
10 :     line = "%s\t%s\n" % (id, name)
11 :     file = open("%s/MAP_SUPPORT/INDEX" % FIG_Config.data, "r")
12 :     l = file.readlines()
13 :     if line not in l:
14 :     l.append(line)
15 :     print "Adding ", line
16 :     file = open("%s/MAP_SUPPORT/INDEX" % FIG_Config.data, "w")
17 :     file.writelines(l)
18 :     file.close()
19 :    
20 :    
21 :     def create_tables(dir):
22 :     # for each area in teh diagram,
23 :     #format a line in the role_coords tabel (role\tcoords)
24 :     #format a line in the link table (coord\tlink)
25 :     #write out the role_coords table in directory OUT_DIR+dir
26 :     #write out the link_table in directory OUT_DIR+dir
27 :     area_table = open("%s%s/area_table" % ( OUT_DIR, dir), "w")
28 :     area_table.write("Test")
29 :     area_table.close()
30 :    
31 :    
32 :     def make_maps(in_dir, dir):
33 :     print
34 :     sub = fig.get_subsystem(dir)
35 :     diags = sub.get_diagrams()
36 :     for diagram in diags:
37 :     mapname = dir+"_"+diagram
38 :     if not os.path.isdir(OUT_DIR+mapname):
39 :     os.mkdir(OUT_DIR+mapname)
40 :     os.system("cp %s%s/%s/diagram.png %s%s/diagram.png" % (in_dir, dir, diagram, OUT_DIR, mapname))
41 :     dia = sub.get_diagram(diagram)[0]
42 :     areas = dia.get_areas()
43 :     roles = {}
44 :     coords = {}
45 :     link_coords={}
46 :     links = {}
47 :     for aitem in areas:
48 :     area, tag, value = aitem
49 :     print "area=%s tag=%s value=%s" % (area, tag, value)
50 :    
51 :     if tag == "role":
52 :     roles[area] = value
53 :     if tag == "shape":
54 :     shape_kind, shape_coords = value.split(":", 1)
55 :    
56 :     if shape_kind == "rect":
57 :     x1,y1,x2,y2 = shape_coords.split(",");
58 :     cvalue = "rect (%s,%s) (%s,%s)" %(x1, y1, x2, y2)
59 :     else:
60 :     print "Unknown shape kind ", shape_kind
61 :     cvalue = ""
62 :    
63 :     coords[area] = cvalue
64 :     link_coords[area] = "<AREA shape=rect coords=%s,%s,%s,%s " % (x1,y1,x2,y2)
65 :     if tag == "link":
66 :     m = re.search(r'^"([^"]+)",(.*)$', value)
67 :     if m:
68 :     value = m.group(2)
69 :     else:
70 :     print "Didn't match", value
71 :     links[area] = value
72 :    
73 :     link_table = open(OUT_DIR+mapname+"/link.table", "w")
74 :     role_coords = open(OUT_DIR+mapname+"/role_coords.table", "w")
75 :     for area in roles.keys():
76 :     role_coords.write(roles[area]+"\t"+coords[area]+"\n")
77 :     if links.has_key(area):
78 :     link_table.write('%s href="%s">\n' % (link_coords[area], links[area]))
79 :     role_coords.close()
80 :     link_table.close()
81 :     add_to_index(mapname, dir)
82 :    
83 :    
84 :    
85 :     fig = FIG()
86 :    
87 :     for dir in os.listdir(IN_DIR):
88 :     print dir
89 :     make_maps(IN_DIR, dir)
90 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3