File: diff_splice_paths.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 (160 lines) | stat: -rwxr-xr-x 3,623 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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env perl

use strict;
use warnings;

my $usage = "usage: $0 splicePaths_A  splicePaths_B\n\n";

my $fileA = $ARGV[0] or die $usage;
my $fileB = $ARGV[1] or die $usage;


main: {

    my %combosA = &get_combos($fileA);
    my %combosB = &get_combos($fileB);

    my %introns_to_combos;
    &index_combos_by_intron(\%combosA, \%introns_to_combos);
    &index_combos_by_intron(\%combosB, \%introns_to_combos);

    my %seen_intron;

    foreach my $intron (keys %introns_to_combos) {
        
        if ($seen_intron{$intron}) { next; }
                
        my %paths;
        &get_all_connected_paths($intron, \%introns_to_combos, \%seen_intron, \%paths);
        
        

        my @paths_A_not_B;
        my @paths_B_not_A;
        my @paths_both_A_and_B;
        foreach my $path (keys %paths) {
            if ($combosA{$path} && $combosB{$path}) {
                push (@paths_both_A_and_B, $path);
            }
            elsif ($combosA{$path}) {
                push (@paths_A_not_B, $path);
            }
            elsif ($combosB{$path}) {
                push (@paths_B_not_A, $path);
            }
        }


        ## filter out those that are subpaths of others.
        @paths_A_not_B = &remove_subpaths(\@paths_A_not_B, [@paths_B_not_A]);
        @paths_B_not_A = &remove_subpaths(\@paths_B_not_A, [@paths_A_not_B]);
        

        print join("\t", $intron, 
                   scalar(@paths_both_A_and_B),
                   scalar(@paths_A_not_B),
                   scalar(@paths_B_not_A)) . "\n";
    }
    
    
    
    exit(0);
    
}

####
sub remove_subpaths {
    my ($paths_query_aref, $paths_to_examine_as_containing_subpaths_aref) = @_;

    my @ok;

    foreach my $path (@$paths_query_aref) {
       
        my ($chr, $rest_path) = split(/:/, $path);

        my $found_as_subpath = 0;

        foreach my $other_path (@$paths_to_examine_as_containing_subpaths_aref) {

            if ($other_path =~ /$rest_path/) {
                $found_as_subpath = 1;
                last;
            }
        }
        if (! $found_as_subpath) {
            push (@ok, $path);
        }
    }

    return(@ok);
}


####
sub get_combos {
    my ($file) = @_;

    my %combos;

    open (my $fh, $file) or die $!;
    while (<$fh>) {
        chomp;
        
        my @x = split(/\t/);
        
        if ($x[0] =~ /COMBO/) { 
            $combos{$x[1]} = 1;
        }

    }

    close $fh;

    return(%combos);
}


####
sub index_combos_by_intron {
    my ($combos_href, $introns_to_combos_href) = @_;
    
    foreach my $combo (keys %$combos_href) {
        my @introns = &get_introns_from_path($combo);        
        foreach my $intron (@introns) {
            push (@{$introns_to_combos_href->{$intron}}, $combo);
        }
    }
    
    return;
}


sub get_introns_from_path {
    my ($path) = @_;
    my ($chr, @introns) = split(/_+/, $path);
        
    foreach my $intron (@introns) {
        $intron = "$chr$intron";
    }
    return(@introns);
}


sub get_all_connected_paths {
    my ($intron, $introns_to_combos_href, $seen_href, $paths_href) = @_;
    
    my @paths = @{$introns_to_combos_href->{$intron}};
    $seen_href->{$intron} = 1;
    foreach my $path (@paths) {
        if (! exists $paths_href->{$path}) {
            $paths_href->{$path} = 1;
            my @introns = &get_introns_from_path($path);
            foreach my $intron (@introns) {
                if ($seen_href->{$intron}) { next; }
                &get_all_connected_paths($intron, $introns_to_combos_href, $seen_href, $paths_href);
            }
        }
    }

    return;
}