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

View of /FigKernelScripts/make_maps_from_sub.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Wed Jun 16 14:57:28 2004 UTC (15 years, 9 months ago) by olson
Branch: MAIN
New file.

from FigKernelPackages.FIG2 import FIG
import FIG_Config
import re
import os, sys, string

IN_DIR = "%s/SubsystemDiagrams/" % FIG_Config.data
OUT_DIR = "%s/MAP_SUPPORT/Maps/" % FIG_Config.data

def add_to_index(id, name):
	line = "%s\t%s\n" % (id, name)
	file = open("%s/MAP_SUPPORT/INDEX" % FIG_Config.data, "r")
	l = file.readlines()
	if line not in l:
		l.append(line)
		print "Adding ", line
	file = open("%s/MAP_SUPPORT/INDEX" % FIG_Config.data, "w")
	file.writelines(l)
	file.close()


def create_tables(dir):
	# for each area in teh diagram,
		#format a line in the role_coords tabel (role\tcoords)
		#format a line in the link table (coord\tlink)
	#write out the role_coords table in directory OUT_DIR+dir
	#write out the link_table in directory OUT_DIR+dir
	area_table = open("%s%s/area_table" % ( OUT_DIR, dir), "w")
	area_table.write("Test")
	area_table.close()	
	
	
def make_maps(in_dir, dir):
	print 
	sub = fig.get_subsystem(dir)
	diags = sub.get_diagrams()
	for diagram in diags:	
		mapname = dir+"_"+diagram
		if not os.path.isdir(OUT_DIR+mapname):
			os.mkdir(OUT_DIR+mapname)
		os.system("cp %s%s/%s/diagram.png %s%s/diagram.png" % (in_dir, dir, diagram, OUT_DIR, mapname))
		dia = sub.get_diagram(diagram)[0]
		areas = dia.get_areas()
		roles = {}
		coords = {}
		link_coords={}
		links = {}
	        for aitem in areas:
			area, tag, value = aitem
			print "area=%s tag=%s value=%s" % (area, tag, value)

			if tag == "role":
				roles[area] = value
			if tag == "shape":
				shape_kind, shape_coords = value.split(":", 1)

				if shape_kind == "rect":
					x1,y1,x2,y2 = shape_coords.split(",");
					cvalue = "rect (%s,%s) (%s,%s)" %(x1, y1, x2, y2)
				else:
					print "Unknown shape kind ", shape_kind
					cvalue = ""

				coords[area] = cvalue
				link_coords[area] = "<AREA shape=rect coords=%s,%s,%s,%s " % (x1,y1,x2,y2)
			if tag == "link":
				m = re.search(r'^"([^"]+)",(.*)$', value)
				if m:
					value = m.group(2)
				else:
					print "Didn't match", value
				links[area] = value

		link_table = open(OUT_DIR+mapname+"/link.table", "w")
		role_coords = open(OUT_DIR+mapname+"/role_coords.table", "w")
		for area in roles.keys():
			role_coords.write(roles[area]+"\t"+coords[area]+"\n")
			if links.has_key(area): 
				link_table.write('%s href="%s">\n' % (link_coords[area], links[area])) 
		role_coords.close()
		link_table.close()
		add_to_index(mapname, dir)
		
	

fig = FIG()

for dir in os.listdir(IN_DIR):
	print dir
	make_maps(IN_DIR, dir)


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3