[Bio] / FigKernelScripts / check_sims_basic.pl Repository:
ViewVC logotype

Diff of /FigKernelScripts/check_sims_basic.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3, Tue Feb 8 21:32:27 2005 UTC revision 1.4, Fri Mar 11 20:52:34 2005 UTC
# Line 5  Line 5 
5  use File::Path;  use File::Path;
6  use File::Basename;  use File::Basename;
7    
8  $usage = "usage: check_sims_basic [-delint_dir=Dir] [-logfile=log] NR [SimsDir | Sims1 Sims2 Sims3 ...] < sims > checked.sims [2> errors (recommended if a logfile isn't specified)]";  $usage = "usage: check_sims_basic [-delint_dir=Dir] [-logfile=log] NR [ < sims | - | SimsDir | Sims1 Sims2 Sims3 ...] > checked.sims [2> errors (recommended if a logfile isn't specified)]";
9    
10  $outdir  = "";  $outdir  = "";
11  $logfh   = \*STDERR;  $logfh   = \*STDERR;
# Line 35  Line 35 
35          ++$i;          ++$i;
36      }      }
37      else {      else {
38          print STDERR "Invalid arg $ARGV[$i]";          $trouble = 1;
39            print STDERR "Invalid arg $ARGV[$i]\n";
40          ++$i;          ++$i;
41      }      }
42  }  }
43  die "There were bad args" if ($trouble);  die "aborting due to invalid args" if ($trouble);
44    
45  (($nr = shift @ARGV) && (-s $nr))  (($nr = shift @ARGV) && (-s $nr))
46      || die $usage;      || die $usage;
47    
48  if  (@ARGV == 0) { push @ARGV, "$FIG_Config::data/Sims"; }  if (@ARGV == 0)
49    {
50        if (-t STDIN)
51        {
52            push @ARGV, '-';
53        }
54        else
55        {
56            print STDERR "No arguments given --- checking $FIG_Config::data/Sims by default\n";
57            push @ARGV, "$FIG_Config::data/Sims";
58        }
59    }
60    
61  if ((@ARGV == 1) && (-d $ARGV[0]))  if ((@ARGV == 1) && (-d $ARGV[0]))
62  {  {
63      $sims_dir = shift @ARGV;      $sims_dir = shift @ARGV;
# Line 62  Line 75 
75  }  }
76  die "There were nonexistent input files" if $trouble;  die "There were nonexistent input files" if $trouble;
77    
78  open(NR,"<$nr") || die $usage;  
79    
80  $/ = "\n>";  $/ = "\n>";
81  while (defined($_ = <NR>))  open(NR,"<$nr") || die $usage;
82    print STDERR "Loading lengths from $nr ...\n" if $ENV{FIG_VERBOSE};
83    while (defined($entry = <NR>))
84  {  {
85      chomp;      chomp $entry;
86      if ($_ =~ /^>?(\S+)[^\n]*\n(.*)/s)      if ($entry =~ /^>?(\S+)[^\n]*\n(.*)/s)
87      {      {
88          $id  =  $1;          $id  =  $1;
89          $seq =  $2;          $seq =  $2;
# Line 91  Line 106 
106      $outfh = \*STDOUT;      $outfh = \*STDOUT;
107  }  }
108    
109  while (defined($_ = <>))  foreach $simfile (@ARGV)
110    {
111        print STDERR "Processing $simfile\n" if $ENV{FIG_VERBOSE};
112    
113        open(SIMFILE, "<$simfile") || die "Could not open $simfile";
114        while (defined($sim = <SIMFILE>))
115  {  {
116      chomp;    # $/)          chomp $sim;
117      if ($_ =~ m/^\S+\t\S+\t(\d+|\d+\.\d+)(\t\d+){7}\t(\d+(\.\d*)?e[-+]?\d+|\d+\.\d+)\t(\d\.\d*e[-+]?\d+|\d+\.\d+|\d+)/)  
118            if ($sim =~ m/^\S+\t\S+\t(\d+|\d+\.\d+)(\t\d+){7}\t(\d+(\.\d*)?e[-+]?\d+|\d+\.\d+)\t(\d\.\d*e[-+]?\d+|\d+\.\d+|\d+)/)
119      {      {
120          # print STDERR "$1\t$2\t$3\t$4\t$5\t$6\n";          # print STDERR "$1\t$2\t$3\t$4\t$5\t$6\n";
121          ($id1,$id2,$iden,$ali_ln,$mis,$gaps,$b1,$e1,$b2,$e2,$psc,$bsc,$ln1,$ln2) =          ($id1,$id2,$iden,$ali_ln,$mis,$gaps,$b1,$e1,$b2,$e2,$psc,$bsc,$ln1,$ln2) =
122              split(/\t/,$_);                  split(/\t/,$sim);
123    
124          if ($ln{$id1} && $ln{$id2} && ($ln{$id1} == $ln1) && ($ln{$id2} == $ln2))          if ($ln{$id1} && $ln{$id2} && ($ln{$id1} == $ln1) && ($ln{$id2} == $ln2))
125          {          {
126              print $outfh "$_\n";   #...print valid sims to OUTPUT                  print $outfh "$sim\n";   #...print valid sims to OUTPUT
127          }          }
128          else          else
129          {          {
130              if ($ln{$id1})              if ($ln{$id1})
131              {              {
132                  if ($ln{$id1} != $ln1) { print $logfh "badlen1\t$ARGV, $.:\t$id1\t$ln{$id1}\t$ln1\t$_\n"; }                      if ($ln{$id1} != $ln1) { print $logfh "badlen1\t$ARGV, $.:\t$id1\t$ln{$id1}\t$ln1\t$sim\n"; }
133              }              }
134              else              else
135              {              {
136                  print $logfh "undef1\t$ARGV, $.:\t$id1\t\t\t$_\n";                      print $logfh "undef1\t$ARGV, $.:\t$id1\t\t\t$sim\n";
137              }              }
138    
139              if ($ln{$id2})              if ($ln{$id2})
140              {              {
141                  if ($ln{$id2} != $ln2) { print $logfh "badlen2\t$ARGV, $.:\t$id2\t$ln{$id2}\t$ln2\t$_\n"; }                      if ($ln{$id2} != $ln2) { print $logfh "badlen2\t$ARGV, $.:\t$id2\t$ln{$id2}\t$ln2\t$sim\n"; }
142              }              }
143              else              else
144              {              {
145                  print $logfh "undef2\t$ARGV, $.:\t$id2\t\t\t$_\n";                      print $logfh "undef2\t$ARGV, $.:\t$id2\t\t\t$sim\n";
146              }              }
147          }          }
148      }      }
149      else      else
150      {      {
151          print $logfh "INVALID FORMAT\t$ARGV, $.:\t$_\n";              print $logfh "INVALID FORMAT\t$ARGV, $.:\t$sim\n";
     }  
 }  
 continue  
 {  
 #...Suggested by the "Perl Cookbook;" however, Ross does not like  
 # the use of the 'continue' block, so this needs to be re-written...  
   
     if (eof)  
     {  
 #...reset line-number to zero, so that we know which line of which file is bad...  
         close(ARGV) || warn "Could not close $ARGV";  
         print STDERR "Finished processing $ARGV\n\n" if $ENV{FIG_VERBOSE};  
   
         if ($outdir && $ARGV)  
         {  
             $file  = "$outdir/" . basename($ARGV[0]);  
             open(OUTPUT, ">$file") || die "could not write-open $file";  
             print STDERR "Opening $file" if $ENV{FIG_VERBOSE};  
             $outfh = \*OUTPUT;  
152          }          }
153      }      }
154  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3