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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
|
/**
*
* museq.c: Main program control
* Author: A.R.Subramanian
*
*/
/**
* TODO LIST:
* - option: multi diags as optional argument
*/
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include "parameters.h"
#include "struct.h"
#include "translate.h"
#include "orf.h"
#include "io.h"
/**
* external functions definitions
*/
// diag.c
//extern struct seq_part* create_seq_part(int num, struct seq* aSeq,
// unsigned int startpos);
//extern struct diag* create_diag(struct seq_part* part1, struct seq_part* part2,
// int dlength);
//extern void calc_weight(struct diag* dg, struct scr_matrix* smatrix,
// struct prob_dist *pdist);
//extern struct diag_col *create_diag_col(int seq_amount);
extern void free_diag(struct diag* dg);
extern void free_diag_col(struct diag_col* dcol);
extern struct diag_col *find_all_diags(struct scr_matrix *smatrix,
struct prob_dist *pdist,
struct seq_col *in_seq_col, struct alignment *algn, int round);
// prob.c
//extern struct seq* create_random_seq(struct scr_matrix *smatrix, int length);
//extern double* approx_prob(struct scr_matrix *smatrix, struct prob_dist *sdist,
// int diaglen, int seqlen);
extern struct prob_dist* calc_score_dist(struct scr_matrix *smatrix, int mxdlen);
// alig.c
extern struct alignment* create_empty_alignment(struct seq_col *scol);
//extern char adapt_diag(struct alignment *algn, struct scr_matrix *smatrix, struct diag* dg);
extern char simple_aligner(struct seq_col *scol, struct diag_col *dcol,
struct scr_matrix* smatrix,
struct prob_dist *pdist,
struct alignment *algn, int round);
extern struct simple_diag_col* read_anchors(char *filename, struct seq_col* scol);
extern struct alignment* guided_aligner(struct alignment *palgn,
struct seq_col *scol, struct diag_col *dcol,
struct scr_matrix* smatrix,
struct prob_dist *pdist, struct gt_node *gtn,
int round);
extern void free_alignment(struct alignment *algn);
/**
* main program routine
*/
int main(int argc, char **argv)
{
parameters(argc, argv);
version();
// read similarity matrix
char *smatrixfile = (char *)build_pathname(para->conf_dir,para->SCR_MATRIX_FILE_NAME);
struct scr_matrix *smatrix = read_scr_matrix(smatrixfile);
// print the score matrix
if( para->DEBUG >5) {
print_scr_matrix(smatrix);
}
// read the probability distribution for diagonals
char *pdistfilename = (char *)build_pathname(para->conf_dir,para->DIAG_PROB_FILE_NAME);
int i;
struct seq_col *in_seq_col;
struct prob_dist *pdist;
if(!para->COMPUTE_PROB){
pdist = read_diag_prob_dist(smatrix, pdistfilename);
in_seq_col = read_fasta(para->in_file);
if(para->DNA_TRANSLATION){
if(para->FIND_ORF){
if(para->ORF_FRAME){
translate_sequence_collection_orf_frame(in_seq_col);
}
else {
in_seq_col = set_longest_orf(in_seq_col);
}
}
else{
translate_sequence_collection_default(in_seq_col);
}
}
}
// print read input sequences
if(para->DEBUG>5) {
int sc,scl = in_seq_col->length;
for(sc=0; sc < scl;sc++) {
print_seq(&(in_seq_col->seqs[sc]));
printf("\n");
}
}
// ----------------------------------------------------------------------
// probability table generation area
// ----------------------------------------------------------------------
if(para->COMPUTE_PROB)
{
char *prob_table_output_file = (char *)build_pathname(para->conf_dir,"prob_table");
struct prob_dist *sdist = calc_score_dist(smatrix, 100);
print_pdist_matrix(sdist, prob_table_output_file);
exit(0);
}
double tim = clock(),tim2;
// fast mode has higher threshold weights
if(para->FAST_MODE) {
para->PROT_SIM_SCORE_THRESHOLD += 0.25;
}
// ----------------------------------------------------------------------
// Consider Anchors
// ----------------------------------------------------------------------
struct simple_diag_col *anchors = NULL;
struct diag_col adcol;
struct alignment *algn= NULL;
if(! para->FAST_MODE) {
algn = create_empty_alignment(in_seq_col);
}
struct alignment *salgn = create_empty_alignment(in_seq_col);
if(para->DO_ANCHOR>0) {
anchors = read_anchors(para->ANCHOR_FILE_NAME, in_seq_col);
adcol.diags = anchors->data;
adcol.diag_amount = anchors->length;
simple_aligner(in_seq_col, &adcol,smatrix,pdist,salgn,1);
if(! para->FAST_MODE) simple_aligner(in_seq_col, &adcol,smatrix,pdist,algn,1);
if(anchors!=NULL) {
for(i=0;i<adcol.diag_amount;i++) {
free_diag(adcol.diags[i]);
}
free(adcol.diags);
free(anchors);
}
}
// ----------------------------------------------------------------------
// Compute pairwise diagonals
// ----------------------------------------------------------------------
//if(para->DNA_PARAMETERS && (para->SENS_MODE>0)) {
// para->DIAG_THRESHOLD_WEIGHT = -log(0.875);
//}
struct diag_col *all_diags = find_all_diags(smatrix, pdist, in_seq_col,salgn,1);
double duration = (clock()-tim)/CLOCKS_PER_SEC;
if(para->DEBUG >1) printf("Found %i diags in %f secs\n", all_diags->diag_amount, duration);
int diag_amount = all_diags->diag_amount;
// ----------------------------------------------------------------------
// Compute alignment
// ----------------------------------------------------------------------
tim2=clock();
if(! para->FAST_MODE) {
struct diag *cp_diags[all_diags->diag_amount];
for(i=0;i<diag_amount;i++) {
cp_diags[i] = malloc(sizeof (struct diag));
*(cp_diags[i]) = *(all_diags->diags[i]);
}
guided_aligner(algn, in_seq_col, all_diags,smatrix,pdist,all_diags->gt_root, 1);
for(i=0;i<diag_amount;i++) {
all_diags->diags[i] = cp_diags[i];
}
all_diags->diag_amount = diag_amount;
}
//struct alignment *algn = salgn;
simple_aligner(in_seq_col, all_diags,smatrix,pdist,salgn,1);
duration = (clock()-tim2)/CLOCKS_PER_SEC;
if(! para->FAST_MODE) {
if(para->DEBUG >1) printf("First alignment after %f secs. simple: %f guided: %f\n", duration, salgn->total_weight, algn->total_weight);
} else {
if(para->DEBUG >1) printf("First alignment after %f secs. simple: %f \n", duration, salgn->total_weight);
}
//if(para->DEBUG >1) printf("First alignment after %f secs. guided: %f\n", duration, algn->total_weight);
free_diag_col(all_diags);
para->DO_ANCHOR = 0; // anchors done
// round 2+
int round;
char newFound = 0;
int type;
//printf(" SENS %i\n", para->SENS_MODE);
// consider sensitivity level
if(! para->FAST_MODE) {
if(para->SENS_MODE==0) {
para->DIAG_THRESHOLD_WEIGHT = 0.0;
} else if(para->SENS_MODE==1) {
if(para->DNA_PARAMETERS)
para->DIAG_THRESHOLD_WEIGHT = -log(0.75);//-log(.875+0.125/2.0);
else
para->DIAG_THRESHOLD_WEIGHT = -log(0.75);
}else if(para->SENS_MODE==2) {
if(para->DNA_PARAMETERS)
para->DIAG_THRESHOLD_WEIGHT = -log(0.5);//-log(0.875);
else
para->DIAG_THRESHOLD_WEIGHT = -log(0.5);
}
}
int stype = (para->FAST_MODE ? 1 : 0);
for(type=stype;type<2;type++) {
for(round=2;round<=20;round++) {
//for(round=2;round<=1;round++) {
tim2=clock();
all_diags = find_all_diags(smatrix, pdist, in_seq_col,(type ? salgn : algn), round);
//all_diags = find_all_diags(smatrix, pdist, in_seq_col, algn);
duration = (clock()-tim2)/CLOCKS_PER_SEC;
if(para->DEBUG >1) printf("Found %i diags after %f secs\n", all_diags->diag_amount, duration);
if(all_diags->diag_amount ==0) {
free_diag_col(all_diags);
break;
} else {
// round 2 and further we use the simple aligner
newFound = simple_aligner(in_seq_col, all_diags,smatrix,pdist,(type ? salgn : algn),round);
//newFound = simple_aligner(in_seq_col, all_diags,smatrix,pdist,algn,round);
// newFound = complex_aligner(in_seq_col, all_diags,smatrix,pdist,algn,round);
free_diag_col(all_diags);
if(!newFound) break;
}
}
}
if(para->DEBUG >1)
printf("Alignment ready!\n");
if(! para->FAST_MODE) {
if(para->DEBUG >1) printf("Final alignment simple: %f guided: %f\n", salgn->total_weight, algn->total_weight);
} else {
if(para->DEBUG >1) printf("Final alignment simple: %f \n", salgn->total_weight);
}
//if(para->DEBUG >1) printf("Final alignment guided: %f\n", algn->total_weight);
if( ( para->FAST_MODE) || (salgn->total_weight > algn->total_weight)) {
if(! para->FAST_MODE) free_alignment(algn);
algn = salgn;
}
//algn = salgn;
if(para->out_file==NULL) {
if(para->OUTPUT){
if(para->DNA_TRANSLATION)
simple_print_alignment_dna_retranslate(algn);
else
simple_print_alignment_default(algn);
}
else{
simple_print_alignment_default(algn);
}
}else {
if(para->OUTPUT){
if(para->DNA_TRANSLATION) {
fasta_print_alignment_dna_retranslate(algn, para->out_file);
}
else {
fasta_print_alignment_default(algn, para->out_file);
}
}
else{
fasta_print_alignment_default(algn, para->out_file);
}
}
duration = (clock()-tim)/CLOCKS_PER_SEC;
printf("Total time: %f secs\n", duration);
printf("Total weight: %f \n", algn->total_weight);
exit(EXIT_SUCCESS);
}
|