#programme for parsing Heinz result set to cytoscape understandable format

use strict;
use warnings;


my $inputNodes = 'file9_example2_nodefile_heinz.0.hnz';
my $inputEdges = 'file7_example2_edgefile_heinz.0.hnz';
my $outputNodeScores = 'NodeScores.noa';
my $outputProteinList = 'ProteinList.txt';
my $outputEdgeScores = 'EdgeScores.eda';

open(INPUTNODES, "<$inputNodes") || die "cant open file $inputNodes";
open(INPUTEDGES, "<$inputEdges") || die "cant open file $inputEdges";
open(OUTPUTNODESCORES, ">$outputNodeScores") || die "cant write to file $outputNodeScores";
open(OUTPUTPROTEINLIST, ">$outputProteinList") || die "cant write to file $outputProteinList";
open(OUTPUTEDGESCORES, ">$outputEdgeScores") || die "cant write to file $outputEdgeScores";

print(OUTPUTNODESCORES "nodescores\n");
print(OUTPUTEDGESCORES "edgescores\n");

while(my $line = <INPUTNODES>)
{
	my $gene_id;
	my $value;
	if ($line=~/^(\d+)\tNaN/)
	{	
		#print(OUTPUTPROTEINLIST $1);
	}
	elsif ($line=~/^(\d+)\t([-|\d+].*$)/)
	{
		$gene_id = $1;
		$value = $2;
		print(OUTPUTNODESCORES "$gene_id = $value\n");
		print(OUTPUTPROTEINLIST $gene_id . "\n");
	}
}

while(my $line = <INPUTEDGES>)
{
	my $gene_id1;
	my $gene_id2;
	my $value;
	
	if ($line=~/^\d+\t\d+\tNaN/ || $line=~/^#.*/)
	{	
		#print(OUTPUTPROTEINLIST $1);
	}
	elsif ($line=~/^(\d+)\t(\d+)\t([-|\d+].*)$/)
	{
		$gene_id1 = $1;
		$gene_id2 = $2;
		$value = $3;
		
		print(OUTPUTEDGESCORES "$gene_id1 (ih) $gene_id2 = $value\n");
	}
}

close(INPUTNODES) || die "cant close file $inputNodes";
close(INPUTEDGES) || die "cant close file $inputEdges";
close(OUTPUTNODESCORES) || die "cant close file $outputNodeScores";
close(OUTPUTPROTEINLIST) || die "cant close file $outputProteinList";
close(OUTPUTEDGESCORES) || die "cant close file $outputEdgeScores";

