]> git.donarmstrong.com Git - rsem.git/blob - rsem-plot-transcript-wiggles
Fixed a bug in perl scripts for printing error messages
[rsem.git] / rsem-plot-transcript-wiggles
1 #!/usr/bin/perl
2
3 use Getopt::Long;
4 use Pod::Usage;
5 use File::Basename;
6 use strict;
7
8 my $gene_list = 0; # default is 0, means input is a transcript list; 1 means input is a gene list
9 my $show_unique = 0; # 0, default value, means do not show unique transcript wiggles; 1 means show unique transcript wiggles
10 my $help = 0;
11
12 GetOptions("gene-list" => \$gene_list,
13            "show-unique" => \$show_unique,
14            "h|help" => \$help) or pod2usage(-exitval => 2, -verbose => 2);
15
16 pod2usage(-verbose => 2) if ($help == 1);
17 pod2usage(-msg => "Invalid number of arguments!", -exitval => 2, -verbose => 2) if (scalar(@ARGV) != 3);
18
19 my ($fn, $dir, $suf) = fileparse($0);
20 my $command = "";
21
22 unless (-e "$ARGV[0].transcript.sorted.bam") {
23     $command = $dir."sam/samtools sort $ARGV[0].transcript.bam $ARGV[0].transcript.sorted";
24     &runCommand($command);
25 }
26 unless (-e "$ARGV[0].transcript.readdepth") {
27     $command = $dir."rsem-bam2readdepth $ARGV[0].transcript.sorted.bam $ARGV[0].transcript.readdepth";
28     &runCommand($command);
29 }
30
31 if ($show_unique) {
32     unless (-e "$ARGV[0].uniq.transcript.bam") {
33         $command = $dir."rsem-get-unique $ARGV[0].transcript.bam $ARGV[0].uniq.transcript.bam";
34         &runCommand($command);
35     }
36     unless (-e "$ARGV[0].uniq.transcript.sorted.bam") {
37         $command = $dir."sam/samtools sort $ARGV[0].uniq.transcript.bam $ARGV[0].uniq.transcript.sorted";
38         &runCommand($command);
39     }
40     unless (-e "$ARGV[0].uniq.transcript.readdepth") {
41         $command = $dir."rsem-bam2readdepth $ARGV[0].uniq.transcript.sorted.bam $ARGV[0].uniq.transcript.readdepth";
42         &runCommand($command);
43     }
44 }
45
46 $command = $dir."rsem-gen-transcript-plots $ARGV[0] $ARGV[1] $gene_list $show_unique $ARGV[2]";
47 &runCommand($command);
48
49
50 # command, {err_msg}
51 sub runCommand {
52     print $_[0]."\n";
53     my $status = system($_[0]);
54     if ($status != 0) { 
55         my $errmsg;
56         if (scalar(@_) > 1) { $errmsg = $_[1]; }
57         else { $errmsg = "\"$command\" failed! Plase check if you provide correct parameters/options for the pipeline!"; }
58         print $errmsg."\n";
59         exit(-1);
60     }
61     print "\n";
62 }
63
64 __END__
65
66 =head1 NAME
67
68 rsem-plot-transcript-wiggles
69
70 =head1 SYNOPSIS
71
72 =over
73
74  rsem-plot-transcript-wiggles [options] sample_name input_list output_plot_file
75
76 =back
77
78 =head1 ARGUMENTS
79
80 =over
81
82 =item B<sample_name>
83
84 The name of the sample analyzed.
85
86 =item B<input_list>
87
88 A list of transcript ids or gene ids. But it cannot be a mixture of transcript & gene ids. Each id occupies one line without extra spaces.
89
90 =item B<output_plot_file>
91
92 The file name of the pdf file which contains all plots.
93
94 =back
95
96 =head1 OPTIONS
97
98 =over
99
100 =item B<--gene-list>
101
102 The input-list is a list of gene ids. (Default: off)
103
104 =item B<--show-unique>
105
106 Show the wiggle plots as stacked bar plots. See description section for details. (Default: off)
107
108 =item B<-h/--help>
109
110 Show help information.
111
112 =back
113
114 =head1 DESCRIPTION
115
116 This program generates transcript wiggle plots and outputs them in a pdf file. This program can accept either a list of transcript ids or gene ids (if transcript to gene mapping information is provided) and has two modes of showing wiggle plots. If '--show-unique' is not specified, the wiggle plot for each transcript is a histogram where each position has the expected read depth at this position as its height. If '--show-unique' is specified, for each transcript a stacked bar plot is generated. For each position, the read depth of unique reads, which have only one alignment, is showed in black. The read depth of multi-reads, which align to more than one places, is showed in red on top of the read depth of unique reads.This program will use some files RSEM generated previouslly. So please do not delete/move any file 'rsem-calculate-expression' generated.
117
118 =head1 OUTPUT
119
120 =over
121
122 =item B<output_plot_file>
123
124 This is a pdf file containing all plots generated. If a list of transcript ids is provided, each page display at most 6 plots in 3 rows and 2 columns. If gene ids are provided, each page display a gene. The gene's id is showed at the top and all its transcripts' wiggle plots are showed in this page. The arrangment of plots is determined automatically. For each transcript wiggle plot, the transcript id is displayed as title. x-axis is position in the transcript and y-axis is read depth. 
125
126 =item B<sample_name.transcript.sorted.bam and sample_name.transcript.readdepth>
127
128 If these files do not exist, 'rsem-plot-transcript-wiggles' will automatically generate them.
129
130 =item B<sample_name.uniq.transcript.bam, sample_name.uniq.transcript.sorted.bam and sample_name.uniq.transcript.readdepth>
131
132 If '--show-unique' option is specified and these files do not exist, 'rsem-plot-transcript-wiggles' will automatically generate them. 
133
134 =back
135
136 =head1 EXAMPLES
137
138 Suppose sample_name and output_plot_file are set to 'mmliver_single_quals' and 'output.pdf' respectively. input_list is set to 'transcript_ids.txt' if transcript ids are provided, and is set to 'gene_ids.txt' if gene ids are provided.
139
140 1) Transcript ids are provided and we just want normal wiggle plots:
141
142  rsem-plot-transcript-wiggles mmliver_single_quals transcript_ids.txt output.pdf
143
144 2) Gene ids are provided and we want to show stacked bar plots:
145
146  rsem-plot-transcript-wiggles --gene-list --show-unique mmliver_single_quals gene_ids.txt output.pdf 
147
148 =cut