]> git.donarmstrong.com Git - rsem.git/blob - rsem-form-counts-matrix
Fixed a bug in perl scripts for printing error messages
[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 $line;
12 my $n = scalar(@ARGV);
13 my $M = -1;
14 my @matrix = ();
15
16 for (my $i = 0; $i < $n; $i++) {
17     my @sample = ();
18     open(INPUT, $ARGV[$i]);
19     while ($line = <INPUT>) {
20         chomp($line); 
21         my @fields = split(/\t/, $line);
22         push(@sample, $fields[1]);
23     }
24     close(INPUT);
25     if (scalar(@sample) == 0) {
26         print STDERR "No transcript is detected! Please check if $ARGV[$i] exists.\n";
27         exit(-1);
28     }
29     if ($M < 0) { $M = scalar(@sample); }
30     elsif ($M != scalar(@sample)) { 
31         print STDERR "Number of transcripts among samples are not equal!\n"; 
32         exit(-1); 
33     }
34     push(@matrix, \@sample);
35 }
36
37 for (my $i = 0; $i < $M; $i++) {
38     for (my $j = 0; $j < $n - 1; $j++) { print "$matrix[$j][$i]\t"; }
39     print "$matrix[$n - 1][$i]\n";
40 }