#!/usr/bin/perl -w package runnetcglyc; use strict; use base 'Exporter'; our @EXPORT = qw/netcglyc_extract_results/; use IO::File; sub netcglyc_extract_results($$$$){ my ($delta, $netcglyc_result_file, $name_encoding_file, $output_file) = @_; #~ my ($delta, $path, $date) = @_; my $tmpfile = $output_file.".tmp"; print "$tmpfile\n"; #Construct the hash table my $sav = new IO::File $name_encoding_file || die "Can not open $name_encoding_file : $! \n"; my %id;#Hash with all name / id while(<$sav>){ if($_ =~ m/^>(\S*)\s*(.*)/){ $id{$2} .= $1; } } $sav->close(); #Open and extract name, position and score of C manosylation. my $res = new IO::File $netcglyc_result_file || die "Can not open file $netcglyc_result_file : $! \n"; my $tmp = new IO::File ">$tmpfile" || die "Can not create netcglyc temp file $tmpfile: $! \n"; while(<$res>){ if($_ =~ m/^_(\d*)\s*\S*\s*\S*\s*(\d*)\s*(\d*)\s*(\S*)\s*\S*\s*(\S*)/){ print $tmp "$1\t$2\t$4\t$5\n"; } } $tmp->close(); $res->close(); #Find variations $tmp = new IO::File "$tmpfile" || die "Can not open netcglyc temp file $tmpfile: $! \n"; my $netcglyc = new IO::File ">$output_file" || die "Can not create final results of netcglyc $output_file: $! \n"; my %a1; my %a2; my %check; my $allele = ""; my $name = ""; my $c = 2; while(<$tmp>){ my $line = $_; if($line =~ s/^(\d*)/$id{$1}/){#Substitute the ID by his coresponding name if($line =~ m/^(\S*)_allele(\d)\s*(\d*)\s(\S*)\s(\S*)/){ if($2 eq $allele){ if($c == 0){#Same allele1 $allele = $2; if($5 eq "W"){ my $position = $3; my $score = $4; $a1{$position}.=$score; $check{$position}.="1"; } } elsif($c == 1){#Same allele2 $allele = $2; if($5 eq "W"){ my $position = $3; my $score = $4; $a2{$position}.= $score; $check{$position}.="2"; } } } else{ if($c == 0){#Other allele $c++; $allele = $2; if($5 eq "W"){ my $position = $3; my $score = $4; $a2{$position}.=$score; $check{$position}.="2"; } } elsif($c == 1){#Other transcript compare($netcglyc,$delta,\%a1,\%a2,\%check,$name); %a1=(); %a2=(); %check=(); $allele = $2; $name = $1; if($5 eq "W"){ my $position = $3; my $score = $4; $a1{$position}.=$score; $check{$position}.="1"; } $c = 0; } elsif($c == 2){#Initialisation $name = $1; $allele = $2; if($5 eq "W"){ my $position = $3; my $score = $4; $a1{$position}.=$score; $check{$position}.="1"; } $c = 0; } } } } } compare_netcglyc_alleles($netcglyc,$delta,\%a1,\%a2,\%check,$name);#For the last transcript $tmp->close(); $netcglyc->close(); } sub compare_netcglyc_alleles($$$$$$){ my ($netcglyc,$delta,$ref1,$ref2,$ref3,$name) = @_; my %a1=%$ref1; my %a2=%$ref2; my %check=%$ref3; foreach my $k (keys(%check)){ print "ok\n"; my $v = $check{$k}; if($v eq "12"){ my $diffscore = $a1{$k}-$a2{$k}; if($diffscore >= $delta){ print $netcglyc "$name : Signal lost at position $k. Score allele 1 = $a1{$k} - Score allele 2 = $a2{$k}\n"; } elsif($diffscore <= -$delta){ print $netcglyc "$name : Signal gain at position $k. Score allele 1 = $a1{$k} - Score allele 2 = $a2{$k}\n"; } } elsif($v eq "1"){ print $netcglyc "$name : Signal lost at position $k . Score : $a1{$k}\n"; } elsif($v eq "2"){ print $netcglyc "$name : Signal gain at position $k. Score : $a2{$k}\n"; } } } 1;