[Bio] / FluxMapMaker / Rbreaker3 Repository:
ViewVC logotype

View of /FluxMapMaker/Rbreaker3

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (download) (annotate)
Wed Jan 28 19:06:24 2004 UTC (15 years, 8 months ago) by efrank
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +1 -1 lines
who knows at this point

#!/usr/bin/perl
#
# May 19, 2003    mh    add stoichiometry
# July 21 2003		ls		proper arrowheads on bidirectional edges

$unique = 100;

print "digraph PW {\n";
print "size=\"27,15\"\n";
#print "rankdir=\"LR\"\n";
print "node [shape=box, height=0.1]\n";
#print "graph [ratio=0.75]\n";
print "graph [fontsize=10]\n";

while (<STDIN>) {
	chop($_);
	@parts = split('	', $_);
	$key = $parts[0];
	if ($key EQ "X") {
		@multi_node = split(':',$parts[1]);
		foreach $X (@multi_node) {
			$X =~ s/^\s*//;	# remove leading and trailing whitespace
			$X =~ s/\s*$//;
			$species = $X;	# pick off species and label it
			$species =~ s/\(.*//;
			$species_nodeness{$species} = "MULTI_NODE";
			if ($X =~ /.*\((.*)\).*/) {
				$species_color{$species} = $1;
			}
		}
	} elsif ($key EQ "R") {
		$enzyme = $parts[1];
		$enzyme=~ s/^\s*"*\s*//;
		$enzyme=~ s/\s*"*\s*$//;
		$gene = $parts[2];
		$reaction = $parts[3];
		$EC_number = $parts[4];
		$EC_number=~ s/^\s*"*\s*//;
		$EC_number=~ s/\s*"*\s*$//;

		if ($reaction =~ /(.*) *<-> *(.*)/) {
			$direction = 'BOTH';
			$inputs = $1;
			$outputs = $2;
		} elsif ($reaction =~ /(.*) *-> *(.*)/) {
			$direction = 'FORWARD';
			$inputs = $1;
			$outputs = $2;
		} elsif ($reaction =~ /(.*) *<- *(.*)/) {
			$direction = 'BACKWARD';
			$inputs = $1;
			$outputs = $2;
		} else {
			$direction = 'NEITHER';
			$inputs = 'FROM';
			$outputs = 'TO';
		}
	
		#	printf "$direction:\n   $inputs\n   $outputs\n";
	
		@inputs = split('\+', $inputs);
		@outputs = split('\+', $outputs);

		$in_node = "node$unique";
		print "$in_node [label=\"\", style=invis];\n";
		$unique = $unique + 1;
		$out_node = "node$unique";
		print "$out_node [label=\"\", style=invis];\n";
		$unique = $unique + 1;
	
		foreach $term (@inputs) {
			$term =~ s/^\s*//;	# strip leading and trailing blanks
			$term =~ s/\s*$//;
			@bits = split(' ',$term);
			if ($#bits == 0) {
				$stoich = 1;
				$inney = $bits[0];
			} else {
				$stoich = $bits[0];
				$inney = $bits[1];
			}
			$multi_node = 0;
			if (exists $species_nodeness{$inney}) {
				if ($species_nodeness{$inney} EQ "MULTI_NODE") {
					$multi_node = 1;
				}
			}
			$create_new_node = 0;
			if (exists $species_hash{$inney}) {
				if ($multi_node) {
					$create_new_node = 1;
				}
			} else {
				$create_new_node = 1;
			}
			if ($create_new_node) {
				$this_node = "node$unique";
				$species_hash{$inney} = "$this_node";
				$unique = $unique+1;
				if ($multi_node) {
					if (exists $species_color{$inney}) {
						print "$this_node [label = \"$inney\", color=$species_color{$inney}, style=filled];\n";
					} else {
						print "$this_node [label = \"$inney\"];\n";
					}
				} else {
					print "$this_node [label = \"$inney\", color = \"light blue\", style=filled];\n";
				}
			} else {
				$this_node = $species_hash{$inney};
			}
			# Added by Larry: if bidirectional, make first part of edge (inputs --
			# in_node) have an arrowhead at the beginning
			if($direction EQ "BOTH") {
				print "$this_node -> $in_node [dir=\"back\"];\n";
			} else {
				print "$this_node -> $in_node;\n";
			}
		}
	
		print "$in_node -> $out_node [label=\"$EC_number\", URL=\"E\"];\n";

		foreach $term (@outputs) {
			$term =~ s/^\s*//;	# strip leading and trailing blanks
			$term =~ s/\s*$//;
			@bits = split(' ',$term);
			if ($#bits == 0) {
				$stoich = 1;
				$outey = $bits[0];
			} else {
				$stoich = $bits[0];
				$outey = $bits[1];
			}
			$multi_node = 0;
			if (exists $species_nodeness{$outey}) {
				if ($species_nodeness{$outey} EQ "MULTI_NODE") {
					$multi_node = 1;
				}
			}
			$create_new_node = 0;
			if (exists $species_hash{$outey}) {
				if ($multi_node) {
					$create_new_node = 1;
				}
			} else {
				$create_new_node = 1;
			}
			if ($create_new_node) {
				$this_node = "node$unique";
				$species_hash{$outey} = "$this_node";
				$unique = $unique+1;
				if ($multi_node) {
					if (exists $species_color{$outey}) {
						print "$this_node [label = \"$outey\", color=$species_color{$outey}, style=filled];\n";
					} else {
						print "$this_node [label = \"$outey\"];\n";
					}
				} else {
					 print "$this_node [label = \"$outey\", color = \"light blue\", style=filled];\n";
				}
			} else {
				$this_node = $species_hash{$outey};
			}
			print "$out_node -> $this_node;\n";
		}
	}
}

print "}\n";


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3