]> git.donarmstrong.com Git - rsem.git/blob - preRef.cpp
Removed Mac ._* files from repo
[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], idxF[STRLEN], n2g_idxF[STRLEN];
27
28 int polyAChoice, polyALen;
29 char exceptionF[STRLEN];
30 bool quiet; // verbose = !quiet;
31
32 // always generate references for aligners, default convert all N into G
33 int main(int argc, char* argv[]) {
34
35         if (argc < 4) {
36                 printf("USAGE : rsem-preref refFastaF polyAChoice refName [-l polyALen] [-f exceptionF] [-q]\n\n");
37                 printf("  refFastaF: a FASTA format file contains all reference transcripts\n");
38                 printf("  polyAChoice: choice for polyA tail padding.It is a number from {0,1,2}\n");
39                 printf("    0: pad polyA tail\n");
40                 printf("    1: do not pad polyA tail at all\n");
41                 printf("    2: pad polyA tail for all references but those in exceptionF\n");
42                 printf("  -l: polyALen: specify the length of polyA tail you want to pad. Default is 100\n");
43                 printf("  -f: exceptionF: file contains a list of exception reference ids. IDs starts from 1. Must set if polyAChoice = 2\n");
44                 printf("  -q: quiet\n");
45                 exit(-1);
46         }
47
48         polyAChoice = atoi(argv[2]);
49
50         polyALen = 125;
51         quiet = false;
52         memset(exceptionF, 0, sizeof(exceptionF));
53
54         for (int i = 4; i < argc; i++) {
55                 if (!strcmp(argv[i], "-l")) { polyALen = atoi(argv[i + 1]); }
56                 if (!strcmp(argv[i], "-f")) { strcpy(exceptionF, argv[i + 1]); }
57                 if (!strcmp(argv[i], "-q")) { quiet = true; }
58         }
59
60         verbose = !quiet;
61
62         //make references
63         rules = PolyARules(polyAChoice, polyALen, exceptionF);
64         refs.makeRefs(argv[1], refp, rules);
65         M = refs.getM();
66
67         //save references
68         sprintf(refF, "%s.seq", argv[3]);
69         refs.saveRefs(refF);
70
71         sprintf(idxF, "%s.idx.fa", argv[3]);
72         fout.open(idxF);
73         for (int i = 1; i <= M; i++) {
74                 fout<< ">"<< refs.getRef(i).getName()<< endl<< refs.getRef(i).getSeq()<< endl;
75         }
76         fout.close();
77         if (verbose) printf("%s is generated!\n", idxF);
78
79         sprintf(n2g_idxF, "%s.n2g.idx.fa", argv[3]);
80         fout.open(n2g_idxF);
81         for (int i = 1; i <= M; i++) {
82           fout<< ">"<< refs.getRef(i).getName()<< endl<< aligner_refp.convert(refs.getRef(i).getSeq())<< endl;
83         }
84         fout.close();
85         if (verbose) printf("%s is generated!\n", n2g_idxF);
86
87         return 0;
88 }