[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.5 - (download) (as text) (annotate)
Mon Dec 5 18:56:37 2005 UTC (14 years ago) by olson
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, rast_rel_2008_06_18, myrast_rel40, rast_rel_2008_06_16, mgrast_dev_05262011, rast_rel_2008_12_18, mgrast_dev_04082011, rast_rel_2008_07_21, rast_rel_2010_0928, rast_2008_0924, mgrast_version_3_2, mgrast_dev_12152011, rast_rel_2008_04_23, mgrast_dev_06072011, rast_rel_2008_09_30, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, caBIG-05Apr06-00, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, rast_rel_2009_02_05, rast_rel_2011_0119, mgrast_rel_2008_0625, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, rast_rel_2008_10_09, mgrast_dev_04012011, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, rast_rel_2009_07_09, rast_rel_2010_0827, mgrast_rel_2008_1110, myrast_33, rast_rel_2011_0928, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, mgrast_dev_04052011, mgrast_dev_02222011, caBIG-13Feb06-00, rast_rel_2009_03_26, mgrast_dev_10262011, rast_rel_2008_11_24, rast_rel_2008_08_07, HEAD
Changes since 1.4: +17 -0 lines
Add license words.

#
# Copyright (c) 2003-2006 University of Chicago and Fellowship
# for Interpretations of Genomes. All Rights Reserved.
#
# This file is part of the SEED Toolkit.
# 
# The SEED Toolkit is free software. You can redistribute
# it and/or modify it under the terms of the SEED Toolkit
# Public License. 
#
# You should have received a copy of the SEED Toolkit Public License
# along with this program; if not write to the University of Chicago
# at info or the Fellowship for Interpretation of
# Genomes at veronika or download a copy from
# http://www.theseed.org/LICENSE.TXT.
#

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