File: get_tissue_enriched_DE_one_vs_all.pl

package info (click to toggle)
trinityrnaseq 2.2.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 212,452 kB
  • ctags: 5,067
  • sloc: perl: 45,552; cpp: 19,678; java: 11,865; sh: 1,485; makefile: 613; ansic: 427; python: 313; xml: 83
file content (69 lines) | stat: -rwxr-xr-x 1,861 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env perl

use strict;
use warnings;

my $usage = "usage: $0 MAX_FDR MIN_FC\n\n"
    . " \n\tRun this in the edgeR results directory.\n\n";

my $MAX_FDR = $ARGV[0] or die $usage;
my $MIN_FC = $ARGV[1] or die $usage;

my $MIN_LOGFC = log($MIN_FC)/log(2);

main: {

    my @DE_files = <*.DE_results>;
    
    my %sample_to_comparison_count;
    my %sample_to_DE_genes;
    
    foreach my $DE_file (@DE_files) {
        
        $DE_file =~ /\.([^\.]+)_vs_([^\.]+)/ or die "Error, cannot extract sample names from filename: $DE_file";
        
        my $sample_A = $1;
        my $sample_B = $2;
        
        $sample_to_comparison_count{$sample_A}++;
        $sample_to_comparison_count{$sample_B}++;
        
        open (my $fh, $DE_file) or die "Error, cannot open file $DE_file";
        my $header = <$fh>;
        while (<$fh>) {
            chomp;
            my @x = split(/\t/);
            my $logFC = $x[1];
            my $FDR = $x[4];
            
            unless ($FDR <= $MAX_FDR && abs($logFC) >= $MIN_LOGFC) { next; }
            
            my $gene = $x[0];
            
            if ($logFC < 0) {
                $sample_to_DE_genes{$sample_A}->{$gene}++;
            }
            else {
                $sample_to_DE_genes{$sample_B}->{$gene}++;
            }
        }
        close $fh;
        
    }
    
    foreach my $sample (keys %sample_to_DE_genes) {
        foreach my $gene (keys %{$sample_to_DE_genes{$sample}}) {

            my $count_DE_induced = $sample_to_DE_genes{$sample}->{$gene};
            
            my $num_sample_comparisons = $sample_to_comparison_count{$sample};
            if ($count_DE_induced == $num_sample_comparisons) {
                ## DE and induced in each comparison
                
                print "$gene\t$sample\n";
            }
        }
    }

    exit(0);
}