view ACorF/lib/IonFiltration.pm @ 1:26aa3a8f95ce draft

Uploaded
author melpetera
date Wed, 30 Oct 2019 06:54:20 -0400
parents
children
line wrap: on
line source

#!usr/bin/perl
package IonFiltration;

### Perl modules
use strict;
use warnings;






########################################################################
### Création of a hash containing all adduits and fragments possible ###
########################################################################


sub MassCollecting{
	
	my $mass_file = $_[0];
	my %hmass;

	open (F1, $mass_file);
	
	while(my $line = <F1>){
		chomp $line;
		my @tline = split(/[\t;]/, $line);
		if(defined($hmass{$tline[2]})){
			print "The mass difference already exists : $tline[2] !\n";
		}
		$hmass{$tline[1]}{$tline[2]}=$tline[0];
	}
	
	close F1;
	return %hmass;
	
}







########################################################
### Creation of a sif table + correlation filtration ###
########################################################


sub sifTableCreation{
	
	my $file = $_[0];
	my $output_sif = $_[1];
#	my $opt = $_[2];
#	my $rt_threshold = $_[3];
#	my $mass_threshold = $_[4];
	my $correl_threshold = $_[5];
#	my $dataMatrix = $_[6];
#	my $output_tabular = $_[7];
	my $combined_DMVM = $_[8];
#	my $repres_opt = $_[9];
#	my $intensity_threshold = $_[10];
#	my $intensity_pourc = $_[11];
#	my $refhmass = $_[12];
	
	
	
	
	my %hheader_file;
	my %hduplicate;
	
	my %hcorrelgroup;
	my $groupct=1;

	
	my $linenb3=0;
	my %hheader_line;
	my %hrtmz;
	
	open (F5, $combined_DMVM);
	while(my $line = <F5>){
		chomp $line;
		my @tline = split(/\t/, $line);
		
		if($linenb3 == 0){
			for(my $i=0; $i<scalar(@tline);$i++){
				my $a = $tline[$i];
				$hheader_line{$a}=$i;
			}
		}
		else{
			if(defined($hheader_line{mzmed})){
				my $b = $tline[$hheader_line{mzmed}];
				$hrtmz{$tline[0]}{mz}=$b;
			}
			else{
				my $b = $tline[$hheader_line{mz}];
				$hrtmz{$tline[0]}{mz}=$b;
			}
			if(defined($hheader_line{rtmed})){
				my $d = $tline[$hheader_line{rtmed}];
				$hrtmz{$tline[0]}{rt}=$d;
			}
			else{
				my $d = $tline[$hheader_line{rt}];
				$hrtmz{$tline[0]}{rt}=$d;
			}
		}
		
		$linenb3 ++;
	}
	close F5;
	
	
	my $linenb=0;
	
	open (F1, $file) or die "Impossible to open $file\n";
	open(F2, ">$output_sif") or die "Impossible to open $output_sif\n";
	
	
	while(my $line = <F1>){
		chomp $line;
		my @tline = split(/\t/, $line);
		
		###############################
		### Création of a sif table ###
		###############################
		
		if($linenb == 0){
			for(my $i=0; $i<scalar(@tline);$i++){
				my $a = $tline[$i];
				$hheader_file{$i}=$a;
			}
		}
		else{
			for(my $i=1; $i<scalar(@tline);$i++){
				my $a=$tline[0];
				my $b=$hheader_file{$i};
				my $coef=$tline[$i];
								
				if($a eq $b){
	#				print "This is a correlation between A ($a) and A ($b) !\n"
				}
				else{
					
					#########################
					### Remove duplicates ###
					#########################
					
					my $y = $a."/".$b;
					my $z = $b."/".$a;
					
					if((!(defined($hduplicate{$y}))) && (!(defined($hduplicate{$z})))){
						
						$hduplicate{$y}=1;
#						my $abcoef=abs($coef); # Only when you want to consider negative correlations
						
#						if($abcoef > $correl_threshold){ # Only when you want to consider negative correlations
						if($coef > $correl_threshold){
						
							print F2 "$a\t$coef\t$b\n";
							
							my $count=0;
							
						}
					}
				}
			}
		}
		$linenb ++;
	}
	close F1;
	close F2;
	return ($output_sif, %hrtmz);
}			
							
							
							
							

1;