#!/usr/local/bin/perl # camitro2.p # COLUMN STRIPPING PROGRAM # read data file and strip out entries corresponding to useless columns # Report rows in which those entries are nonzero. # Default settings $comments = 0 ; $blank = 0 ; $lastnum = -999 ; $num_lines_same = 0 ; $num_blocks = 0 ; $sep="0"; # replace by preferred separator $skip = 0 ; # number of header lines to drop $strip="17 20 24 25 85 92 103 110 111 135 136" ; eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; $_ = $strip ; @s = split ; $ss = ":".join(":",@s).":" ; print STDERR "read column stripping list of length $#s- $ss\n" ; # Read and write $line = 0 ; $badlinelist = "" ; while ( <> ) { $line ++ ; s/^\s*//; # get rid of initial gap on line s/\n//; # get rid of newline if ( /^\#/ || /^\%/ || ($line<=$skip) ) { $comments ++ ; } else { if("0" eq $sep) { @w=split ; # use default space separator }else{ @w=split($sep, $_) ; } if ( $#w == -1 ) { $blank ++ ; } else { if ( $#w != $lastnum ) { # new block if ( $num_blocks > 0 ) { # report previous block &report () ; } $num_blocks ++ ; $num_lines_same = 0 ; $lastnum = $#w ; if ($autoinputmax) { $inputmax = $lastnum ; } } $num_lines_same ++ ; for ($ii = 0 ;$ii<=$#w; $ii++){ if( $ss =~ /:$ii:/ ) { # skip this col and check the value is zero if (!($w[$ii] eq "0")) { print STDERR "line $line has col $ii = $w[$ii]\n" ; if(!$badline{$line}) { $badline{$line} = 1 ; $badlines ++ ; $badlinelist .= "$line " ; } } } else { print $w[$ii], " " ; } } print "\n" ; } } } if($badlines ) { print STDERR "These lines violated the rules:\n $badlinelist\n" ; } &report () ; if ( $blank + $comments > 0 ) { print STDERR "-----------\n$blank blank lines, $comments comments\n" ; } sub report { $lastnum ++ ; print STDERR "Block $num_blocks: $num_lines_same lines, $lastnum entries\n" ; }