Hello and thank you,
So I have posted too much here on LQ for Perl problems but you guys are great so here we go anyway.
My problem is that when I print to a file I get results that 'I' don't think should be there. Oboviously the prgram is doing just what it is told but I cannot figure it out. The main code actually comes from another thread
http://www.linuxquestions.org/questi...d.php?t=410918
I have altered it a bit so that it now takes a list makes the $val from the list.
Code:
while (<MS_file>){
chomp;
my ($to_be_peak, $intensity, $FWHM, $res) = split /\t/;
if ($intensity >= $min){
$_=$to_be_peak;
s/(\d+)\.\d+/$1/; # removes the dps
$peak=$_;
#$peak = $to_be_peak;
push(@peak_list, $peak);
}
}
print MS_out "These results are from : $file\n";
print MS_out "These are the selected peaks\n@peak_list\n";
#---------------------------------------
#the value we want to start with - putting $peak_arrary into $val - and then printing it
for (my $d=0; $d<= @peak_list; $d++){
$diff_peak[$d]=$peak_list[$d]-$peak_list[$d+1];
}
print "Diff_peak after @diff_peak\n";
for (my $j=0; $j<= @diff_peak;$j++){
$val=$diff_peak[$j];
# $val = 89; #test
print "This is val $val\n"; # test value
&find_molecules($val, 0, \%a_result, $accuracy); # start function with new val
#to print the results on your screen
foreach my $rh_result(@list_of_results){
foreach(keys %{$rh_result}){
print MS_out ($_, "\t", $rh_result->{$_}, "\n");
}
print MS_out "*******************\n";
}
print MS_out "_________________End_of_Result_________________\n";
foreach my $rh_result (@list_of_results){
foreach (keys %{$rh_result}){
$rh_result->{$_}=0;
}
}
}
print MS_out "/\/\/\ \n";
#--------------------------------------
#Now find the difference and find possiblitiess
sub find_molecules{
my ($current_val, $current_index, $rh_result, $acc)= @_;
#we go through all the element_masses, which weren't below equal or below zero before
for(my $i=$current_index; $i<=$#element_masses; $i++){
#if the current_val is equal the current element_mass
if(!($current_val-$element_masses[$i])){
#we add the result to the list_of_results
my %a_result= %{$rh_result};
$a_result{$element_masses[$i]}++;
push @list_of_results, \%a_result;
#if the difference is greater than zero, we keep on going
}elsif($current_val-$element_masses[$i] >= $acc){
my %a_result= %{$rh_result};
#we add the current element_mass to the result hash
$a_result{$element_masses[$i]}++;
#and call ourselves with the new parameters..
&find_molecules($current_val-$element_masses[$i], $i, \%a_result, $acc);
}
}
}
So the file print out looks like this (Wow this is going to be long sorry
)
Code:
These results are from : Proline.txt
These are the selected peaks
117 116 71 70
1 1
16 0 # Normal!
12 0
14 0
*******************
_________________End_of_Result_________________
1 1
16 0 # Why does it do this?
12 0
14 0
*******************
1 1
16 2
12 1
14 0
*******************
1 13
16 2
12 0
14 0
*******************
1 1
16 1
12 0
14 2
*******************
A lot more file....
*******************
1 21
16 0
12 2
14 0
*******************
1 33
16 0
12 1
14 0
*******************
1 45
16 0
12 0
14 0
*******************
_________________End_of_Result_________________
1 1
16 0 #Why does it do this?
12 0
14 0
*******************
1 1
16 2
12 1
14 0
*******************
So the file goes on further with more of the mistakes noted in the file.
Cheers,
PB