[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.4 - (download) (as text) (annotate)
Thu Jul 1 22:19:02 2004 UTC (15 years, 5 months ago) by olson
Branch: MAIN
CVS Tags: merge-trunktag-bobdev_news-2, Root-bobdev_news, merge-bobdev_news-1, caBIG-dataload-0, merge-trunktag-bobdev_news-1, merge-bodev_news-3, efrank-preMakefileToStandardMk, caBIG-00-00-00, merge-bobdev_news-2, merge-trunktag-bodev_news-3
Branch point for: Branch-bobdev_news
Changes since 1.3: +2 -1 lines
test for existence of link before referring to it.

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

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

if not os.path.isdir(IN_DIR):
	print "Creating ", IN_DIR
	os.makedirs(IN_DIR)

if not os.path.isdir(OUT_DIR):
	print "Creating ", OUT_DIR
	os.makedirs(OUT_DIR)

def add_to_index(id, name):
	line = "%s\t%s\n" % (id, name)
	index_file = "%s/MAP_SUPPORT/INDEX" % FIG_Config.data

	if os.path.isfile(index_file):
		
		file = open(index_file, "r")
		l = file.readlines()
		file.close()
	else:
		l = []
		
	if line not in l:
		l.append(line)
		print "Adding ", line
		
	file = open(index_file, "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)
	if sub is None:
		return
	
	diags = sub.get_diagrams()
	if diags is None:
		return
	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 = {}
		compounds = {}
	        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 == "compound":
				compounds[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)
					link_coords[area] = "<AREA shape=rect coords=%s,%s,%s,%s " % (x1,y1,x2,y2)

				elif shape_kind == "circle":
					x, y, r = shape_coords.split(",");
					cvalue = "circ (%s,%s) %s" % (x, y, r)
					link_coords[area] = "<AREA shape=circle coords=%s,%s,%s " % (x, y, r)
				else:
					print "Unknown shape kind ", shape_kind
					cvalue = ""

				coords[area] = cvalue
			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])) 
		for compound in compounds.keys():
		#for link in links.keys():
			#print "("+link+")", link_coords[compound], links[compound]
			if links.has_key(compound):
				link_table.write('%s href="%s">\n' % (link_coords[compound], links[compound])) 
		role_coords.close()
		link_table.close()

		#
		# mapstuff needs name_coords.table with the same contents as role_coords.table
		#

		shutil.copyfile(OUT_DIR + mapname + "/role_coords.table",
				OUT_DIR + mapname + "/name_coords.table")
		
		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