#!/usr/bin/perl -w package rungpi; use strict; use IO::File; use base 'Exporter'; our @EXPORT = qw/gpisom_extract_results/; use formatAlleleSeq; #~ kohgpi.c -> /home/rodriguez/save/Polymorfind//kohgpi.c #~ lrwxrwxrwx 1 rodriguez GABI 44 oct 24 16:07 kohgpi.dat -> /home/rodriguez/save/Polymorfind//kohgpi.dat #~ lrwxrwxrwx 1 rodriguez GABI 44 oct 24 16:07 kohgpi.log -> /home/rodriguez/save/Polymorfind//kohgpi.log #~ lrwxrwxrwx 1 rodriguez GABI 44 oct 24 16:07 kohgpi.map -> /home/rodriguez/save/Polymorfind//kohgpi.map #~ lrwxrwxrwx 1 rodriguez GABI 44 oct 24 16:07 kohgpi.net -> /home/rodriguez/save/Polymorfind//kohgpi.net #~ lrwxrwxrwx 1 rodriguez GABI 44 oct 24 16:07 kohgpi.nmp -> /home/rodriguez/save/Polymorfind//kohgpi.nmp #~ lrwxrwxrwx 1 rodriguez GABI 44 oct 24 16:07 kohgpi.pmp -> /home/rodriguez/save/Polymorfind//kohgpi.pmp sub gpisom_extract_results($$$$$$){ my ($delta, $workpath, $outpath, $infile, $execommand, $encodingfile) = @_; my ($fh_in,$fh_out,$allele,$name,$line,$basis_name,$gpisom_result_file); my %pos_allele1 = (); # key : initial complete name => positive prediction my %pos_allele2 = (); # key : initial complete name => positive prediction my %und_allele1 = (); # key : initial complete name => undefined prediction my %und_allele2 = (); # key : initial complete name => undefined prediction my $prog="gpi"; my @args = (); my ($seqname,$outfile); # get the names of the parameter files my ($command) = $execommand =~ /\/([^\/]+)$/; my ($file) = $infile =~ /\/([^\/]+)$/; # get the base name of the input file to create the ouput file name #~ $outfile = $prog."_output.txt"; # final output file # get the base name of the input file to create the ouput file name ($gpisom_result_file) = $infile =~ /\/([^\/]+)$/; $gpisom_result_file =~ s/\..*/_$prog\_results.res/; $gpisom_result_file = $outpath."/".$gpisom_result_file; # create the symbolic links for the executable to the working directory # otherwise the resulting file cannot be obtained @args = ("ln", "-s", $execommand, "$workpath/."); print "@args\n"; #~ unless (-e "$workpath/$command") {system(@args) == 0 or die "system @args failed: $?"}; unless (-e "$workpath/$command") {`ln -s $execommand* $workpath/.`}; # copy inout file to working directory @args = ("cp", "$infile", "$workpath/."); unless (-e "$workpath/$file") {system(@args) == 0 or die "system @args failed: $?"}; # go to the working directory to run the command chdir "$workpath" or die "cannot change dir rumiptoprot::runmitoprot chdir $workpath : $?"; # get the encoing information my ($h_encodingName,$h_encodingID,$h_name_allele,$h_name_position,$h_name_var_type) = getEncoding($encodingfile); # RUN the program in the working dir # th output file is localized where the command is launched (!?) @args = ("$workpath/$command", "$workpath/$file"); system(@args) == 0 or die "system @args failed: $?"; # get information from the positive predictions $fh_in = new IO::File "$workpath/$file.pos" || die "Can not open file $workpath/$file.pos : $!";#Data $/ = ">"; <$fh_in>; while(<$fh_in>){ ($name) = $_ =~ /([^\s]*)/; if(defined $h_encodingID->{$name}){ #~ if($h_name_var_type->{$name} eq "snp"){ ### ($basis_name,$allele) = $h_encodingID->{$name} =~ /(.*)_(allele\d)$/; if($h_name_allele->{$name} eq "allele1"){ $pos_allele1{$basis_name} = $name; } elsif($h_name_allele->{$name} eq "allele2"){ $pos_allele2{$basis_name} = $name; } else{ print "PB: $name :$h_name_allele->{$name}\n"; exit(12); } #~ } } else{ print "PB rungpi::gpisom_extract_results : $name no encoding\n"; exit(11); } } $fh_in->close(); # get information from the undefined predictions $fh_in = new IO::File "$workpath/$file.und" || die "Can not open file $workpath/$file.und : $!";#Data $/ = ">"; <$fh_in>; while(<$fh_in>){ ($name) = $_ =~ /([^\s]*)/; if(defined $h_encodingID->{$name}){ #~ if($h_name_var_type->{$name} eq "snp"){ ### ($basis_name,$allele) = $h_encodingID->{$name} =~ /(.*)_(allele\d)$/; if($h_name_allele->{$name} eq "allele1"){ $und_allele1{$basis_name} = $name; } elsif($h_name_allele->{$name} eq "allele2"){ $und_allele2{$basis_name} = $name; } else{ print "PB: $name :$h_name_allele->{$name}\n"; exit(12); } #~ } } else{ print "PB rungpi::gpisom_extract_results : $name no encoding\n"; exit(11); } } $fh_in->close(); # print the title my $fh_title = new IO::File ">$outpath/$prog\_title.txt" || die "Can not open $outpath/$prog\_title.txt : $! \n"; print $fh_title ("Sequence Name\tCase\tNote\n"); $fh_title->close(); # Print the results #~ $fh_out = new IO::File ">$outpath/$prog\_results.txt" || die "Can not create the result file ($prog) $outpath/$prog\_results.txt: $! \n"; $fh_out = new IO::File ">$gpisom_result_file" || die "Can not create the result file ($prog) $outpath/$prog\_results.txt: $! \n"; foreach $name (keys %pos_allele1){ if(not defined $pos_allele2{$name} and not defined $und_allele2{$name}){ print $fh_out "$name\tloss\t\n"; } elsif(not defined $pos_allele2{$name} and defined $und_allele2{$name}){ print $fh_out "$name\tloss?\tallele2 undefined\n"; } else{ delete $pos_allele2{$name}; } } foreach $name (keys %pos_allele2){ if(not defined $pos_allele1{$name} and not defined $und_allele1{$name}){ print $fh_out "$name\tgain\t\n"; } elsif(not defined $pos_allele1{$name} and defined $und_allele1{$name}){ print $fh_out "$name\tgain?\tallele1 undefined\n"; } else{ delete $pos_allele2{$name}; } } $fh_out->close(); } #~ #This function copy/paste the db in the foler of GPI-SOM and extracts alls results. #~ sub init($$){ #~ my ($path, $date) = @_; #~ print "GPI-SOM in progress.\n"; #~ #~ #Check the results folder. #~ unless (-e "$path/results/GPI-SOM"){ #~ system("mkdir results/GPI-SOM"); #~ } #~ #~ ##############################Batch of 10 000 lines (5000 seqs) #~ my $list_snps = new IO::File "fic/list_snps_$date" || die "Can not open file fic/list_snps_$date: $!";#Data #~ my $tempgpi = new IO::File ">fic/temp-gpi_$date" || die "Can not create file fic/temp-gpi_$date: $!";#Temporary data (10000 lines) #~ my $i = 0; #~ my $gpipos; #~ my $gpipos2; #~ while(<$list_snps>){ #~ $i++; #~ print $tempgpi $_; #~ if($i >= 10000){ #~ $tempgpi->close(); #~ $i = 0; #~ system("cp fic/temp-gpi_$date $path/Programmes/GPI-SOM/kohgpi-1.5"); #~ chdir "$path/Programmes/GPI-SOM/kohgpi-1.5"; #~ my $res = `./kohgpi temp-gpi_$date`; #~ $gpipos = new IO::File "temp-gpi_$date.pos" || die "Can not open file temp-gpi_$date .pos (results of gpi): $!"; #~ $gpipos2 = new IO::File ">>$path/results/GPI-SOM/gpi-som_$date" || die "Can not create file results/GPI-SOM/gpi-som_$date : $!"; #~ # concatenation in final file #~ while(<$gpipos>){ #~ print $gpipos2 $_; #~ } #~ $gpipos->close(); #~ $gpipos2->close(); #~ chdir "$path"; #~ my $tempgpi = new IO::File ">fic/temp-gpi_$date" || die "Can not create file fic/temp-gpi_$date: $!"; #~ } #~ } #~ #Last file #~ $list_snps->close(); #~ $tempgpi->close(); #~ system("cp fic/temp-gpi_$date $path/Programmes/GPI-SOM/kohgpi-1.5"); #~ chdir "$path/Programmes/GPI-SOM/kohgpi-1.5"; #~ my $res = `./kohgpi temp-gpi_$date`; #~ $gpipos = new IO::File "temp-gpi_$date.pos" || die "Can not open file temp-gpi_$date.pos (results of gpi): $!"; #~ $gpipos2 = new IO::File ">>$path/results/GPI-SOM/gpi-som_$date" || die "Can not create file results/GPI-SOM/gpi-som_$date : $!"; #~ # concatenation in final file #~ if(defined $gpipos){ #~ while(<$gpipos>){ #~ print $gpipos2 $_; #~ } #~ $gpipos->close(); #~ $gpipos2->close(); #~ } #~ ###################################################### #~ #~ #Erase old files (cleaning) #~ system("rm -f temp-gpi_$date.pos"); #~ system("rm -f temp-gpi_$date.png"); #~ system("rm -f temp-gpi_$date.neg"); #~ system("rm -f temp-gpi_$date.und"); #~ system("rm -f temp-gpi_$date.log"); #~ system("rm -f temp-gpi_$date"); #~ chdir "$path"; #~ system("rm -f fic/temp-gpi_$date"); #~ #Function of comparison #~ extract_results($date); #~ } #~ #~ #Extract the name of the sequences who LOST a GPI-signal (only 1 allele in the .pos file) #~ sub extract_results($){ #~ my $date = shift; #~ #~ #Print a last line (indicate the end of file) #~ my $gpipos = new IO::File ">>results/GPI-SOM/gpi-som_$date" || die "Can not open file gpi-som_$date: $!"; #~ print $gpipos ">END_allele"; #~ $gpipos->close(); #~ $gpipos = new IO::File "results/GPI-SOM/gpi-som_$date" || die "Can not open file gpi-som_$date: $!"; #~ #~ # file containing the list of transcript which have undergone a loss or gain of gpi site (allele comparison) #~ my $gpi = new IO::File ">results/programs/gpi-som_$date" || die "Can not open file results/programs/gpi-som_$date: $!"; #~ #~ my $iterator = 1; #~ my $oname; #~ while(<$gpipos>){ #~ if($_ =~ m/>(.*)_allele(\d).*/){ #~ my $name = $1; #~ my $numberallele = $2; #~ if((defined($oname)) && ($oname eq $name)){#If previous name already exist there is no variation. #~ $iterator = 0; #~ } #~ else{ #~ $iterator++; #~ } #~ if((defined($oname)) && ($iterator >= 2)){#If previous name don't exist (second time) this is a variation (only 1 allele is present) #~ print $gpi $oname."_allele"."$numberallele"."\n"; #~ $iterator = 1; #~ } #~ $oname = $name; #~ } #~ } #~ $gpipos->close(); #~ $gpi->close(); #~ } 1;