]> git.donarmstrong.com Git - rsem.git/blob - rsem-form-counts-matrix
changed output format to contain FPKM etc. ; fixed a bug for paired-end reads
[rsem.git] / rsem-form-counts-matrix
1 #!/usr/bin/perl
2
3 use strict;
4
5 if (scalar(@ARGV) == 0) {
6     print "Usage: rsem-form-counts-matrix sampleA.[genes/isoforms].results sampleB.[genes/isoforms].results ... > output_name.counts.matrix\n";
7     print "Results files should be either all .genes.results or all .isoforms.results.\n";
8     exit(-1);
9 }
10
11 my $offsite = 4; # for new file formats
12
13 my $line;
14 my $n = scalar(@ARGV);
15 my $M = -1;
16 my @matrix = ();
17
18 for (my $i = 0; $i < $n; $i++) {
19     my @sample = ();
20     open(INPUT, $ARGV[$i]);
21     while ($line = <INPUT>) {
22         chomp($line); 
23         my @fields = split(/\t/, $line);
24         push(@sample, $fields[$offsite]);
25     }
26     close(INPUT);
27     if (scalar(@sample) == 0) {
28         print STDERR "No transcript is detected! Please check if $ARGV[$i] exists.\n";
29         exit(-1);
30     }
31     if ($M < 0) { $M = scalar(@sample); }
32     elsif ($M != scalar(@sample)) { 
33         print STDERR "Number of transcripts among samples are not equal!\n"; 
34         exit(-1); 
35     }
36     push(@matrix, \@sample);
37 }
38
39 for (my $i = 0; $i < $M; $i++) {
40     for (my $j = 0; $j < $n - 1; $j++) { print "$matrix[$j][$i]\t"; }
41     print "$matrix[$n - 1][$i]\n";
42 }