]> git.donarmstrong.com Git - rsem.git/blobdiff - rsem-plot-transcript-wiggles
Imported Upstream version 1.2.17
[rsem.git] / rsem-plot-transcript-wiggles
index 46a71aaee21ea7abc7d45533db12b93812c7230a..5bd89f2ffecb2d0d55818bd77a8363f71de461c2 100755 (executable)
@@ -1,66 +1,78 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
 
 use Getopt::Long;
 use Pod::Usage;
-use File::Basename;
+
+use FindBin;
+use lib $FindBin::RealBin;
+use rsem_perl_utils;
+
+use Env qw(@PATH);
+@PATH = ($FindBin::RealBin, "$FindBin::RealBin/sam", @PATH);
+
 use strict;
 
-my $gene_list = 0; # default is 0, means input is a transcript list; 1 means input is a gene list
+
+my $gene_list = 0; # default is 0, means input is not a gene list
+my $transcript_list = 0; # default is 0, this option can only be turned on if allele-specific expression is calculated
 my $show_unique = 0; # 0, default value, means do not show unique transcript wiggles; 1 means show unique transcript wiggles
 my $help = 0;
 
 GetOptions("gene-list" => \$gene_list,
+          "transcript-list" => \$transcript_list,
           "show-unique" => \$show_unique,
           "h|help" => \$help) or pod2usage(-exitval => 2, -verbose => 2);
 
 pod2usage(-verbose => 2) if ($help == 1);
 pod2usage(-msg => "Invalid number of arguments!", -exitval => 2, -verbose => 2) if (scalar(@ARGV) != 3);
 
-my ($fn, $dir, $suf) = fileparse($0);
+my $alleleS = 0;
+if (-e "$ARGV[0].alleles.results") { $alleleS = 1; }
+
+pod2usage(-msg => "--transcript-list cannot be set if allele-specific reference is not built!", -exitval => 2, -verbose => 2) if (!$alleleS && $transcript_list);
+pod2usage(-msg => "--gene-list and --transcript-list cannot be set at the same time!", -exitval => 2, -verbose => 2) if ($gene_list && $transcript_list);
+
 my $command = "";
 
 unless (-e "$ARGV[0].transcript.sorted.bam") {
-    $command = $dir."sam/samtools sort $ARGV[0].transcript.bam $ARGV[0].transcript.sorted";
+    $command = "samtools sort $ARGV[0].transcript.bam $ARGV[0].transcript.sorted";
     &runCommand($command);
 }
 unless (-e "$ARGV[0].transcript.readdepth") {
-    $command = $dir."rsem-bam2readdepth $ARGV[0].transcript.sorted.bam $ARGV[0].transcript.readdepth";
+    $command = "rsem-bam2readdepth $ARGV[0].transcript.sorted.bam $ARGV[0].transcript.readdepth";
     &runCommand($command);
 }
 
 if ($show_unique) {
     unless (-e "$ARGV[0].uniq.transcript.bam") {
-       $command = $dir."rsem-get-unique $ARGV[0].transcript.bam $ARGV[0].uniq.transcript.bam";
+       $command = "rsem-get-unique $ARGV[0].transcript.bam $ARGV[0].uniq.transcript.bam";
        &runCommand($command);
     }
     unless (-e "$ARGV[0].uniq.transcript.sorted.bam") {
-       $command = $dir."sam/samtools sort $ARGV[0].uniq.transcript.bam $ARGV[0].uniq.transcript.sorted";
+       $command = "samtools sort $ARGV[0].uniq.transcript.bam $ARGV[0].uniq.transcript.sorted";
        &runCommand($command);
     }
     unless (-e "$ARGV[0].uniq.transcript.readdepth") {
-       $command = $dir."rsem-bam2readdepth $ARGV[0].uniq.transcript.sorted.bam $ARGV[0].uniq.transcript.readdepth";
+       $command = "rsem-bam2readdepth $ARGV[0].uniq.transcript.sorted.bam $ARGV[0].uniq.transcript.readdepth";
        &runCommand($command);
     }
 }
 
-$command = $dir."rsem-gen-transcript-plots $ARGV[0] $ARGV[1] $gene_list $show_unique $ARGV[2]";
-&runCommand($command);
-
+my $id_type;
 
-# command, {err_msg}
-sub runCommand {
-    print $_[0]."\n";
-    my $status = system($_[0]);
-    if ($status != 0) { 
-       my $errmsg;
-       if (scalar(@_) > 1) { $errmsg = $_[1]; }
-       else { $errmsg = "\"$command\" failed! Please check if you provide correct parameters/options for the pipeline!"; }
-       print $errmsg."\n";
-       exit(-1);
-    }
-    print "\n";
+if ($alleleS) {
+    $id_type = 0;
+    if ($transcript_list) { $id_type = 1; }
+    if ($gene_list) { $id_type = 2; }
+} 
+else {
+    $id_type = 1;
+    if ($gene_list) { $id_type = 2; }
 }
 
+$command = "rsem-gen-transcript-plots $ARGV[0] $ARGV[1] $alleleS $id_type $show_unique $ARGV[2]";
+&runCommand($command);
+
 __END__
 
 =head1 NAME
@@ -69,11 +81,7 @@ rsem-plot-transcript-wiggles
 
 =head1 SYNOPSIS
 
-=over
-
- rsem-plot-transcript-wiggles [options] sample_name input_list output_plot_file
-
-=back
+rsem-plot-transcript-wiggles [options] sample_name input_list output_plot_file
 
 =head1 ARGUMENTS
 
@@ -101,6 +109,10 @@ The file name of the pdf file which contains all plots.
 
 The input-list is a list of gene ids. (Default: off)
 
+=item B<--transcript-list>
+
+The input-list is a list of transcript ids. This option can only be turned on if allele-specific expression is calculated. (Default: off)
+
 =item B<--show-unique>
 
 Show the wiggle plots as stacked bar plots. See description section for details. (Default: off)
@@ -113,7 +125,7 @@ Show help information.
 
 =head1 DESCRIPTION
 
-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.
+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. If allele-specific expression is calculated, the basic unit for plotting is an allele-specific transcript and plots can be grouped by either transcript ids (--transcript-list) or gene ids (--gene-list). 
 
 =head1 OUTPUT
 
@@ -121,7 +133,7 @@ This program generates transcript wiggle plots and outputs them in a pdf file. T
 
 =item B<output_plot_file>
 
-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. 
+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. If allele-specific expression is calculated, the basin unit becomes an allele-specific transcript and transcript ids and gene ids can be used to group allele-specific transcripts.
 
 =item B<sample_name.transcript.sorted.bam and sample_name.transcript.readdepth>