-
Notifications
You must be signed in to change notification settings - Fork 5
/
alignments_gff3_to_introns.pl
71 lines (45 loc) · 1.68 KB
/
alignments_gff3_to_introns.pl
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env perl
use strict;
use warnings;
my %match_id_to_seg_list;
my %match_id_to_orient;
my %match_id_to_contig;
while (<STDIN>) {
chomp;
unless (/\w/) { next; }
my @x = split (/\t/);
my ($contig, $lend, $rend, $orient, $info) = ($x[0], $x[3], $x[4], $x[6], $x[8]);
$info =~ /ID=([^;]+)/;
my $match_id = $1 or die "Error, cannot extract match ID from $info";
$match_id = "$contig/$match_id";
$match_id_to_contig{$match_id} = $contig;
$match_id_to_orient{$match_id} = $orient;
my $segment_list_aref = $match_id_to_seg_list{$match_id};
unless (ref $segment_list_aref) {
$segment_list_aref = $match_id_to_seg_list{$match_id} = [];
}
push (@$segment_list_aref, [$lend, $rend]);
}
foreach my $match_id (keys %match_id_to_seg_list) {
my $seg_list_aref = $match_id_to_seg_list{$match_id};
my $num_segments = scalar (@$seg_list_aref);
# print "match_id: $match_id, $num_segments\n";
if ($num_segments == 1) {
# no candidate introns.
next;
}
my $orient = $match_id_to_orient{$match_id};
my $contig = $match_id_to_contig{$match_id};
my @segments = @$seg_list_aref;
@segments = sort {$a->[0]<=>$b->[0]} @segments;
my $prev_segment = shift @segments;
while (@segments) {
my $next_segment = shift @segments;
my ($prev_lend, $prev_rend) = @$prev_segment;
my ($next_lend, $next_rend) = @$next_segment;
my ($intron_lend, $intron_rend) = ($prev_rend + 1, $next_lend - 1);
print "${contig}_${intron_lend}_${intron_rend}_[$orient]\n";
$prev_segment = $next_segment;
}
}
exit(0);