NMRsucks has asked for the wisdom of the Perl Monks concerning the following question:
it works for the top example but not the bottom and I dont know why. ie we're comparing the combinations of f\2HA and 2HB1, 2HA and 2HG etc. The first example deletes the line with 7 in it as it should, while the second example deletes all the lines with twos even though they are valid. Here is the script!# 23 ! 3 1 ! 9 10 37 ! 11 assign ( (resid 2 and name HB1) or (resid 2 and name HG) or (resid 7 and name HG11) ) ( (resid 2 and name HN) ) 0.0 1.8 3.00 ! 24 !# 25 ! 3 2 ! 9 10 37 ! 7 30 assign ( (resid 2 and name HB1) or (resid 2 and name HG) or (resid 7 and name HG11) ) ( (resid 2 and name HA) or (resid 6 and name HA) ) 0.0 1.8 4.07 ! 26
#!/usr/bin/perl $katfile = "/remote/belgarath/tpukala/pegasus/xplor/signif/25jun2.kat2 +" ; $outfile = "temp.kat"; open(OUTFILE, ">$outfile") or die "Can't open $outfile"; open(KATFILE, "$katfile") or die "Can't open $katfile"; @array = <KATFILE>; chomp @array; $numelements = @array; @arraylist=(0 .. $numelements); foreach $el (@arraylist) { if ($array[$el] =~ /^\)$/ && $array[$el+1] =~ /^\($/) { print(OUTFILE ")\n*\n*\n*\n*\n*\n*\n*\n") } elsif ($array[$el] =~ /assign/ && $array[$el+1] =~ /^\($/) { print(OUTFILE "assign\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n" +) } else { print(OUTFILE "$array[$el]\n"); } } close(KATFILE); close(OUTFILE); $distfile = "/remote/belgarath/tpukala/pegasus/xplor/signif/25jun/rnk_ +2 5jun_signif_.dst"; $katfile = "/remote/belgarath/tpukala/pegasus/xplor/signif/temp.kat"; $outfile = "temp2.kat"; open(OUTFILE, ">$outfile") or die "Can't open $outfile"; open(KATFILE, "$katfile") or die "Can't open $katfile"; @array2 = <KATFILE>; chomp @array2; $numelements2 = @array2; @arraylist2=(0 .. $numelements2); #************************** #************************** foreach $el (@arraylist2) { #************************** if ($array2[$el+10] =~ /resid (\d+) and name (H\w+\d*).?\)/ && $array2[$el] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $resid = $1; $atomid = $2; if ($array2[$el+10] =~ /resid (\d+) and name (H\w+\d*) +. ?\)/) { $residmatch = $1; $atomidmatch = $2; } open(DISTFILE, "$distfile") or die "Can't open $distfi +l e"; while (<DISTFILE>) { $line=$_; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } elsif($array2[$el+11] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+12] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+13] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+14] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+15] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } }} } #************************* elsif ($array2[$el+11] =~ /resid (\d+) and name (H\w+\d*).?\)/ && $array2[$el] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $resid = $1; $atomid = $2; if ($array2[$el+11] =~ /resid (\d+) and name (H\w+\d*) +. ?\)/) { $residmatch = $1; $atomidmatch = $2; } open(DISTFILE, "$distfile") or die "Can't open $distfi +l e"; while (<DISTFILE>) { $line=$_; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } elsif($array2[$el+12] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+13] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+14] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+15] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+16] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } }} } #************************* elsif ($array2[$el+12] =~ /resid (\d+) and name (H\w+\d*).?\)/ && $array2[$el] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $resid = $1; $atomid = $2; if ($array2[$el+12] =~ /resid (\d+) and name (H\w+\d*) +. ?\)/) { $residmatch = $1; $atomidmatch = $2; } open(DISTFILE, "$distfile") or die "Can't open $distfi +l e"; while (<DISTFILE>) { $line=$_; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } elsif($array2[$el+13] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+14] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+15] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+16] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+17] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } }} } #************************* elsif ($array2[$el+13] =~ /resid (\d+) and name (H\w+\d*).?\)/ && $array2[$el] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $resid = $1; $atomid = $2; if ($array2[$el+13] =~ /resid (\d+) and name (H\w+\d*) +. ?\)/) { $residmatch = $1; $atomidmatch = $2; } open(DISTFILE, "$distfile") or die "Can't open $distfi +l e"; while (<DISTFILE>) { $line=$_; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } elsif($array2[$el+14] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+15] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+16] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+17] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+18] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } }} } #************************* elsif ($array2[$el+14] =~ /resid (\d+) and name (H\w+\d*).?\)/ && $array2[$el] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $resid = $1; $atomid = $2; if ($array2[$el+14] =~ /resid (\d+) and name (H\w+\d*) +. ?\)/) { $residmatch = $1; $atomidmatch = $2; } open(DISTFILE, "$distfile") or die "Can't open $distfi +l e"; while (<DISTFILE>) { $line=$_; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } elsif($array2[$el+15] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+16] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+17] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+18] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+19] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } }} } #************************* elsif ($array2[$el+15] =~ /resid (\d+) and name (H\w+\d*).?\)/ && $array2[$el] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $resid = $1; $atomid = $2; if ($array2[$el+15] =~ /resid (\d+) and name (H\w+\d*) +. ?\)/) { $residmatch = $1; $atomidmatch = $2; } open(DISTFILE, "$distfile") or die "Can't open $distfi +l e"; while (<DISTFILE>) { $line=$_; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } elsif($array2[$el+16] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+17] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+18] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+19] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+20] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } }} } #************************* else { print(OUTFILE "$array2[$el]\n"); } } close(KATFILE); close(OUTFILE); #*************************** #*************************** $katfile = "/remote/belgarath/tpukala/pegasus/xplor/signif/temp2.kat"; $outfile = "half.kat"; open(OUTFILE, ">$outfile") or die "Can't open $outfile"; open(KATFILE, "$katfile") or die "Can't open $katfile"; @array3 = <KATFILE>; chomp @array3; $numelements3 = @array3; @arraylist3=(0 .. $numelements3); foreach $el (@arraylist3) { if($array3[$el] =~ /^\*$/) { } elsif($array3[$el] eq $array3[$el+1]) { } else { print(OUTFILE "$array3[$el]\n"); } } #end
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: nmr comparison script
by graff (Chancellor) on Jul 21, 2004 at 05:29 UTC | |
|
Re: nmr comparison script
by edan (Curate) on Jul 21, 2004 at 07:55 UTC | |
|
Re: nmr comparison script
by FoxtrotUniform (Prior) on Jul 21, 2004 at 02:47 UTC | |
|
Re: nmr comparison script
by BrowserUk (Patriarch) on Jul 21, 2004 at 15:53 UTC | |
by graff (Chancellor) on Jul 22, 2004 at 03:03 UTC | |
by BrowserUk (Patriarch) on Jul 22, 2004 at 03:26 UTC |