-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathManipulateIntronFile.pl
71 lines (61 loc) · 1.3 KB
/
ManipulateIntronFile.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
71
#!/usr/bin/env perl
use strict ;
use warnings ;
die "usage: a.pl intronA intronB [op]\n" if (@ARGV == 0 ) ;
my %intronInfo ;
my %chromRank ;
sub sortIntron
{
my @cols1 = split /\s+/, $a ;
my @cols2 = split /\s+/, $b ;
if ( $cols1[0] ne $cols2[0] )
{
$chromRank{ $cols1[0] } cmp $chromRank{ $cols2[0] } ;
}
elsif ( $cols1[1] != $cols2[1] )
{
$cols1[1] <=> $cols2[1] ;
}
else
{
$cols1[2] <=> $cols2[2] ;
}
}
open FP1, $ARGV[0] ;
my $cnt = 0 ;
while ( <FP1> )
{
chomp ;
my $line = $_ ;
my @cols = split /\s+/ ;
push @cols, 1 ;
@{ $intronInfo{ $cols[0]." ".$cols[1]." ".$cols[2] } } = @cols ;
if ( !defined $chromRank{ $cols[0]} )
{
$chromRank{ $cols[0] } = $cnt ;
++$cnt ;
}
}
close FP1 ;
open FP1, $ARGV[1] ;
while ( <FP1> )
{
chomp ;
my $line = $_ ;
my @cols = split /\s+/ ;
my $key = $cols[0]." ".$cols[1]." ".$cols[2] ;
next if ( !defined $intronInfo{ $key } ) ;
my @infoCols = @{ $intronInfo{ $key } } ;
$infoCols[4] = $cols[4] if ( $infoCols[4] ne "+" || $infoCols[4] ne "-" ) ;
$infoCols[9] |= 2 ;
@{ $intronInfo{ $key } } = @infoCols ;
}
close FP1 ;
foreach my $key (sort sortIntron keys %intronInfo )
{
my @infoCols = @{ $intronInfo{ $key } } ;
#print join( " ", @infoCols ), "\n" ;
next if ( $infoCols[9] != 3 ) ;
pop @infoCols ;
print join( " ", @infoCols ), "\n" ;
}