]> git.donarmstrong.com Git - rsem.git/blob - preRef.cpp
rsem v1.1.21
[rsem.git] / preRef.cpp
1 #include<cstdio>
2 #include<cstring>
3 #include<cstdlib>
4 #include<cctype>
5 #include<string>
6 #include<fstream>
7 #include<sstream>
8 #include<cassert>
9
10 #include "utils.h"
11 #include "Refs.h"
12 #include "PolyARules.h"
13 #include "RefSeqPolicy.h"
14 #include "AlignerRefSeqPolicy.h"
15
16 using namespace std;
17
18 int M;
19
20 RefSeqPolicy refp;
21 AlignerRefSeqPolicy aligner_refp;
22 PolyARules rules;
23 Refs refs;
24
25 ofstream fout;
26 char refF[STRLEN], alignerFastaF[STRLEN];
27
28 int polyAChoice, polyALen;
29 char exceptionF[STRLEN];
30 bool ntog; // true , change N into G; false do not change. Default is true. 
31 bool quiet; // verbose = !quiet;
32
33 // always generate references for aligners, default convert all N into G
34 int main(int argc, char* argv[]) {
35
36   if (argc < 4) {
37     printf("USAGE : rsem-preref refFastaF polyAChoice refName [-l polyALen] [-f exceptionF] [--no-ntog] [-q]\n\n");
38     printf("  refFastaF: a FASTA format file contains all reference transcripts\n");
39     printf("  polyAChoice: choice for polyA tail padding.It is a number from {0,1,2}\n");
40     printf("    0: pad polyA tail\n");
41     printf("    1: do not pad polyA tail at all\n");
42     printf("    2: pad polyA tail for all references but those in exceptionF\n");
43     printf("  -l: polyALen: specify the length of polyA tail you want to pad. Default is 100\n");
44     printf("  -f: exceptionF: file contains a list of exception reference ids. IDs starts from 1. Must set if polyAChoice = 2\n");
45     printf("  --no-ntog: do not convert N in references into G\n");
46     printf("  -q: quiet\n");
47     exit(-1);
48   }
49
50
51   polyAChoice = atoi(argv[2]);
52
53   polyALen = 125;
54   ntog = true;
55   quiet = false;
56   memset(exceptionF, 0, sizeof(exceptionF));
57
58   for (int i = 4; i < argc; i++) {
59           if (!strcmp(argv[i], "-l")) { polyALen = atoi(argv[i + 1]); }
60           if (!strcmp(argv[i], "-f")) { strcpy(exceptionF, argv[i + 1]); }
61           if (!strcmp(argv[i], "--no-ntog")) { ntog = false; }
62           if (!strcmp(argv[i], "-q")) { quiet = true; }
63   }
64
65   verbose = !quiet;
66
67   //make references
68   rules = PolyARules(polyAChoice, polyALen, exceptionF);
69   refs.makeRefs(argv[1], refp, rules);
70   M = refs.getM();
71
72   //save references
73   sprintf(refF, "%s.seq", argv[3]);
74   refs.saveRefs(refF);
75
76   sprintf(alignerFastaF, "%s.idx.fa", argv[3]);
77   fout.open(alignerFastaF);
78   for (int i = 1; i <= M; i++) {
79     fout<<">"<<refs.getRef(i).getName()<<endl<<(ntog ? aligner_refp.convert(refs.getRef(i).getSeq()) : refs.getRef(i).getSeq())<<endl;
80   }
81   fout.close();
82   
83   if (verbose) { printf("IDX.fa generated!\n"); }
84
85   return 0;
86 }