📄 dna2.cc
字号:
XSetLineAttributes(g.display, g.gc, 1, LineSolid, CapButt, JoinBevel); x2 = g.xsize-2; y2 = g.ysize-2; xx1 = max(0, xx1); yy1 = max(0, yy1); dytot = totalspacing(); // Distance between lines of 1 sequence if(g.editing != oediting) { XClearWindow(g.display, g.draw_window); XClearWindow(g.display, g.xlabel_window); XClearWindow(g.display, g.ylabel_window); } if(g.editing) { x = 0; ytopmargin = 10; for(k=0; k<g.noofsequences; k++) { dy = g.doc[k].charheight + LINESPACING; // Pixels between each sequence s1 = g.doc[k].text + max(0, g.doc[k].offset); matches = 0; mismatches = 0; if(g.doc[k].n) { charsperline = g.xsize / g.doc[k].charwidth; start = 0; xshift = 0; // Spaces to skip at left of sequence len = g.doc[k].n - max(0, g.doc[k].offset); linecount = 0; if(g.doc[k].offset<0) { xshift = -g.doc[k].offset; start = g.doc[k].offset; } while(start < len) { width = charsperline - xshift; // width to print on this line if(start + width > len) width = len - start; // Check if necessary to highlight part of the line if(g.doc[k].marked && ( between(g.doc[k].markstart, start, start+width) || between(g.doc[k].markend, start, start+width))) { drawmarkedline(x, ytopmargin + linecount * dytot + k * dy, s1 + start, g.doc[k].markstart - start, g.doc[k].markend - start, width, g.doc[k].charwidth); }else XDrawImageString(g.display, win, g.gc, x + xshift*g.doc[k].charwidth, ytopmargin + linecount * dytot + k * dy, max(g.doc[k].text, s1 + start), width); xshift = max(0, xshift - width); start += width; // Starting pos in s1 for line segment linecount++; // Line segment count for string } if(width==charsperline) // Bottom line was full, add space at start // of next line XDrawImageString(g.display, win, g.gc, x , ytopmargin + linecount * dytot + k * dy, " ", 1); else // Add a space after last char on same line XDrawImageString(g.display, win, g.gc, x + width*g.doc[k].charwidth, ytopmargin + (linecount-1) * dytot + k * dy, " ", 1); } } //// Draw vertical lines showing identical areas for(k=0; k<g.noofsequences-1; k++) { s1 = g.doc[k].text + g.doc[k].offset; s2 = g.doc[k+1].text + g.doc[k+1].offset; dy = g.doc[k].charheight + LINESPACING; // Pixels between each sequence pos = g.doc[k].pos; pos2 = g.doc[k+1].pos; matches = 0; mismatches = 0; if(g.doc[k].charwidth)charsperline = g.xsize / g.doc[k].charwidth; xx[k] = g.doc[k].charwidth/2-1; linecount = 0; charcount = 0; if(g.doc[k].n && g.doc[k+1].n) { for(j=0; j<g.doc[k].n; j++) { if(charcount >= charsperline) { charcount = 0; xx[k] = g.doc[k].charwidth/2-1; linecount++; } yy[k] = linecount * dytot + g.doc[k].charheight-3 + k*dy; color = g.bcolor; if(matchable_base(s1[j], g.doc[k].type) && matchable_base(s2[j], g.doc[k+1].type)) { if(toupper(s1[j]) == toupper(s2[j])) { color=g.fcolor; matches++; } else mismatches++; } XSetForeground(g.display, g.gc, color); if(between(xx[k], 0, g.xres-1) && between(yy[k], 0, g.yres-7)) XDrawLine(g.display, win, g.gc, xx[k], yy[k], xx[k], yy[k] + 6); xx[k] += g.doc[k].charwidth; charcount++; } } } XFlush(g.display); XSetForeground(g.display, g.gc, g.fcolor); printmatches(matches, mismatches); for(k=0; k<g.noofsequences; k++) { if(k*100 > g.xsize-20) break; print(basefilename(g.doc[k].filename), k*100, 0, g.fcolor, g.bcolor, g.xlabel_window, 1, HORIZONTAL); } }else if(g.image_ximage !=NULL) { //// Redraw the correlation plot XPutImage(g.display, g.draw_window, g.gc, g.image_ximage, max(0, xx1+g.doc[g.matrix_set1].offset), max(0, yy1+g.doc[g.matrix_set2].offset), xx1, yy1, xx2-xx1, yy2-yy1); strcpy(tempstring, basefilename(g.doc[g.matrix_set1].filename)); print(tempstring, 50, 0, g.fcolor, g.bcolor, g.xlabel_window, 1, HORIZONTAL); strcpy(tempstring, basefilename(g.doc[g.matrix_set2].filename)); text_size(tempstring, xlabelsize, ylabelsize, ascent, descent); print(tempstring, -2, 2*xlabelsize, g.fcolor, g.bcolor, g.ylabel_window, 1, VERTICAL); } oediting = g.editing; return OK;}//--------------------------------------------------------------------------//// drawmarkedline draw one line of a string with part of it marked ////--------------------------------------------------------------------------//int drawmarkedline(int x, int y, char *s, int ms, int me, int w, int cw){ // Draw the first (possibly 0 length) segment in normal color XDrawImageString(g.display, g.draw_window, g.gc, x, y, s, ms); x += ms * cw; // Draw the second segment in highlighted color XSetBackground(g.display, g.gc, g.hcolor); XDrawImageString(g.display, g.draw_window, g.gc, x, y, s+ms, me-ms); x += (me-ms) * cw; XSetBackground(g.display, g.gc, g.bcolor); // Draw the 3rd (possibly 0 length) segment in normal color XDrawImageString(g.display, g.draw_window, g.gc, x, y, s+me, w-me); return 0; }//--------------------------------------------------------------------------//// search ////--------------------------------------------------------------------------//void search(char *searchstring){ int charsperline, count, hit, j, j2, k, len, slen, spos; char *s; if(searchstring==NULL) return; slen = (int)strlen(searchstring); strupr(searchstring); for(k=0; k<g.noofsequences; k++) { s = g.doc[k].text; if(s==NULL) break; len = (int)strlen(s); g.doc[k].marked = 0; charsperline = g.xsize / g.doc[k].charwidth; spos = 0; // position in search string j = 0; // position in s count = 0; // no. of matching positions for(j=g.doc[k].pos+1; j<len-slen; j++) { hit=1; for(j2=0; j2<slen; j2++) if(s[j+j2] != searchstring[j2]){ hit=0; break; } if(hit) { count++; g.doc[k].marked = 1; g.doc[k].markstart = j; g.doc[k].markend = j + slen; g.doc[k].pos = j; redrawscreen(0, 0, g.xsize, g.ysize); break; } } } XSetForeground(g.display, g.gc, g.fcolor); }//--------------------------------------------------------------------------//// valid_base - check if letter is valid base or amino acid symbol ////--------------------------------------------------------------------------//int valid_base(int c, int mode){ int valid=0; c = toupper(c); if(mode==DNA) { if(strchr("ACGTU",c)) valid=1; }else if(mode==PROTEIN) { if(c>='A' && c<='Z') valid=1; } return valid;}//--------------------------------------------------------------------------//// matchable_base - check if letter is valid base or aa & matchable ////--------------------------------------------------------------------------//int matchable_base(int c, int mode){ int valid=0; if(c==0) return 0; c = toupper(c); if(mode==DNA) { if(strchr("ACGTU",c)) valid=1; }else if(mode==PROTEIN) { if(strchr("ACDEFGHIKLMNPQRSTVWY",c)) valid=1; } return valid;}//--------------------------------------------------------------------------//// comments ////--------------------------------------------------------------------------//void comments(void){ int j,k; int listcount = -1, selection; char listtitle[100] = "Sequence comments"; char **info; info = new char*[MAXCOMMENTS]; for(j=0; j<MAXSEQUENCES; j++) { if(!g.doc[j].n) continue; listcount++; info[listcount] = new char[1024]; sprintf(info[listcount], basefilename(g.doc[j].filename)); for(k=0; k<g.doc[j].ncomments;k++) { listcount++; info[listcount] = new char[1024]; if(!g.doc[j].ncomments) strcpy(info[listcount], "Sequence has no comments"); else strcpy(info[listcount], g.doc[j].comment[k]); } } selection = 0; listinfo l; l.title = listtitle; l.info = info; l.size = listcount+1; l.itemstoshow = listcount-1; l.firstitem = 1; l.wantsort = 0; l.wantsave = 0; l.helptopic = 0; l.allowedit = 0; l.selection = &selection; l.width = 0; l.transient = 0; l.wantfunction = 0; l.autoupdate = 0; l.clearbutton = 0; l.highest_erased = 0; list(&l); for(k=0;k<=listcount;k++) delete[] info[k]; delete[] info; g.getout=0;}//--------------------------------------------------------------------------//// translate ////--------------------------------------------------------------------------//void translate(int wantcheck){ char code[8]; if(wantcheck && g.doc[g.cs].type==PROTEIN) { message("Can't translate protein sequence"); return; } int k, n, aa; n = strlen(g.doc[g.cs].dtext); char *tempseq; tempseq = new char[n]; aa = 0; for(k=g.doc[g.cs].frame; k<n-2; k+=3) { code[0] = g.doc[g.cs].dtext[k ]; code[1] = g.doc[g.cs].dtext[k+1]; code[2] = g.doc[g.cs].dtext[k+2]; code[3] = 0; g.doc[g.cs].text[aa++] = dna2protein(code); } g.doc[g.cs].n = aa; g.doc[g.cs].type = PROTEIN; delete[] tempseq; XClearWindow(g.display, g.draw_window); redrawscreen(0, 0, g.xsize, g.ysize);}//--------------------------------------------------------------------------//// reverse ////--------------------------------------------------------------------------//void reverse(void){ if(g.doc[g.cs].type != DNA){ message("Can't reverse protein sequence"); return; } int k, n; n = g.doc[g.cs].n; char *tempseq; tempseq = new char[n]; for(k=0; k<n; k++) tempseq[k] = g.doc[g.cs].text[n-k-1]; for(k=0; k<n; k++) { switch(tempseq[k]) { case 'A' : tempseq[k] = 'T'; break; case 'T' : tempseq[k] = 'A'; break; case 'G' : tempseq[k] = 'C'; break; case 'C' : tempseq[k] = 'G'; break; } } for(k=0; k<n; k++) g.doc[g.cs].text[k] = tempseq[k]; delete[] tempseq; memcpy(g.doc[g.cs].dtext, g.doc[g.cs].text, n); XClearWindow(g.display, g.draw_window); redrawscreen(0, 0, g.xsize, g.ysize);}//--------------------------------------------------------------------------//// prevframe ////--------------------------------------------------------------------------//void prevframe(void){ g.doc[g.cs].frame++; if(g.doc[g.cs].frame>2) g.doc[g.cs].frame=0; translate(0); // don't check if it's a protein
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -