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