Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #
- # For NMR Peak Assignment using known assignments
- # tries to match picked peaks to assignments based on
- # peak closest distance
- #
- #
- # ./nmrasser.pl <picked peaks> <peak assignments>
- #
- #
- #
- # picked peaks file should be from NMRviewJ
- # Assigned peaks file should be of the format
- # Kind of Ugly but it works
- # Residue #. HN/N Chemicalshift
- #
- # ex.
- # 1. HN 9.3
- # 1. N 120.2
- use Math::Complex;
- my %hn = ();
- my %n = ();
- my %npeaks = ();
- my %hnpeaks = ();
- $x = 0;
- if(!$ARGV[0]){ die "Need your picked peaks to parse!"; }
- if(!$ARGV[1]) { die "Need your peak assignments!"; }
- open(PEAKS, $ARGV[0]);
- open(ASS, $ARGV[1]);
- open(OUTPUT, "$ARGV[0].out");
- if($ARGV[2])
- {open(SEQ, $ARGV[2]);
- @seq = <SEQ>;
- }
- @peaks = <PEAKS>;
- @ass = <ASS>;
- #find 1Hppm and N15 ppm for each peak
- foreach $line (@peaks)
- {
- if($line =~ m/\{\}/)
- {
- @ln = split(/ /, $line);
- $hnpeaks{ $ln[0] } = $ln[2];
- $npeaks{ $ln[0] } = $ln[9];
- #print "$ln[2] : $ln[9] \n";
- }
- # else { print "BALLS\n!"; }
- }
- #Finds location of 1H N15 peaks from assignments
- $a=1;
- foreach $line1 (@ass)
- {
- if($line1 =~ m/\d{1,3}\.N /)
- {
- @nit = split(/\s{1,6}/, $line1);
- #print "$nit[0] $nit[1]\n";
- @stuff = split(/\./, $nit[0]);
- #Assign H peak to a number
- $n{ $stuff[0] } = $nit[1];
- #$n{ $stuff[0] }->{ seq } = substr($seq[0],$a,1);
- $a++;
- }
- if($line1 =~ m/\d{1,3}\.HN /)
- { @hnit = split(/\s{1,7}/, $line1);
- #print "$hnit[0] $hnit[1]\n";
- @stuff1 = split(/\./, $hnit[0]);
- $hn{ $stuff1[0] } = $hnit[1];
- }
- #else { print "CRAP!\n"; }
- }
- #print "assigns: $a\n\n";
- #foreach $key (keys %n) {
- #print "$key $n{ $key } $hn{ $key }\n";
- #}
- foreach $keay (sort keys %npeaks)
- {
- &matcher($keay,0);
- }
- foreach $keyr (keys %npeaks) {
- &removedups($keyr,1);
- }
- foreach $keyr (keys %npeaks) {
- &removedups($keyr,2);
- }
- foreach $keyr (keys %npeaks) {
- &removedups($keyr,3);
- }
- foreach $keyr (keys %npeaks) {
- &removedups1($keyr);
- }
- $x=0;
- foreach $key (sort keys %npeaks) {
- if($npeaks->{$key}->{ winname }->{0} > 0) { $x++; }
- printf("%d N:%f HN:%f : %d N:%f HN:%f ::: %f \n",$key, $npeaks{$key}, $hnpeaks{$key}, $npeaks->{$key}->{ winname }->{0}, $n{$npeaks->{$key}->{ winname }->{0} }, $hn{$npeaks->{$key}->{ winname }->{0}}, $npeaks-> {$key}->{ winner }->{0});
- }
- print "Number matches: $x\n";
- close(OUTPUT);
- close(PEAKS);
- close(ASS);
- #close(SEQ);
- exit;
- sub matcher
- {
- # print "###### $_[0]\n\n\n\n\n\n\n\n";
- $num = $_[0];
- $npeaks->{ $num }->{ winner }->{0} = 1;
- foreach $keym (sort keys %hn )
- {
- #print "$npeaks{ $num } ** $n{ $keym } ** $hnpeaks{ $num } ** $hn{ $keym}\n";
- $rise = abs($npeaks{ $num } - $n{ $keym });
- $run = abs($hnpeaks{ $num } - $hn{ $keym});
- $c = sqrt($rise**2 + $run**2);
- #print "$rise **** $run ***** $c\n\n\n";
- if($npeaks->{ $num }->{ winner }->{0} > $c && $c < 0.25)
- {
- $npeaks->{ $num }->{ winner }->{1} = $npeaks->{ $num }->{ winner }->{0}; $npeaks->{ $num }->{ winname }->{1} = $npeaks->{ $num }->{ winname }->{0};
- $npeaks->{ $num }->{ winner }->{2} = $npeaks->{ $num }->{ winner }->{1}; $npeaks->{ $num }->{ winname }->{2} = $npeaks->{ $num }->{ winname }->{1};
- $npeaks->{ $num }->{ winner }->{3} = $npeaks->{ $num }->{ winner }->{2}; $npeaks->{ $num }->{ winname }->{3} = $npeaks->{ $num }->{ winname }->{2};
- $npeaks->{ $num }->{ winner }->{0} = $c; $npeaks->{ $num }->{ winname }->{0} = $keym;
- }
- #print "$n{$keym} : $hn{$keym}\n";
- }
- #print "$npeaks->{ $num }->{ winname }->{3}\n\n\n";
- }#sub
- sub removedups
- {
- my($keyp,$nt)=@_;
- foreach $key1 (keys %npeaks) {
- if($keyp != $key1 && $npeaks->{ $keyp }->{ winname }->{0} == $npeaks->{ $key1 }->{ winname }->{0})
- {
- if($npeaks->{ $keyp }->{ winner }->{0} > $npeaks->{ $key1 }->{ winner }->{0})
- {
- $npeaks->{ $keyp }->{ winner }->{0} = $npeaks->{ $keyp }->{ winner }->{$nt};
- $npeaks->{ $keyp }->{ winname }->{0} = $npeaks->{ $keyp }->{ winname }->{$nt};
- }
- else {
- $npeaks->{ $key1 }->{ winner }->{0} = $npeaks->{ $key1 }->{ winner }->{$nt};
- $npeaks->{ $key1 }->{ winname }->{0} = $npeaks->{ $key1 }->{ winname }->{$nt};
- #if(removedups1($key1,$nt+1) == -1){ print "POOP\n\n"; return 0;}
- }
- }
- }#foreach
- }#sub
- sub removedups1
- {
- my($keyp) = $_[0];
- my($key1);
- foreach $key1 (keys %npeaks) {
- if($keyp != $key1 && $npeaks->{ $keyp }->{ winname }->{0} == $npeaks->{ $key1 }->{ winname }->{0})
- {
- if($npeaks->{ $keyp }->{ winner }->{0} > $npeaks->{ $key1 }->{ winner }->{0})
- {
- $npeaks->{ $keyp }->{ winner }->{0} = 0;
- $npeaks->{ $keyp }->{ winname }->{0} = 0;
- }
- else {
- $npeaks->{ $key1 }->{ winner }->{0} = 0;
- $npeaks->{ $key1 }->{ winname }->{0} = 0;
- }
- }
- }#foreach
- }#sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement