File: join_partitions_within_range.pl

package info (click to toggle)
trinityrnaseq 2.11.0%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 417,528 kB
  • sloc: perl: 48,420; cpp: 17,749; java: 12,695; python: 3,124; sh: 1,030; ansic: 983; makefile: 688; xml: 62
file content (42 lines) | stat: -rwxr-xr-x 704 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env perl

use strict;
use warnings;

my $usage = "usage: $0 partitions.gff join_within_dist\n";

my $partitions_gff = $ARGV[0] or die $usage;
my $join_within_dist = $ARGV[1] or die $usage;

my @prev_line;

open (my $fh, $partitions_gff) or die "Error, cannot open file $partitions_gff";
while (<$fh>) {
	chomp;
	
	my @x = split(/\t/);
	
	if (!@prev_line) {
		@prev_line = @x;
		next;
	}
	
	
	if ($x[0] ne $prev_line[0] 
		|| 
		$x[3] - $prev_line[4] > $join_within_dist) {

		print join("\t", @prev_line) . "\n";
		@prev_line = @x;
	}
	else {
		# same contig and within distance
		$prev_line[4] = $x[4]; # update right end.
	}
}

print join("\t", @prev_line) . "\n" if @prev_line;


exit(0);