File: join_mult_hints.pl

package info (click to toggle)
augustus 3.2.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 289,676 kB
  • sloc: cpp: 48,711; perl: 13,339; ansic: 1,251; makefile: 859; sh: 58
file content (52 lines) | stat: -rwxr-xr-x 1,229 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl
#
# summarize multiple identical hints to one with mult=n
#
# Mario Stanke, 4.1.2010

use strict;
use Getopt::Long;

my $usage = "$0 -- summarize multiple identical hints to one with mult=n\n";
$usage .= "\n";
$usage .= "Usage: $0 <in.psl >joined.psl\n";
$usage .= "  PREREQUISITE: input GFF file must be sorted so that hints that should be summarized are below each other\n";
$usage .= "  e.g. do a cat hints.gff | sort -n -k 4,4 | sort -s -n -k 5,5 | sort -s -k 3,3 | sort -s -k 1,1 | join_mult_hints.pl\n";


my $help=0;
GetOptions('help!'=>\$help);
if ($help) {
    print "$usage";
    exit(0);       
}

my @f;
my @lf;
my ($lm,$m);

while (<>) {
    @f = split(/\t/,$_);
    if (!(@lf)){
	@lf = @f;	
    } elsif (!(($f[0] eq $lf[0]) && ($f[2] eq $lf[2]) && ($f[3] == $lf[3]) && ($f[4] == $lf[4])  && ($f[6] eq $lf[6]) && ($f[7] eq $lf[7]))){
	print join("\t",@lf);
	@lf = @f;
    } else {
	# update lf by adding f to it
	$lf[8] =~ s/gro?u?p=[^;]*;//;
	if ($lf[8] =~ /mult=(\d+);/){
	    $lm = $1;
	    $lf[8] =~ s/mult=\d+;//;
	} else {
	    $lm = 1;
	}
	if ($f[8] =~ /mult=(\d+);/){
	    $m = $1;
	} else {
	    $m = 1;
	}
	$lf[8] = "mult=" . ($lm+$m) . ";" . $lf[8];
    }
}
print join("\t",@lf) if (@lf);