]> git.donarmstrong.com Git - rsem.git/blob - rsem-prepare-reference
Added user-friendly error messages if users forget to compile the source codes
[rsem.git] / rsem-prepare-reference
1 #!/usr/bin/perl
2
3 use Getopt::Long;
4 use Pod::Usage; 
5 use File::Basename;
6 use strict;
7
8 use rsem_perl_utils;
9
10 my $status;
11
12 my $gtfF = "";
13 my $mappingF = "";
14 my $polyAChoice = 0; # 0, default, pad polyA tails for all isoforms; 1, --no-polyA; 2, --no-polyA-subset
15 my $no_polyA = 0; # for option --no-polyA 
16 my $subsetFile = "";
17 my $polyALen = 125;
18 my $bowtie_path = "";
19 my $no_bowtie = 0;
20 my $no_ntog = 0; 
21 my $quiet = 0;
22 my $help = 0;
23
24 GetOptions("gtf=s" => \$gtfF,
25            "transcript-to-gene-map=s" => \$mappingF,
26            "no-polyA" => \$no_polyA, 
27            "no-polyA-subset=s" => \$subsetFile,
28            "polyA-length=i" => \$polyALen,
29            "bowtie-path=s" => \$bowtie_path,
30            "no-bowtie" => \$no_bowtie,
31            "no-ntog" => \$no_ntog,
32            "q|quiet" => \$quiet,
33            "h|help" => \$help) or pod2usage(-exitval => 2, -verbose => 2);
34
35 pod2usage(-verbose => 2) if ($help == 1);
36 pod2usage(-msg => "Set --no-polyA & --no-polyA-subset at the same time!", -exitval => 2, -verbose => 2) if ($no_polyA == 1 && $subsetFile ne '');
37 pod2usage(-msg => "Invalid number of arguments!", -exitval => 2, -verbose => 2) if (scalar(@ARGV) != 2);
38 pod2usage(-msg => "If bowtie is used, --no-ntog cannot be set!", -exitval => 2, -verbose => 2) if (!$no_bowtie && $no_ntog);
39
40 if ($no_bowtie && $bowtie_path ne "") { print "Warning: If bowtie is not used, no need to set --bowtie-path option!\n"; }
41
42 my $type;
43
44 if ($gtfF ne "") { $type = 0; }
45 else { $type = 1; }
46
47 my @list = split(/,/, $ARGV[0]);
48 my $size = scalar(@list);
49
50 if ($size == 1 && (-d $list[0])) {
51     my $dir = $list[0];
52     @list = (<$dir/*.fa>, <$dir/*.fasta>);
53     $size = scalar(@list);
54 }
55
56 pod2usage(-msg => "reference_fasta_file(s) is empty! Please check if you provide the correct folder name or file suffixes!", -exitval => 2, -verbose => 2) if ($size <= 0);
57
58 if ($no_polyA) { $polyAChoice = 1 }
59 elsif ($subsetFile ne "") { $polyAChoice = 2; }
60
61 if ($bowtie_path ne "") { $bowtie_path .= "/"; }
62
63 my ($fn, $dir, $suf) = fileparse($0); 
64 my $command = "";
65
66 if ($type == 0) {
67     $"=" ";
68     $command = $dir."rsem-extract-reference-transcripts $ARGV[1] $quiet $gtfF";
69     if ($mappingF ne "") { $command .= " 1 $mappingF"; }
70     else { $command .= " 0"; }
71     $command .= " @list";
72     &runCommand($command);
73 }
74 else {
75     $"=" ";
76     $command = $dir."rsem-synthesis-reference-transcripts $ARGV[1] $quiet";
77     if ($mappingF ne "") { $command .= " 1 $mappingF"; }
78     else { $command .= " 0"; } 
79     $command .= " @list";
80     &runCommand($command);
81 }
82
83 $command = $dir."rsem-preref $ARGV[1].transcripts.fa $polyAChoice $ARGV[1] -l $polyALen";
84 if ($polyAChoice == 2) { $command .= " -f $subsetFile"; }
85 if ($no_ntog) { $command .= " --no-ntog"; }
86 if ($quiet) { $command .= " -q"; }
87
88 &runCommand($command);
89
90 if (!$no_bowtie) {
91     $command = $bowtie_path."bowtie-build -f";
92     if ($quiet) { $command .= " -q"; }
93     $command .= " $ARGV[1].idx.fa $ARGV[1]";
94
95     &runCommand($command);
96 }
97
98 __END__
99
100 =head1 NAME
101
102 rsem-prepare-reference
103
104 =head1 SYNOPSIS
105
106 =over
107
108  rsem-prepare-reference [options] reference_fasta_file(s) reference_name
109
110 =back
111
112 =head1 ARGUMENTS
113
114 =over
115
116 =item B<reference_fasta_file(s)>
117
118 Either a comma-separated list of FASTA formatted files OR a directory name. If a directory name is specified, RSEM will read all files with suffix ".fa" or ".fasta" in this directory.  The files should contain either the sequences of transcripts or an entire genome, depending on whether the --gtf option is used.
119
120 =item B<reference name>
121
122 The name of the reference used. RSEM will generate several reference-related files that are prefixed by this name. This name can contain path information (e.g. /ref/mm9).
123
124 =back
125
126 =head1 OPTIONS
127
128 =over 
129
130 =item B<--gtf> <file>
131
132 If this option is on, RSEM assumes that 'reference_fasta_file(s)' contains the sequence of a genome, and will extract transcript reference sequences using the gene annotations specified in <file>, which should be in GTF format.
133
134 If this option is off, RSEM will assume 'reference_fasta_file(s)' contains the reference transcripts. In this case, RSEM assumes that name of each sequence in the FASTA files is its transcript_id. 
135
136 (Default: off)
137
138 =item B<--transcript-to-gene-map> <file>
139
140 Use information from <file> to map from transcript (isoform) ids to gene ids.
141 Each line of <file> should be of the form:
142
143 gene_id transcript_id
144
145 with the two fields separated by a tab character.
146
147 If you are using a GTF file for the "UCSC Genes" gene set from the UCSC Genome Browser, then the "knownIsoforms.txt" file (obtained from the "Downloads" section of the UCSC Genome Browser site) is of this format.
148
149 If this option is off, then the mapping of isoforms to genes depends on whether the --gtf option is specified.  If --gtf is specified, then RSEM uses the "gene_id" and "transcript_id" attributes in the GTF file.  Otherwise, RSEM assumes that each sequence in the reference sequence files is a separate gene.
150
151 (Default: off)
152
153 =item B<--no-polyA>
154
155 Do not add poly(A) tails to the end of reference isoforms. (Default: adding poly(A) tails to all transcripts)
156
157 =item B<--no-polyA-subset> <file>
158
159 Add poly(A) tails to all transcripts except those listed in <file>. <file> is a file containing a list of transcript_ids. (Default: add poly(A) tails to all transcripts. This option cannot be used with '--no-polyA'.)
160
161 =item B<--polyA-length> <int>
162
163 The length of the poly(A) tails to be added. (Default: 125)
164
165 =item B<--bowtie-path> <path>
166
167 The path to the Bowtie executables. (Default: the path to Bowtie executables is assumed to be in the user's PATH environment variable)
168
169 =item B<--no-bowtie>
170
171 Do not build Bowtie indices.  Specify this option if you wish to use an alternative aligner for mapping reads to transcripts.  You should align against the sequences generated in the output file 'reference_name.idx.fa'.  (Default: off)
172
173 =item B<--no-ntog>
174
175 Disable the conversion of 'N' characters to 'G' characters in the reference sequences.  This conversion is normally desired because it allows some aligners (e.g., Bowtie) to align against all positions in the reference.
176 (Default: off)
177
178 =item B<-q/--quiet>
179
180 Suppress the output of logging information. (Default: off)
181
182 =item B<-h/--help>
183
184 Show help information.
185
186 =back
187
188 =head1 DESCRIPTION
189
190 This program extracts/preprocesses the reference sequences and builds Bowtie indices using default parameters.  If an alternative aligner is to be used, then the '--no-bowtie' option should be specified to disable building Bowtie indices. This program is used in conjunction with the 'rsem-calculate-expression' program.
191
192 =head1 OUTPUT
193
194 This program will generate 'reference_name.grp', 'reference_name.ti', 'reference_name.transcripts.fa', 'reference_name.seq', 'reference_name.chrlist' (if '--gtf' is on), 'reference_name.idx.fa', and corresponding Bowtie index files (unless '--no-bowtie' is specified).
195
196 'reference_name.grp', 'reference_name.ti', 'reference_name.seq', 'reference_name.idx.fa', and 'reference_name.chrlist' are used by RSEM internally.
197
198 B<'reference_name.transcripts.fa'> contains the extracted reference transcripts in FASTA format. Poly(A) tails are added unless '--no-polyA' is set.
199
200 =head1 EXAMPLES
201
202 1) Suppose we have mouse RNA-Seq data and want to use the UCSC mm9 version of the mouse genome. We have downloaded the UCSC Genes transcript annotations in GTF format (as mm9.gtf) using the Table Browser and the knownIsoforms.txt file for mm9 from the UCSC Downloads. We also have all chromosome files for mm9 in the directory '/data/mm9'.  We want to put the generated reference files under '/ref' with name 'mouse_125'. We'll add poly(A) tails with length 125. Please note that GTF files generated from UCSC's Table Browser do not contain isoform-gene relationship information.  For the UCSC Genes annotation, this information can be obtained from the knownIsoforms.txt file.  Suppose we want to build Bowtie indices and Bowtie executables are found in '/sw/bowtie'.
203
204 There are two ways to write the command:
205
206  rsem-prepare-reference --gtf mm9.gtf \
207                         --transcript-to-gene-map knownIsoforms.txt \
208                         --bowtie-path /sw/bowtie \                  
209                         /data/mm9/chr1.fa,/data/mm9/chr2.fa,...,/data/mm9/chrM.fa \
210                         /ref/mouse_125
211
212 OR
213
214  rsem-prepare-reference --gtf mm9.gtf \
215                         --transcript-to-gene-map knownIsoforms.txt \
216                         --bowtie-path /sw/bowtie \
217                         /data/mm9 \
218                         /ref/mouse_125
219
220 2) Suppose we only have transcripts from EST tags in 'mm9.fasta'. In addition, we also have isoform-gene information in 'mapping.txt'. We do not want to add any poly(A) tails. The reference_name will be set to 'mouse_0'. In addition, we do not want to build Bowtie indices, and will use an alternative aligner to align reads against the 'mouse_0.idx.fa' output file:
221
222  rsem-prepare-reference --transcript-to-gene-map mapping.txt \
223                         --no-polyA \
224                         --no-bowtie \
225                         mm9.fasta \
226                         mouse_0
227
228 =cut