- 论坛徽章:
- 0
|
本帖最后由 alphafighter 于 2015-11-19 18:15 编辑
- #! /usr/bin/perl
- use strict;
- use warnings;
- # get the mz value and make it easier to use{
- my $dummyfile = "dummy.pepmasses"; #filename defined here
- my @mzco;
- open my $fh, "<" , $dummyfile or die "Unable to open $dummyfile:$!";
- readline $fh;
- while (my $line = <$fh>){
- #read each line in file
- chomp $line;
- my $mz_value = (split/\s+/,$line)[2]; #pick column 2th at everyline
-
- push (@mzco,$mz_value); #add them all in one array @mzco
- }
- open (FILE, ">tmp.data");
- print FILE join("\n",@mzco),"\n";
- close $fh;
- close FILE;
- my $tmpdata = "tmp.data";
- open my $fa, "<", $tmpdata or die "Unable to open $tmpdata:$!";
- my @mvalue = <$fa>;
- my @somvalue = sort { $a <=> $b } @mvalue;
- open (FI,">tmpf.data");
- print FI"@somvalue";
- close FI;
- # }
- my $tmpf = "tmpf.data";
- open my $ff, "<" , $tmpf or die "Unable to open $tmpf:$!";
- my $text = ();
- # get rage and intervals
- print "what range of information do you want to know?\n";
- # sample text : 1000-4000-250-result
- chomp($text = <STDIN>);
- my ($from,$to,$intervals) = split (/\s+/,$text);
- my $whole_pepnumber = 0;
- my $whole_mass = 0;
- my $mass = 0;
- my $bin_pepnumber = 0;
- my $bin_number = 0;
- my $tmp_from = $from;
- my $tmp_to = $tmp_from + $intervals;
- # head line of final result
- print "Bin number\t From\t To\t peptide number\t average m\/z value\n";
- # get the number of bins
- readline $ff;
- while(defined(my $m_z_value = <$ff>)) {
- $m_z_value =~ s/^\s+//;
- GOD:
- chomp $m_z_value;
- if ($tmp_to <= $to and $m_z_value <= $to){
-
- if($m_z_value >> $tmp_to){
- ++$bin_number;
- print "$bin_number\t\t $tmp_from\t $tmp_to\t 0\t\t -\n";
- $tmp_from = $tmp_from + $intervals;
- $tmp_to = $tmp_to + $intervals;
- goto GOD;
- }else{
- if ($m_z_value < $from){
- goto MIRACLE;
- }
- else{
- if($m_z_value == $from){
- $mass = $mass + $m_z_value;
- $whole_mass = $whole_mass +$m_z_value;
- ++$bin_pepnumber;
- ++$whole_pepnumber;
-
- print "$bin_number\t\t $tmp_from\t $tmp_to\t $bin_pepnumber\t\t $mass/$bin_pepnumber\n";
- }
- else{
- if ($m_z_value >= $tmp_from and $m_z_value <= $tmp_to) {
- $mass = $mass + $m_z_value;
- $whole_mass = $whole_mass +$m_z_value;
- ++$bin_pepnumber;
- ++$whole_pepnumber;
- }
- else{
- if ($m_z_value > $tmp_to){
- print "$bin_number\t\t $tmp_from\t $tmp_to\t $bin_pepnumber\t\t $mass/$bin_pepnumber\n";
- ++$bin_number;
- $mass = $m_z_value;
- $whole_mass = $whole_mass + $m_z_value;
- $bin_pepnumber = 0;
- ++$whole_pepnumber;
- $tmp_from = $tmp_from + $intervals;
- $tmp_to = $tmp_to + $intervals;
- goto GOD;
- }
- }
- }
- }
- }
- MIRACLE:
-
- }
- }
- print "The peptide number in the range is $whole_pepnumber\n";
- my $average_mass = $whole_mass / $whole_pepnumber;
- print "The average m\/z value is $whole_mass/$whole_pepnumber";
复制代码 上面的是完整的代码。是有use strict和use warning的。但是源代码在运行中并没有反应任何有关后面的if跟else的部分。
因为不能直接插入图片,所以我把异常的情况更详细地说一下。
100到300范围,区间大小为20的时候。
其他数据都正常,只有240到260是0,而原处理数据中这个部分很明显不是0。经检查,发现,在其他行运行的时候,
if($m_z_value >> $tmp_to){ (这一行是后加的判定)
这一行的>>都是作大于号的,只有运行到240到260的时候,这一行会突然失效,我用了debug,当运行到这个区间的时候,$mz_v_value最小的值为245,最大的为259,$tmp_to为260,明明这个if在这里是false,但是程序就是会执行下面的代码。然后到260到280就会又恢复正常。
然后每次的范围总会漏掉最后一个区间。
我试验了更大的区间,1000到5000,区间大小为50,结果发现,之前那个莫名其妙失效的效果的出现完全没有规律,3,4,12,6,5,3,4,3,4. 前面的是它会出现的大概间隔。
@jason680
|
|