#!/usr/bin/perl -w package runmitoprot; use strict; use IO::File; use base 'Exporter'; our @EXPORT = qw/runmitoprot extract_mitoprot_results/; # Run MITOPROT sub runmitoprot($$$){ my ($infile,$outpath,$execommand) = @_; my @args = (); # get teh names of the parameter files my ($inputfilename) = $infile =~ /\/([^\/]+)$/; print "$inputfilename\n"; my ($inputname) = $infile =~ /\/([^\/]+)\..*$/; print "$inputname\n"; my ($command) = $execommand =~ /\/([^\/]+)$/; print "$command\n"; # create the symbolic links for the input file to the working directory # otherwise the resulting file cannot be obtained @args = ("ln", "-s", $infile, "$outpath/."); unless (-e "$outpath/$inputfilename") {system(@args) == 0 or die "system @args failed: $?"}; # create the symbolic links for the executable to the working directory # otherwise the resulting file cannot be obtained @args = ("ln", "-s", $execommand, "$outpath/."); unless (-e "$outpath/$command") {system(@args) == 0 or die "system @args failed: $?"}; # RUN the program in the working dir # th output file is localized where the command is launched (!?) @args = ("$outpath/$command", "$outpath/$inputfilename"); system(@args) == 0 or die "system @args failed: $?"; # Placing the output file in the working directory @args = ("mv", "$inputname.mitoprot", "$outpath/."); system(@args) == 0 or die "system @args failed: $?"; return $inputname,"$outpath/$inputname.mitoprot"; } #~ # For each sequence, this function will create a new file : Mitoprot work with only one sequence in one file. #~ # mkdir the output dir in ergatis component before #~ sub format_multifasta_to_singlefastas($$){ #~ #~ my ($inputfile,$outdir) = @_; #~ #~ print "runmitoprot::format_multifasta_to_singlefastas: formats a fasta file containing multiple sequences into 1 sequence per file...\n"; #~ #~ my $listsnps = new IO::File "$inputfile" || die "Can not open file $inputfile : $!";#Data #~ #~ my $i = 1; #~ my $k = 0; #~ while(<$listsnps>){ #~ #~ if($_ =~ /^>(.*)/){ #~ #~ my $id = $1; #~ my $tempmitoprot = new IO::File ">fic/temp-mitoprot_$date" || die "Can not create fic/temp-mitoprot_$date : $! \n"; #~ my $name = $_; #~ print $tempmitoprot $name;#print the name of the SNP #~ $_ = <$listsnps>; #~ if($_ !~ /^M/){#A seq must begin by a M in Mitoprot II #~ print $stderr "$name"; #~ $k++; #~ next; #~ } #~ print $tempmitoprot $_;#Print the sequence of the SNP #~ $tempmitoprot->close(); #~ system("cp fic/temp-mitoprot_$date $path/Programmes/MitoprotII/mitoprotII-v1.101");#Copy file for run Mitoprot #~ chdir "$path/Programmes/MitoprotII/mitoprotII-v1.101"; #~ `./mitoprot temp-mitoprot_$date`; #~ system("rm -f temp-mitoprot_$date");#Clean #~ system("rm -f $path/fic/temp-mitoprot_$date");#Clean #~ extract_results($id,$path,$date); #~ #system("mv tempmitoprot.mitoprot $path/results/MitoprotII/seq$i");#Rename and replace file (optional) #~ $i++; #~ chdir "$path"; #~ } #~ else{ #~ print "Error\n"; #~ } #~ } #~ $listsnps->close(); #~ $stderr->close(); #~ ############################################################# #~ #~ search_var($path,$delta,$date); #~ print "$k errors found. Consult results/error.out.\n"; #~ } #~ #~ sub format_multifasta_to_singlefastas($$){ #~ #~ my ($delta,$path,$datedate) = @_; #~ #~ print "runmitoprot::create: Searching amino acid sequence for each allele...\n"; #~ #~ #Check the fresults folder. #~ print "Running Mitoprot II.\n"; #~ unless (-e "$path/results/MitoprotII"){ #~ system("mkdir results/MitoprotII"); #~ } #~ #~ ############################################Batch #~ my $listsnps = new IO::File "fic/list_snps_$date" || die "Can not open file list_snps_$date : $!";#Data #~ my $stderr = new IO::File ">>results/error_$date" || die "Can not open file results/error_$date : $!";#Errors file #~ print $stderr "\nErrors for Mitoprot: A seq must begin by a M. The folowing sequences are untreated.\n"; #~ my $i = 1; #~ my $k = 0; #~ while(<$listsnps>){ #~ if($_ =~ /^>(.*)/){ #~ my $id = $1; #~ my $tempmitoprot = new IO::File ">fic/temp-mitoprot_$date" || die "Can not create fic/temp-mitoprot_$date : $! \n"; #~ my $name = $_; #~ print $tempmitoprot $name;#print the name of the SNP #~ $_ = <$listsnps>; #~ if($_ !~ /^M/){#A seq must begin by a M in Mitoprot II #~ print $stderr "$name"; #~ $k++; #~ next; #~ } #~ print $tempmitoprot $_;#Print the sequence of the SNP #~ $tempmitoprot->close(); #~ system("cp fic/temp-mitoprot_$date $path/Programmes/MitoprotII/mitoprotII-v1.101");#Copy file for run Mitoprot #~ chdir "$path/Programmes/MitoprotII/mitoprotII-v1.101"; #~ `./mitoprot temp-mitoprot_$date`; #~ system("rm -f temp-mitoprot_$date");#Clean #~ system("rm -f $path/fic/temp-mitoprot_$date");#Clean #~ extract_results($id,$path,$date); #~ #system("mv tempmitoprot.mitoprot $path/results/MitoprotII/seq$i");#Rename and replace file (optional) #~ $i++; #~ chdir "$path"; #~ } #~ else{ #~ print "Error\n"; #~ } #~ } #~ $listsnps->close(); #~ $stderr->close(); #~ ############################################################# #~ #~ search_var($path,$delta,$date); #~ print "$k errors found. Consult results/error.out.\n"; #~ } #Concatenation in /results/MitoprotII/mitoprot print "WARNING: need to put the correct name instead of ID!!!!!\n"; sub extract_mitoprot_results($$$){ my ($path, $resfile, $seqname) = @_; my $score; my $found = 0; my $fh_in = new IO::File $resfile || die "Can not open the output file of mitoprot $resfile : $! \n"; my $fh_out = new IO::File ">>$path/mitoprot_results.txt" || die "Can not create the result file (mitoprot) $path/mitoprot_results.txt: $! \n"; while(<$fh_in>){ if($_ =~ m/^DFM\s*:\s*.*\s*(\d\.\d*)/){#Search a line with DFM (Discriminant function for mitochondrial proteins) $score = $1; } if($_ =~ m/This protein is probably imported in mitochondria./){#Check if the protein is imported to the mitochondria. $found = 1;#$found is true } } if($found == 1){#$found = true => this protein is imported to mitochondria. if(defined($score)){ print $fh_out ">$seqname\timported\n"."$score\n"; } } else{ if(defined($score)){ print $fh_out ">$seqname\tnot imported\n"."$score\n"; } } $fh_in->close(); $fh_out->close(); } #Find the transcript who win/lost mitochondrial signal sub search_var($$$){ my ($path, $delta,$mitoprotresfile) = @_; my $fh_in = new IO::File "$mitoprotresfile" || die "Can not create the result file (mitoprot) $mitoprotresfile: $! \n"; my $results = new IO::File ">$path/mitoprot_results_2.txt" || die "Can not create the file $path/mitoprot_results_2.txt : $! \n"; my $oname; my $allele1; my $allele2; my $found = 0; my $vers = 0; while(<$fh_in>){ if($_ =~ m/>(.*)_allele.*?(imported|not imported)/){ my $type = $2; my $name = $1; if($type eq "imported"){$found++;} else{ if($found == 0){ $vers++; } } $_ = <$fh_in>;#Next line : score. $allele2 = $_; chomp $allele2; if((defined($oname)) && ($oname eq $name)){#If previous name already exist (2 alleles) if($found == 2){#If the 2 alleles are imported my $score = $allele1 - $allele2;#Difference between the 2 alleles if($score >= $delta){ print $results "$oname : Signal lost - scores: allele1=$allele1 allele2=$allele2\n";#Mean : allele 1 have better signal than allele 2 } if($score <= -$delta){ print $results "$oname : Signal gain - scores: allele1=$allele1 allele2=$allele2\n";#Mean : allele 2 have better signal } $found = 0; } elsif($found == 1){#If 1 allele is non imported if($vers == 1){ print $results "$oname : Signal gain \n"; } else{ print $results "$oname : Signal lost \n"; } $vers = 0; $found = 0; } } else{#new name (first allele) $allele1 = $_; chomp $allele1; } $oname = $name; } } $res->close(); $results->close(); } 1;