]> git.donarmstrong.com Git - rsem.git/blob - rsem-prepare-reference
Fixed a typo in rsem-calculate-expression's document; Added multi-thread and memory...
[rsem.git] / rsem-prepare-reference
1 #!/usr/bin/perl
2
3 use Getopt::Long;
4 use Pod::Usage; 
5 use FindBin;
6 use lib $FindBin::Bin;
7 use strict;
8
9 use rsem_perl_utils;
10
11 my $status;
12
13 my $gtfF = "";
14 my $mappingF = "";
15 my $polyAChoice = 0; # 0, default, pad polyA tails for all isoforms; 1, --no-polyA; 2, --no-polyA-subset
16 my $no_polyA = 0; # for option --no-polyA 
17 my $subsetFile = "";
18 my $polyALen = 125;
19 my $bowtie_path = "";
20 my $no_bowtie = 0;
21 my $no_ntog = 0; 
22 my $bowtie2 = 0;
23 my $bowtie2_path = "";
24 my $quiet = 0;
25 my $help = 0;
26
27 GetOptions("gtf=s" => \$gtfF,
28            "transcript-to-gene-map=s" => \$mappingF,
29            "no-polyA" => \$no_polyA, 
30            "no-polyA-subset=s" => \$subsetFile,
31            "polyA-length=i" => \$polyALen,
32            "bowtie-path=s" => \$bowtie_path,
33            "no-bowtie" => \$no_bowtie,
34            "no-ntog" => \$no_ntog,
35            "bowtie2" => \$bowtie2,
36            "bowtie2-path=s" => \$bowtie2_path,
37            "q|quiet" => \$quiet,
38            "h|help" => \$help) or pod2usage(-exitval => 2, -verbose => 2);
39
40 pod2usage(-verbose => 2) if ($help == 1);
41 pod2usage(-msg => "Set --no-polyA & --no-polyA-subset at the same time!", -exitval => 2, -verbose => 2) if ($no_polyA == 1 && $subsetFile ne '');
42 pod2usage(-msg => "Invalid number of arguments!", -exitval => 2, -verbose => 2) if (scalar(@ARGV) != 2);
43
44 if ($bowtie2) { $no_bowtie = 1; $no_ntog = 1; }
45
46 pod2usage(-msg => "If bowtie is used, --no-ntog cannot be set!", -exitval => 2, -verbose => 2) if (!$no_bowtie && $no_ntog);
47
48 if ($no_bowtie && ($bowtie_path ne "")) { print "Warning: If bowtie is not used, no need to set --bowtie-path option!\n"; }
49 if (!$bowtie2 && ($bowtie2_path ne "")) { print "Warning: If bowtie2 is not used, no need to set --bowtie2-path option!\n"; }
50  
51 my $type;
52
53 if ($gtfF ne "") { $type = 0; }
54 else { $type = 1; }
55
56 my @list = split(/,/, $ARGV[0]);
57 my $size = scalar(@list);
58
59 if ($size == 1 && (-d $list[0])) {
60     my $dir = $list[0];
61     @list = (<$dir/*.fa>, <$dir/*.fasta>);
62     $size = scalar(@list);
63 }
64
65 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);
66
67 if ($no_polyA) { $polyAChoice = 1 }
68 elsif ($subsetFile ne "") { $polyAChoice = 2; }
69
70 if ($bowtie_path ne "") { $bowtie_path .= "/"; }
71 if ($bowtie2_path ne "") { $bowtie2_path .= "/"; }
72
73 my $dir = "$FindBin::Bin/";
74 my $command = "";
75
76 if ($type == 0) {
77     $"=" ";
78     $command = $dir."rsem-extract-reference-transcripts $ARGV[1] $quiet $gtfF";
79     if ($mappingF ne "") { $command .= " 1 $mappingF"; }
80     else { $command .= " 0"; }
81     $command .= " @list";
82     &runCommand($command);
83 }
84 else {
85     $"=" ";
86     $command = $dir."rsem-synthesis-reference-transcripts $ARGV[1] $quiet";
87     if ($mappingF ne "") { $command .= " 1 $mappingF"; }
88     else { $command .= " 0"; } 
89     $command .= " @list";
90     &runCommand($command);
91 }
92
93 $command = $dir."rsem-preref $ARGV[1].transcripts.fa $polyAChoice $ARGV[1] -l $polyALen";
94 if ($polyAChoice == 2) { $command .= " -f $subsetFile"; }
95 if ($no_ntog) { $command .= " --no-ntog"; }
96 if ($quiet) { $command .= " -q"; }
97
98 &runCommand($command);
99
100 if (!$no_bowtie) {
101     $command = $bowtie_path."bowtie-build -f";
102     if ($quiet) { $command .= " -q"; }
103     $command .= " $ARGV[1].idx.fa $ARGV[1]";
104
105     &runCommand($command);
106 }
107
108 if ($bowtie2) { 
109     $command = $bowtie2_path."bowtie2-build -f";
110     if ($quiet) { $command .= " -q"; }
111     $command .= " $ARGV[1].idx.fa $ARGV[1]";
112     
113     &runCommand($command);
114 }
115
116 __END__
117
118 =head1 NAME
119
120 rsem-prepare-reference
121
122 =head1 SYNOPSIS
123
124 rsem-prepare-reference [options] reference_fasta_file(s) reference_name
125
126 =head1 ARGUMENTS
127
128 =over
129
130 =item B<reference_fasta_file(s)>
131
132 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.
133
134 =item B<reference name>
135
136 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).
137
138 =back
139
140 =head1 OPTIONS
141
142 =over 
143
144 =item B<--gtf> <file>
145
146 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.
147
148 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. 
149
150 (Default: off)
151
152 =item B<--transcript-to-gene-map> <file>
153
154 Use information from <file> to map from transcript (isoform) ids to gene ids.
155 Each line of <file> should be of the form:
156
157 gene_id transcript_id
158
159 with the two fields separated by a tab character.
160
161 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.
162
163 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.
164
165 (Default: off)
166
167 =item B<--no-polyA>
168
169 Do not add poly(A) tails to the end of reference isoforms. (Default: adding poly(A) tails to all transcripts)
170
171 =item B<--no-polyA-subset> <file>
172
173 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'.)
174
175 =item B<--polyA-length> <int>
176
177 The length of the poly(A) tails to be added. (Default: 125)
178
179 =item B<--bowtie-path> <path>
180
181 The path to the Bowtie executables. (Default: the path to Bowtie executables is assumed to be in the user's PATH environment variable)
182
183 =item B<--no-bowtie>
184
185 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)
186
187 =item B<--no-ntog>
188
189 Disable the conversion of 'N' characters to 'G' characters in the reference sequences prepared for aligners.  This conversion is in particular desired for Bowtie aligner to align against all positions in the reference. (Default: off)
190
191 =item B<--bowtie2>
192
193 Build Bowtie 2 indices instead of Bowtie indices. Turn on this option will automatically turn on '--no-bowtie' and '--no-ntog' options. (Default: off)
194
195 =item B<--bowtie2-path>
196
197 The path to the Bowtie 2 executables. (Default: the path to Bowtie 2 executables is assumed to be in the user's PATH environment variable)
198
199 =item B<-q/--quiet>
200
201 Suppress the output of logging information. (Default: off)
202
203 =item B<-h/--help>
204
205 Show help information.
206
207 =back
208
209 =head1 DESCRIPTION
210
211 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.
212
213 =head1 OUTPUT
214
215 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).
216
217 'reference_name.grp', 'reference_name.ti', 'reference_name.seq', and 'reference_name.chrlist' are used by RSEM internally.
218
219 B<'reference_name.transcripts.fa'> contains the extracted reference transcripts in FASTA format. Poly(A) tails are added unless '--no-polyA' is set.
220
221 B<'reference_name.idx.fa'> is used by aligners to build their own indices. If '--no-ntog' is set, this file should be identical to 'reference_name.transcripts.fa'.
222  
223 =head1 EXAMPLES
224
225 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'.
226
227 There are two ways to write the command:
228
229  rsem-prepare-reference --gtf mm9.gtf \
230                         --transcript-to-gene-map knownIsoforms.txt \
231                         --bowtie-path /sw/bowtie \                  
232                         /data/mm9/chr1.fa,/data/mm9/chr2.fa,...,/data/mm9/chrM.fa \
233                         /ref/mouse_125
234
235 OR
236
237  rsem-prepare-reference --gtf mm9.gtf \
238                         --transcript-to-gene-map knownIsoforms.txt \
239                         --bowtie-path /sw/bowtie \
240                         /data/mm9 \
241                         /ref/mouse_125
242
243 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:
244
245  rsem-prepare-reference --transcript-to-gene-map mapping.txt \
246                         --no-polyA \
247                         --no-bowtie \
248                         mm9.fasta \
249                         mouse_0
250
251 =cut