-
Notifications
You must be signed in to change notification settings - Fork 61
/
mcscan.cc
161 lines (142 loc) · 4.5 KB
/
mcscan.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* Author: Haibao Tang <bao@uga.edu> May 10, 2007
* Main entry point for the executable mcscan
*
* Modified by Yupeng Wang, Mar 31, 2011
* The parameter MAX_GAPS was added. IN_SYNTENY has 3 choices and is functional.
*/
#include "mcscan.h"
static bool IS_PAIRWISE;
static bool BUILD_MCL;
static char prefix_fn[LABEL_LEN];
static void print_banner()
{
;
}
static void init_opt()
{
// match bonus, final score=MATCH_SCORE-GAPS^GAP_PENALTY
MATCH_SCORE = 50;
// the number of genes required to call synteny, sometimes more
MATCH_SIZE = 5;
// gap extension penalty
GAP_PENALTY = -1;
// alignment significance
E_VALUE = 1e-5;
// maximum gaps allowed
MAX_GAPS =25;
OVERLAP_WINDOW=5;
IS_PAIRWISE = false;
IN_SYNTENY = 0;
}
static void print_help(const char *prg)
{
progress("[Usage] %s prefix_fn [options]\n"
" -k MATCH_SCORE, final score=MATCH_SCORE+NUM_GAPS*GAP_PENALTY\n"
" (default: %d)\n"
" -g GAP_PENALTY, gap penalty (default: %d)\n"
" -s MATCH_SIZE, number of genes required to call a collinear block\n"
" (default: %d)\n"
" -e E_VALUE, alignment significance (default: %lg)\n"
" -m MAX_GAPS, maximum gaps allowed (default: %d)\n"
" -w OVERLAP_WINDOW, maximum distance (# of genes) to collapse BLAST matches (default: %d)\n"
" -a only builds the pairwise blocks (.collinearity file)\n"
" -b patterns of collinear blocks. 0:intra- and inter-species (default); 1:intra-species; 2:inter-species\n"
" -h print this help page\n",
prg, MATCH_SCORE, GAP_PENALTY, MATCH_SIZE, E_VALUE, MAX_GAPS, OVERLAP_WINDOW);
exit(1);
}
static void read_opt(int argc, char *argv[])
{
int c;
opterr = 0;
if (argc < 2) print_help(argv[0]);
while ((c = getopt(argc, argv, "k:g:s:e:b:m:w:ah")) != -1)
switch (c)
{
case 'k':
MATCH_SCORE = atoi(optarg);
break;
case 'g':
GAP_PENALTY = atoi(optarg);
break;
case 's':
MATCH_SIZE = atoi(optarg);
break;
case 'e':
E_VALUE = atof(optarg);
break;
case 'b':
IN_SYNTENY = atoi(optarg);
break;
case 'm':
MAX_GAPS = atoi(optarg);
break;
case 'w':
OVERLAP_WINDOW = atoi(optarg);
break;
case 'a':
IS_PAIRWISE = true;
break;
case '?':
if (optopt=='k' || optopt=='s' || optopt=='g' || optopt=='e' || optopt=='b' || optopt=='m' || optopt=='w')
errAbort("Option -%c requires an argument.", optopt);
else if (isprint (optopt))
errAbort("Unknown option `-%c'.", optopt);
else
errAbort("Unknown option character `\\x%x'.", optopt);
default:
print_help(argv[0]);
break;
}
if (optind==argc) errAbort("Please enter your input file");
else strcpy(prefix_fn, argv[optind]);
//OVERLAP_WINDOW=5;
CUTOFF_SCORE = MATCH_SCORE*MATCH_SIZE;
}
void fill_allg()
{
Gene_feat *gf1;
map<string, Gene_feat>::iterator it;
for (it=gene_map.begin(); it!=gene_map.end(); it++)
{
gf1 = &(it->second);
allg.insert(gf1);
}
int i=0;
geneSet::const_iterator it77=allg.begin();
for (; it77!=allg.end(); it77++)
{
(*it77)->gene_id=i;
i++;
}
}
int main(int argc, char *argv[])
{
/* Start the timer */
uglyTime(NULL);
print_banner();
char align_fn[LABEL_LEN], block_fn[LABEL_LEN];
FILE *fw;
init_opt();
read_opt(argc, argv);
read_gff(prefix_fn);
read_blast(prefix_fn);
sprintf(align_fn, "%s.collinearity", prefix_fn);
fw = mustOpen(align_fn, "w");
progress("%d pairwise comparisons", (int) mol_pairs.size());
fill_allg();
map<string, int>::const_iterator ip;
for (ip=mol_pairs.begin(); ip!=mol_pairs.end(); ip++)
{
if (ip->second >= MATCH_SIZE) feed_dag(string(ip->first));
}
progress("%d alignments generated", (int) seg_list.size());
print_align(fw);
fclose(fw);
uglyTime("Pairwise collinear blocks written to %s", align_fn);
if (IS_PAIRWISE) return 0;
msa_main(prefix_fn);
uglyTime("Done!");
return 0;
}