#!/usr/bin/perl -w
# Create graphs for each individual ORF for GO processes

open(IN, "process_graph_hy.txt");
$graph = <IN>; chomp $graph;
close(IN);

@edge = split /\s+/, $graph;
for $edge (@edge) {
	($parent, $child) = split /->/, $edge;
	$parent{$child} = $parent;
}

open(IN, "process_terms_for_orf_hy.txt");
while (<IN>) {
	chomp;
	($orf, @node) = split;

	# Calculate ORF graph

	%orf_graph = ();
	
	for $node (@node) {
		$temp_node = $node;
		while (defined $parent{$temp_node}) {
			$edge = $parent{$temp_node} . "->" . $temp_node;
			$orf_graph{$edge} = 1;
			$temp_node = $parent{$temp_node};
		}
	}

	@orf_graph = sort(keys %orf_graph);
	print "$orf\t@orf_graph\n";
}
close(IN);
