/* @source prettyseq application ** ** Pretty translation of DNA sequences for publication ** ** @author Copyright (C) Alan Bleasby (ableasby@hgmp.mrc.ac.uk) ** @@ ** ** This program is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License ** as published by the Free Software Foundation; either version 2 ** of the License, or (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ******************************************************************************/ #include "emboss.h" #include #include #define POFF 1000000 /* Printing flag */ static void prettyseq_makeRuler(ajint len, ajint begin, char *ruler, ajint *npos); static void prettyseq_calcProteinPos(ajint *ppos, const AjPStr pro, ajint len); static void prettyseq_showTrans(const ajint *ppos, const ajint *npos, const AjPStr pro, const AjPStr substr, ajint len, const char *ruler, ajint begin, AjPFile outf, AjBool isrule, AjBool isp, AjBool isn, ajint width, const char *name); static void prettyseq_showTransb(const ajint *ppos, const ajint *npos, const AjPStr pro, const AjPStr substr, const char *ruler, AjPFile outf, AjBool isrule, AjBool isp, AjBool isn, ajint start, ajint end); static void prettyseq_Translate(ajint beg, ajint end, AjPStr *s, const AjPCod codon, const AjPRange range, AjPStr* pro); /* @prog prettyseq ************************************************************ ** ** Output sequence with translated ranges ** ******************************************************************************/ int main(int argc, char **argv) { AjPSeq a; AjPFile outf; AjPStr codestr; AjPCod codon; AjPStr substr; AjPRange range; AjBool isrule; AjBool isp; AjBool isn; AjPStr pro; ajint beg; ajint end; ajint len; ajint width; char *ruler; ajint *ppos = NULL; ajint *npos = NULL; ajint gcode; embInit("prettyseq", argc, argv); a = ajAcdGetSeq("sequence"); codestr = ajAcdGetListSingle("table"); width = ajAcdGetInt("width"); range = ajAcdGetRange("range"); outf = ajAcdGetOutfile("outfile"); isrule = ajAcdGetBoolean("ruler"); isp = ajAcdGetBoolean("plabel"); isn = ajAcdGetBoolean("nlabel"); ajStrToInt(codestr, &gcode); codon = ajCodNewCodenum(gcode); beg = ajSeqGetBegin(a); end = ajSeqGetEnd(a); substr = ajStrNew(); ajStrAssignSubC(&substr,ajSeqGetSeqC(a),beg-1,end-1); ajStrFmtUpper(&substr); pro=ajStrNewS(substr); len = ajStrGetLen(substr); AJCNEW(ruler, len); AJCNEW(npos, len); AJCNEW(ppos, len); prettyseq_Translate(beg,end,&substr,codon,range,&pro); prettyseq_makeRuler(len,beg,ruler,npos); prettyseq_calcProteinPos(ppos,pro,len); prettyseq_showTrans(ppos,npos,pro,substr,len,ruler,beg, outf,isrule,isp,isn,width,ajSeqGetNameC(a)); AJFREE(npos); AJFREE(ppos); AJFREE(ruler); ajStrDel(&substr); ajCodDel(&codon); ajRangeDel(&range); ajSeqDel(&a); ajFileClose(&outf); ajStrDel(&codestr); ajStrDel(&pro); embExit(); return 0; } /* @funcstatic prettyseq_Translate ******************************************** ** ** Undocumented. ** ** @param [r] beg [ajint] start position ** @param [r] end [ajint] end position ** @param [u] s [AjPStr*] nucleic acid sequence (regions to be case converted) ** @param [r] codon [const AjPCod] translation CU table ** @param [r] range [const AjPRange] region to translate ** @param [w] pro [AjPStr*] protein ** @@ ******************************************************************************/ static void prettyseq_Translate(ajint beg, ajint end, AjPStr *s, const AjPCod codon, const AjPRange range, AjPStr* pro) { ajuint limit; ajuint i; ajuint j; ajuint nr; ajuint st; ajuint en; char *p; char *q; char c; char tri[4]; ajint idx; tri[3]='\0'; /* Convert ranges to subsequence values */ nr = ajRangeGetSize(range); for(i=0;istart[i] -= beg; range->end[i] -= beg; } limit = ajStrGetLen(*s); /* Test ranges for validity */ for(i=0;istart[i]; en = range->end[i]; if(st>=limit || en>=limit) ajFatal("Range outside length of sequence [%d-%d]",st+beg, end+beg); } /* Set areas of sequence to translate to lower case */ p = ajStrGetuniquePtr(s); for(i=0;iaa[idx]==27) c = '*'; else c = (char)(codon->aa[idx]+'A'); } q[i] = c; q[i+1] = q[i+2] = ' '; i += 2; } j = ajStrGetLen(*s)-limit; while(j--) q[i++] = ' '; return; } /* @funcstatic prettyseq_makeRuler ******************************************** ** ** Create a ruler ** ** @param [r] len [ajint] length for ruler ** @param [r] begin [ajint] numbering start ** @param [w] ruler [char*] ruler ** @param [w] npos [ajint*] numbering ** @@ ******************************************************************************/ static void prettyseq_makeRuler(ajint len, ajint begin, char *ruler, ajint *npos) { ajint i; for(i=0;iend) break; continue; } b = v-POFF; break; } pos = end; while(pos>=start) { if(!(v=ppos[pos])) { --pos; continue; } if(v>POFF) v -= POFF; else while(ppos[pos]==v) { --pos; if(pos