annotate PsiCLASS-1.0.2/ManipulateIntronFile.pl @ 0:903fc43d6227 draft default tip

Uploaded
author lsong10
date Fri, 26 Mar 2021 16:52:45 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
1 #!/usr/bin/env perl
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
2
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
3 use strict ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
4 use warnings ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
5
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
6 die "usage: a.pl intronA intronB [op]\n" if (@ARGV == 0 ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
7
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
8 my %intronInfo ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
9 my %chromRank ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
10
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
11 sub sortIntron
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
12 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
13 my @cols1 = split /\s+/, $a ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
14 my @cols2 = split /\s+/, $b ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
15
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
16 if ( $cols1[0] ne $cols2[0] )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
17 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
18 $chromRank{ $cols1[0] } cmp $chromRank{ $cols2[0] } ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
19 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
20 elsif ( $cols1[1] != $cols2[1] )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
21 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
22 $cols1[1] <=> $cols2[1] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
23 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
24 else
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
25 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
26 $cols1[2] <=> $cols2[2] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
27 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
28 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
29
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
30 open FP1, $ARGV[0] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
31 my $cnt = 0 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
32 while ( <FP1> )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
33 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
34 chomp ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
35 my $line = $_ ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
36 my @cols = split /\s+/ ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
37 push @cols, 1 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
38 @{ $intronInfo{ $cols[0]." ".$cols[1]." ".$cols[2] } } = @cols ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
39 if ( !defined $chromRank{ $cols[0]} )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
40 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
41 $chromRank{ $cols[0] } = $cnt ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
42 ++$cnt ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
43 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
44 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
45 close FP1 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
46
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
47 open FP1, $ARGV[1] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
48 while ( <FP1> )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
49 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
50 chomp ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
51 my $line = $_ ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
52 my @cols = split /\s+/ ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
53 my $key = $cols[0]." ".$cols[1]." ".$cols[2] ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
54 next if ( !defined $intronInfo{ $key } ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
55 my @infoCols = @{ $intronInfo{ $key } } ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
56 $infoCols[4] = $cols[4] if ( $infoCols[4] ne "+" || $infoCols[4] ne "-" ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
57 $infoCols[9] |= 2 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
58
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
59 @{ $intronInfo{ $key } } = @infoCols ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
60 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
61 close FP1 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
62
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
63 foreach my $key (sort sortIntron keys %intronInfo )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
64 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
65 my @infoCols = @{ $intronInfo{ $key } } ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
66 #print join( " ", @infoCols ), "\n" ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
67
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
68 next if ( $infoCols[9] != 3 ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
69 pop @infoCols ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
70 print join( " ", @infoCols ), "\n" ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
71 }