"Fossies" - the Fresh Open Source Software Archive

Member "augustus-3.3.3/scripts/weedMaf.pl" (13 Sep 2019, 1606 Bytes) of package /linux/misc/augustus-3.3.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "weedMaf.pl" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.3.2_vs_3.3.3.

    1 #!/usr/bin/env perl
    2 #
    3 # weedMaf remove only-gap columns from a multiple alignment in MAF format
    4 #
    5 # input file format:
    6 # 
    7 # a score=5037
    8 # s chlamy4.chromosome10    5424 36280 + 6579462 ATCA-CCACAG--ACC...
    9 # s    volvox.scaffold_9 2188403 51128 + 9999999 ACCA-CCACGGGCACC...
   10 # 
   11 #
   12 # 10.03.2013, Mario Stanke, mario.stanke@uni-greifswald.de
   13 
   14 use strict;
   15 use Getopt::Long;
   16 
   17 my @alirows;         # array of all alignment rows (including gaps)
   18 my @alidata;           # array of everying up to alignment rows
   19 
   20 my $help = 0;
   21 my $len;
   22 
   23 GetOptions('help!'=>\$help);
   24 
   25 exec("perldoc $0") if ($help);
   26 
   27 while (<>) {
   28     if (!/^s\s/){
   29     my $line = $_;
   30     if (@alirows){
   31         weed();
   32         @alidata = @alirows = ();
   33     }
   34     print $line;
   35     } elsif (/(^s\s.*\s)(\S+)$/){
   36     push @alidata, $1;
   37     push @alirows, $2;
   38     }
   39 }
   40 
   41 if (@alirows){
   42     weed();
   43 }
   44 
   45 sub weed{
   46     $len = length($alirows[0]);
   47     my $k = @alirows;
   48     my @newalirows = ();
   49     foreach my $alirow (@alirows){
   50     if (length($alirow) != $len){
   51         die ("Inconsistent alignment lengths");
   52     }
   53     push @newalirows, "";
   54     }
   55     for (my $i=0; $i<$len; $i++){
   56     my $onlygaps = 1;
   57     for (my $j=0; $j<@alirows && $onlygaps; $j++){
   58         if (substr($alirows[$j], $i, 1) ne '-'){
   59         $onlygaps = 0;
   60         }
   61     }
   62     if (!$onlygaps){
   63         for (my $j=0; $j<@alirows; $j++){
   64         $newalirows[$j] .= substr($alirows[$j], $i, 1);
   65         }
   66     }
   67     }
   68     for (my $j=0; $j<@alirows; $j++){
   69     print $alidata[$j] . $newalirows[$j] . "\n";
   70     }
   71     
   72 }
   73 
   74 
   75 __END__
   76 
   77 =head1 NAME
   78 
   79 weedMaf.pl remove only-gap columns from a multiple alignment in MAF format
   80 
   81 =head1 SYNOPSIS
   82 
   83 weedMaf.pl < in.maf > out.maf
   84 
   85 =cut