-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy path6_Get_Expression_featureCounts.pl
68 lines (61 loc) · 1.43 KB
/
6_Get_Expression_featureCounts.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
use strict;
use warnings;
if (@ARGV < 1) {die "Please provide directory of featurecounts output\n";}
my $dir = $ARGV[0];
my %Gene2ID2FragCount = ();
my @IDs = ();
foreach my $file (glob("$dir/*.fragmentcounts")) {
my $ID = "ERR";
if ($file =~ /([ATCG]{5,})A/) {
# if ($file =~ /_([^_]+_Cell\d\d)/) {
$ID = $1;
} else {
die "$file does not match\n";
}
push(@IDs,$ID);
open(my $ifh, $file) or die $!;
while (<$ifh>) {
chomp;
if ($_ =~ /^#/ || $_ =~ /^Geneid/) {next;} #skip header & comments
my @record=split(/\t/);
my $gene = $record[0]; $gene =~ s/\s+//g;
$Gene2ID2FragCount{$gene}->{$ID} = $record[6];
} close ($ifh);
}
print join("\t",@IDs)."\n";
foreach my $gene (keys(%Gene2ID2FragCount)) {
print "$gene";
foreach my $ID (@IDs) {
my $count = "NA";
if (exists($Gene2ID2FragCount{$gene}->{$ID})) {
$count = $Gene2ID2FragCount{$gene}->{$ID};
} else {
$count = "0";
}
print "\t".$count;
}
print "\n";
}
my %ID2Unassigned = ();
foreach my $file (glob("$dir/*.fragmentcounts.summary")) {
my $ID = "ERR";
#if ($file =~ /_([^_]+_Cell\d\d)/) {
if ($file =~ /([ATCG]{5,})A/) {
$ID = $1;
} else {
die "$file does not match\n";
}
open(my $ifh, $file) or die $!;
<$ifh>; # header
<$ifh>; #Assigned
while (<$ifh>) {
chomp;
my @record=split(/\t/);
$ID2Unassigned{$ID} += $record[1]
} close ($ifh);
}
print "Unassigned_Various";
foreach my $ID (@IDs) {
print "\t".$ID2Unassigned{$ID};
}
print "\n";