Ejemplo n.º 1
0
void print_table(str s, const Dtable& T, bool latex, Slist labels) {
	int SIZE = 7;
	int MAXSIZE = 10;
	int MAXLINE = 50;
	int STANDARDSIZE = 1;

	bool square(true);
	int l = T.size();
	if (MAXLINE<l) printf("Cautious, table is of size %d, only %d will be displayed \n",l,MAXLINE);
	int cc = T[0].size();
	for (int i=0; i<l; i++) if (T[i].size()!=cc) square = false;

	int max = max_row(T);
	List maxRow = initList(max);
	if (square) {
		Table sizestr = initTable(l,max);
		for (int i=0; i<l; i++) {
			for (int j=0; j<max; j++) {
				int sz = f(T[i][j]).size()+1;
				sizestr[i][j] = sz<MAXSIZE ? sz : MAXSIZE;
			}
		}
		maxRow = max_on_row(sizestr);
	}
	else maxRow = initList(max,STANDARDSIZE);

	str et = latex ? " &" : "|";
	str slash = latex ? " \\\\ \n" : "\n";

	str rrr(T[0].size(),'r');
	printf("%s", s.c_str());
	printf("\n");

	bool labelsB = isnull(labels);
	str space(6,' ');
	printf("%s", space.c_str());
    //rnc 10/25/15
    printf("Obs. made ");
    for (int j=0; j<6;j++){
    //for (int j=0; j<max; j++) {
		str s = (j==max-1) ? slash : et;
		printf("%s%s",format(maxRow[j],f(j)).c_str(),s.c_str());
	}
    printf("initial&  fibers&obs'rvd&percent& wght'd\\\\ \n");
	for (int i=0; i<l && i<MAXLINE; i++) {
		str pre = labelsB ? f(i) : format(11,labels[i]);
		printf("%3s  %s",pre.c_str(),et.c_str());
		int c = T[i].size();
		if (c==0) printf("\n");
		for (int j=0; j<c; j++) {
			str s = (j==c-1) ? slash : et;
			str num = T[i][j]==-1 ? "" : f(T[i][j]).c_str();
			printf("%s%s",format(maxRow[j],num).c_str(),s.c_str());
		}
	}
	printf("\n");
}
Ejemplo n.º 2
0
void print_mult_Dtable_latex(str s, str ss, Dtable T, double multX) {
	printf("# %s \n  Output data in %s \n\n",s.c_str(),ss.c_str());
	FILE* pFile;
	pFile = fopen(ss.c_str(),"w");
	if (!pFile) {
		printf("File opening failed \n"); fl();
		myexit(1);
	}

	fprintf(pFile,"x ");
	for (int i=0; i<T.size(); i++) fprintf(pFile,"%d ",i);
	fprintf(pFile,"\n");
	int maxrow = max_row(T);
	for (int j=0; j<maxrow; j++) {
		fprintf(pFile,"%f ",j*multX);
		for (int i=0; i<T.size(); i++) {
			if (j<T[i].size()) fprintf(pFile,"%f ",T[i][j]);
			else fprintf(pFile,"0 ");
		}
		fprintf(pFile,"\n");
	}
	fclose(pFile);
}
Ejemplo n.º 3
0
void make_square(Table& T) {
	int max = max_row(T);
	for (int i=0; i<T.size(); i++) {
		if (T[i].size()<max) T[i].resize(max);
	}
}
Ejemplo n.º 4
0
 /** Run alignment algorithm.
 \param first_last Last aligned position in first sequence (output)
 \param second_last Last aligned position in second sequence (output)
 */
 void align(int& first_last, int& second_last) const {
     adjust_matrix_size();
     limit_range();
     make_frame();
     ASSERT_TRUE(!local() || max_errors() == -1);
     int& r_row = first_last;
     int& r_col = second_last;
     r_row = r_col = -1;
     for (int row = 0; row <= max_row(); row++) {
         int start_col = min_col(row);
         int stop_col = max_col(row);
         int min_score_col = start_col;
         for (int col = start_col; col <= stop_col; col++) {
             ASSERT_TRUE(col >= 0 && col < side());
             ASSERT_TRUE(in(row, col));
             int match = at(row - 1, col - 1) +
                         substitution(row, col);
             int gap1 = at(row, col - 1) + gap_penalty();
             int gap2 = at(row - 1, col) + gap_penalty();
             int score = std::min(match, std::min(gap1, gap2));
             if (local()) {
                 score = std::min(score, 0);
             }
             at(row, col) = score;
             if (score < at(row, min_score_col)) {
                 min_score_col = col;
             }
             track(row, col) = (score == match) ? MATCH :
                               (score == gap1) ? COL_INC :
                               ROW_INC;
         }
         if (max_errors() != -1 &&
                 at(row, min_score_col) > max_errors()) {
             break;
         }
         r_row = row;
         r_col = min_score_col;
     }
     if (max_errors() == -1) {
         // col -> max_col in this row
         ASSERT_TRUE(in(max_row(), max_col(max_row())));
         ASSERT_EQ(r_row, max_row());
         r_col = max_col(max_row());
         // if stopped earlier because of gap range
         int last_row = contents().first_size() - 1;
         int last_col = contents().second_size() - 1;
         if (r_row == last_row) {
             while (r_col < last_col) {
                 r_col += 1;
                 track(r_row, r_col) = COL_INC;
             }
         } else if (r_col == last_col) {
             while (r_row < last_row) {
                 r_row += 1;
                 track(r_row, r_col) = ROW_INC;
             }
         } else {
             throw Exception("row and column are not last");
         }
     }
 }