]> git.donarmstrong.com Git - rsem.git/blob - preRef.cpp
Modified the acknowledgement section of README.md
[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], transF[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                 printf("  This program will generate a file named \"refName.transcripts.fa\", which may rewrite an existing file (e.g. refFastaF).\n");
48                 exit(-1);
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(transF, "%s.transcripts.fa", argv[3]);
77         fout.open(transF);
78         for (int i = 1; i <= M; i++) {
79                 fout<< ">"<< refs.getRef(i).getName()<< endl<< refs.getRef(i).getSeq()<< endl;
80         }
81         fout.close();
82         if (verbose) printf("%s is generated!\n", transF);
83
84         sprintf(alignerFastaF, "%s.idx.fa", argv[3]);
85         fout.open(alignerFastaF);
86         for (int i = 1; i <= M; i++) {
87                 fout<<">"<<refs.getRef(i).getName()<<endl<<(ntog ? aligner_refp.convert(refs.getRef(i).getSeq()) : refs.getRef(i).getSeq())<<endl;
88         }
89         fout.close();
90         if (verbose) printf("%s is generated!\n", alignerFastaF);
91
92         return 0;
93 }