コード例 #1
0
ファイル: prosextract.c プロジェクト: WenchaoLin/JAMg
int main(int argc, char **argv)
{
    AjPFile infdat = NULL;
    AjPFile infdoc = NULL;
    AjPFile outf   = NULL;
    AjPFile outs   = NULL;

    AjBool  haspattern;

    const char   *p;


    AjPStr line  = NULL;
    AjPStr text  = NULL;
    AjPStr dirname  = NULL;
    AjPStr filename = NULL;
    AjPStr id    = NULL;
    AjPStr ac    = NULL;
    AjPStr de    = NULL;
    AjPStr pa    = NULL;
    AjPStr ps    = NULL;
    AjPStr fn    = NULL;
    AjPStr re    = NULL;
    AjPStr fname = NULL;
    AjBool flag;
    AjBool isopen;
    AjBool goback;

    ajlong storepos = 0L;


    embInit("prosextract", argc, argv);

    dirname = ajAcdGetDirectoryName("prositedir");

    line = ajStrNew();
    text = ajStrNew();

    id = ajStrNew();
    ac = ajStrNew();
    de = ajStrNew();
    pa = ajStrNew();
    ps = ajStrNew();



    fn=ajStrNew();
    ajStrAssignS(&fn,dirname);
    ajStrAppendC(&fn,"prosite.dat");
    if(!(infdat=ajFileNewInNameS(fn)))
	ajFatal("Cannot open file %S",fn);
    ajStrDel(&fn);



    fn=ajStrNewC("PROSITE/prosite.lines");
    outf = ajDatafileNewOutNameS(fn);
    ajStrDel(&fn);



    haspattern = ajFalse;

    while(ajReadlineTrim(infdat, &line) )
    {
	if(ajStrPrefixC(line, "ID"))
	{
	    if(ajStrSuffixC(line,"PATTERN."))
	    {
		haspattern = ajTrue;
		/*save id*/
		p = ajStrGetPtr(line);
		p = ajSysFuncStrtok(p," \t;");
		p = ajSysFuncStrtok(NULL," \t;");
		ajStrAssignC(&id,p);
		ajFmtPrintF(outf, "%S ", id);
		continue;
	    }
	    else
	    {
		haspattern = ajFalse;
		continue;
	    }
	}

	if(!haspattern)
	    continue;


	if(ajStrPrefixC(line, "AC") )
	{
	    p = ajStrGetPtr(line);
	    p = ajSysFuncStrtok(p, " \t;");
	    p = ajSysFuncStrtok(NULL, " \t;");
	    ajStrAssignC(&ac,p);
	    ajFmtPrintF(outf, "%S\n ", ac);
	    continue;
	}

    	if(ajStrPrefixC(line, "DE") )
	{
	    p = ajStrGetPtr(line);
	    p = ajSysFuncStrtok(p, " \t.");
	    p = ajSysFuncStrtok(NULL, " \t.");
	    ajStrAssignC(&de,p);
	    ajFmtPrintF(outf, "%S\n ", de);
	    continue;
	}


	if(ajStrPrefixC(line, "PA"))
	{
	    ajStrAssignC(&pa,"");

	    while(ajStrPrefixC(line,"PA"))
	    {
		p = ajStrGetPtr(line);
		p = ajSysFuncStrtok(p, " \t.");
		p = ajSysFuncStrtok(NULL, " \t.");
		ajStrAppendC(&pa,p);
		ajReadlineTrim(infdat, &line);
	    }

	    ajFmtPrintF(outf, "%S\n", pa);
	    re = embPatPrositeToRegExp(pa);
	    ajFmtPrintF(outf, "^%S\n\n", re);
	    ajStrDel(&re);
	    continue;
	}
    }


  /* Finished processing prosite.dat so look at prosite.doc */


    fn = ajStrNew();
    ajStrAssignS(&fn,dirname);
    ajStrAppendC(&fn,"prosite.doc");
    if(!(infdoc=ajFileNewInNameS(fn)))
	ajFatal("Cannot open file %S",fn);
    ajStrDel(&fn);



    fname  = ajStrNewC("PROSITE/");
    flag   = ajFalse;
    isopen = ajFalse;
    goback = ajFalse;


    while(ajReadlineTrim(infdoc, &text))
    {
	if(ajStrPrefixC(text, "{PS") && isopen && !goback)
	    goback = ajTrue;

	if(ajStrPrefixC(text, "{PS") && !isopen)
	{
	    storepos = ajFileResetPos(infdoc);
	    /* save out the documentation text to acc numbered outfiles . */
	    p = ajStrGetPtr(text)+1;
	    p = ajSysFuncStrtok(p, ";");
	    ajStrAssignS(&filename, fname);
	    ajStrAppendC(&filename, p);

	    outs = ajDatafileNewOutNameS(filename);
	    flag   = ajTrue;
	    isopen = ajTrue;
	    continue;
	}


	if(ajStrPrefixC(text, "{BEGIN}") && flag)
	{
	    while(ajReadlineTrim(infdoc, &text))
	    {
		if(ajStrPrefixC(text,"{END}"))
		    break;

		ajFmtPrintF(outs, "%S\n", text);
	    }
	    ajFileClose(&outs);
	    isopen = ajFalse;

	    if(goback)
	    {
		goback = ajFalse;
		ajFileSeek(infdoc,storepos,0);
	    }

	}
    }

    ajStrDel(&line);
    ajStrDel(&text);
    ajStrDel(&dirname);
    ajStrDel(&filename);

    ajStrDel(&id);
    ajStrDel(&ac);
    ajStrDel(&de);
    ajStrDel(&pa);
    ajStrDel(&re);
    ajStrDel(&ps);
    ajStrDel(&fname);


    ajFileClose(&infdat);
    ajFileClose(&infdoc);
    ajFileClose(&outf);

    embExit();

    return 0;
}
コード例 #2
0
ファイル: newcoils.c プロジェクト: WenchaoLin/JAMg
/* @funcstatic newcoils_read_matrix *******************************************
**
** Reads the matrix and stores in a hept_pref structure
**
** @param [u] inf [AjPFile] matrix input file
** @return [struct hept_pref*] Matrix data for heptad preference
******************************************************************************/
static struct hept_pref* newcoils_read_matrix(AjPFile inf)
{
    ajint i;
    ajint j;
    ajint pt;
    ajint aa_len;
    ajint win;

    float m_g;
    float sd_g;
    float m_cc;
    float sd_cc;
    float sc;
    float hept[NCHEPTAD];

    AjPStr buff;
    const char   *pbuff;
    
    struct hept_pref *h;


    buff = ajStrNew();

    aa_len = strlen(NCAAs);

    AJNEW(h);
    AJCNEW(h->m,aa_len);

    for(i=0; i<aa_len; ++i)
    {
	AJCNEW(h->m[i],NCHEPTAD);
	for(j=0; j<NCHEPTAD; ++j)
	    h->m[i][j] = -1;
    }

    AJNEW(h->f);

    h->n = 0;
    h->smallest = 1.0;

    while(ajReadlineTrim(inf,&buff))
    {
	pbuff = ajStrGetPtr(buff);
	if(*pbuff != '%')
	{
	    if((strncmp(pbuff,"uw ",3)==0) || (strncmp(pbuff,"w ",2)==0))
	    {
		i = h->n;
		if(strncmp(pbuff,"uw ",3)==0)
		    h->f[i].w = 0;
		else
		    h->f[i].w = 1;

		ajFmtScanS(buff,"%*s %d %f %f %f %f %f",&win,&m_cc,
			   &sd_cc,&m_g,&sd_g,&sc);

		h->f[i].win   = win;
		h->f[i].m_cc  = (float)m_cc; 
		h->f[i].sd_cc = (float)sd_cc;
		h->f[i].m_g   = (float)m_g;
		h->f[i].sd_g  = (float)sd_g;
		h->f[i].sc    = (float)sc;
		h->n++;

		AJCRESIZE(h->f,(h->n)+1);
		
		if((h->n)>=9)
		    ajFatal("Too many window parms in matrix file\n");

	    }
	    else if(*pbuff>='A' && *pbuff<='Z')
	    {
		/* AA data */
		pt = (int)(pbuff[0]-'A');
		if(h->m[pt][0]==-1)
		{
		    ajFmtScanS(buff,"%*s%f%f%f%f%f%f%f",&hept[0],
			       &hept[1],&hept[2],&hept[3],&hept[4],
			       &hept[5],&hept[6]);

		    for(i=0; i<NCHEPTAD; ++i)
		    {
			h->m[pt][i] = (float)hept[i];
			if(h->m[pt][i]>0)
			{
			    if(h->m[pt][i]<h->smallest)
				h->smallest = h->m[pt][i];
			}
			else
			    h->m[pt][i]=-1; /* Don't permit zero values */
		    }

		}
		else
		    ajWarn("multiple entries for AA %c in matrix file\n",
			   *pbuff);
	    }
	    else
	    {
		ajWarn("strange characters in matrix file\n");
		ajWarn("Ignoring line: %S\n",buff);
	    }
	}
    }


    ajStrDel(&buff);

    return h;
}
コード例 #3
0
int main(int argc, char **argv) {

  embInitPV("kclustalw", argc, argv, "KBWS", "1.0.8");

  struct soap soap;
  struct ns1__clustalwInputParams params;
  char* jobid;
  char* result;

  AjPSeqall  seqall;
  AjPSeq     seq;
  AjPFile    outf;
  AjPFile    outf_dnd;
  AjPStr     substr;
  AjPStr     inseq = NULL;
  AjPStr     alignment;
  AjPStr     output;
  AjPStr     matrix;
  AjPStr     outorder;
  ajint      ktup;
  ajint      window;
  ajint      gapopen;
  float      gapext;
  ajint      gapdist;
  AjBool     endgaps;
  ajint      pairgap;
  ajint      topdiags;
  AjPStr     score;
  AjBool     tossgaps;
  AjBool     kimura;
  AjPStr     outputtree;
  AjBool     tree;
  AjBool     quicktree;
  AjBool     align;
  AjPStr     clustering;
  ajint      numiter;
  AjPStr     iteration;
  alignment  = ajAcdGetString("alignment");
  output     = ajAcdGetString("output");
  matrix     = ajAcdGetString("matrix");
  outorder   = ajAcdGetString("outorder");
  ktup       = ajAcdGetInt("ktup");
  window     = ajAcdGetInt("window");
  gapopen    = ajAcdGetInt("gapopen");
  gapext     = ajAcdGetFloat("gapext");
  gapdist    = ajAcdGetInt("gapdist");
  endgaps    = ajAcdGetBoolean("endgaps");
  pairgap    = ajAcdGetInt("pairgap");
  topdiags   = ajAcdGetInt("topdiags");
  score      = ajAcdGetString("score");
  tossgaps   = ajAcdGetBoolean("tossgaps");
  kimura     = ajAcdGetBoolean("kimura");
  outputtree = ajAcdGetString("outputtree");
  tree       = ajAcdGetBoolean("tree");
  quicktree  = ajAcdGetBoolean("quicktree");
  align      = ajAcdGetBoolean("align");
  clustering = ajAcdGetString("clustering");
  numiter    = ajAcdGetInt("numiter");
  iteration  = ajAcdGetString("iteration");

  seqall = ajAcdGetSeqall("seqall");
  outf   = ajAcdGetOutfile("outfile");
  outf_dnd = ajAcdGetOutfile("dndoutfile");
  params.alignment = ajCharNewS(alignment);
  params.output = ajCharNewS(output);
  params.matrix = ajCharNewS(matrix);
  params.outorder = ajCharNewS(outorder);
  params.ktup = ktup;
  params.window = window;
  params.gapopen = gapopen;
  params.gapext = gapext;
  params.gapdist = gapdist;
  if (endgaps) {
    params.endgaps = xsd__boolean__true_;
  } else {
    params.endgaps = xsd__boolean__false_;
  }
  params.pairgap = pairgap;
  params.topdiags = topdiags;
  params.score = ajCharNewS(score);

  if (tossgaps) {
    params.tossgaps = xsd__boolean__true_;
  } else {
    params.tossgaps = xsd__boolean__false_;
  }
  if (kimura) {
    params.kimura = xsd__boolean__true_;
  } else {
    params.kimura = xsd__boolean__false_;
  }
  params.outputtree = ajCharNewS(outputtree);
  if (tree) {
    params.tree = xsd__boolean__true_;
  } else {
    params.tree = xsd__boolean__false_;
  }
  if (quicktree) {
    params.quicktree = xsd__boolean__true_;
  } else {
    params.quicktree = xsd__boolean__false_;
  }
  if (align) {
    params.align = xsd__boolean__true_;
  } else {
    params.align = xsd__boolean__false_;
  }
  params.clustering = ajCharNewS(clustering);
  params.numiter = numiter;
  params.iteration = ajCharNewS(iteration);

  AjPStr     tmp = NULL;
  AjPStr     tmpFileName = NULL;
  AjPSeqout  fil_file;
  AjPStr     line = NULL; /* if "AjPStr line; -> ajReadline is not success!" */
  AjPStr sizestr = NULL;
  ajint thissize;

  ajint      nb = 0;
  AjBool     are_prot = ajFalse;
  ajint      size = 0;
  AjPFile    infile;

  tmp = ajStrNewC("fasta");

  fil_file = ajSeqoutNew();
  tmpFileName = getUniqueFileName();

  if( !ajSeqoutOpenFilename(fil_file, tmpFileName) ) {
    embExitBad();
  }

  ajSeqoutSetFormatS(fil_file, tmp);

  while (ajSeqallNext(seqall, &seq)) {
    if (!nb) {
      are_prot  = ajSeqIsProt(seq);
    }
    ajSeqoutWriteSeq(fil_file, seq);
    ++nb;
  }
  ajSeqoutClose(fil_file);
  ajSeqoutDel(&fil_file);

  if (nb < 2) {
    ajFatal("Multiple alignments need at least two sequences");
  }

  infile = ajFileNewInNameS(tmpFileName);

  while (ajReadline(infile, &line)) {
    ajStrAppendS(&inseq,line);
    ajStrAppendC(&inseq,"\n");
  }

  soap_init(&soap);

  char* in0;
  in0 = ajCharNewS(inseq);
  if ( soap_call_ns1__runClustalw( &soap, NULL, NULL, in0, &params, &jobid ) == SOAP_OK ) {
    fprintf(stderr,"Jobid: %s\n",jobid);
  } else {
    soap_print_fault(&soap, stderr);
  }

  int check = 0;
  while ( check == 0 ) {
    if ( soap_call_ns1__checkStatus( &soap, NULL, NULL, jobid,  &check ) == SOAP_OK ) {
      fprintf(stderr,"*");
    } else {
      soap_print_fault(&soap, stderr);
    }
    sleep(3);
  }
  fprintf(stderr,"\n");

  char* type;

  type = "out";
  if(soap_call_ns1__getMultiResult( &soap, NULL, NULL, jobid, type, &result )== SOAP_OK) {
    substr = ajStrNewC(result);
    fprintf(stdout, "%s\n", ajStrGetPtr(substr));
  } else {
    soap_print_fault(&soap, stderr);
  }

  type = "aln";
  if(soap_call_ns1__getMultiResult( &soap, NULL, NULL, jobid, type, &result )== SOAP_OK) {
    substr = ajStrNewC(result);
    ajFmtPrintF(outf,"%S\n",substr);
  } else {
    soap_print_fault(&soap, stderr); 
  }

  type = "dnd";
  if(soap_call_ns1__getMultiResult( &soap, NULL, NULL, jobid, type, &result )== SOAP_OK) {
    substr = ajStrNewC(result);
    ajFmtPrintF(outf_dnd,"%S\n",substr);
  } else {
    soap_print_fault(&soap, stderr); 
  }


  ajSysFileUnlinkS(tmpFileName);

  soap_destroy(&soap);
  soap_end(&soap);
  soap_done(&soap);

  ajFileClose(&outf_dnd);

  ajFileClose(&outf);

  ajSeqallDel(&seqall);
  ajSeqDel(&seq);
  ajStrDel(&substr);

  embExit();

  return 0;
}
コード例 #4
0
int main(int argc, char **argv)
{
    AjPStr    cl     = NULL;
    AjPSeqset seqset = NULL;
    AjPSeqout seqout = NULL;
    
    AjPStr    stmp   = NULL;
    AjPStr    email  = NULL;
    AjPStr    fmt    = NULL;
    AjPStr    trtab  = NULL;
    const AjPStr ofn = NULL;
    
    AjPStr    *applist = NULL;

    
    AjBool crc = ajFalse;
    AjBool alt = ajFalse;

    AjBool iprlook = ajFalse;
    AjBool goterms = ajFalse;
    
    ajint trlen = 0;
    
    
    ajuint i    = 0;
    ajuint lcnt = 0;
    
    
    AjPStr fn = NULL;
    AjPFile outf = NULL;
    
    
    embInitPV("eiprscan", argc, argv, "IPRSCAN", VERSION);


    seqset  = ajAcdGetSeqset("sequence");
    email   = ajAcdGetString("email");
    crc     = ajAcdGetBoolean("crc");
    applist = ajAcdGetList("appl");
    fmt     = ajAcdGetListSingle("format");
    trtab   = ajAcdGetListSingle("trtable");
    trlen   = ajAcdGetInt("trlen");
    alt     = ajAcdGetBoolean("altjobs");
    iprlook = ajAcdGetBoolean("iprlookup");
    goterms = ajAcdGetBoolean("goterms");
    outf    = ajAcdGetOutfile("outfile");
    
    stmp = ajStrNew();
    cl   = ajStrNewC("iprscan -cli");
    fn   = ajStrNew();
    


    ajFilenameSetTempname(&fn);
    seqout = ajSeqoutNew();
    if(!ajSeqoutOpenFilename(seqout, fn))
	ajFatal("Cannot open temporary file %S",fn);
    ajSeqoutSetFormatC(seqout, "fasta");
    ajSeqoutWriteSet(seqout,seqset);
    ajSeqoutClose(seqout);

    ajFmtPrintS(&stmp," -i %S",fn);
    ajStrAppendS(&cl,stmp);

    if(!ajSeqsetIsProt(seqset))
        ajStrAppendC(&cl," -seqtype n");

    if(!crc)
        ajStrAppendC(&cl," -nocrc");

    if(ajStrGetLen(email))
    {
        ajFmtPrintS(&stmp," -email %S",email);
        ajStrAppendS(&cl,stmp);
    }
    

    i = 0;
    lcnt = 0;
    
    while(applist[i])
    {
        ++lcnt;
        ++i;
    }
    

    i = 0;
    while(applist[i])
    {
        if(ajStrMatchC(applist[i],"all"))
        {
            if(lcnt != 1)
                ajFatal("Cannot specify 'all' with multiple "
                        "applications");
            ++i;
            continue;
        }
        
        ajFmtPrintS(&stmp," -appl %S",applist[i]);
        ajStrAppendS(&cl,stmp);
        ++i;
    }
    
    ajFmtPrintS(&stmp," -format %S",fmt);
    ajStrAppendS(&cl,stmp);



    ajFmtPrintS(&stmp," -trtable %S",trtab);
    ajStrAppendS(&cl,stmp);

    ajFmtPrintS(&stmp," -trlen %d",trlen);
    ajStrAppendS(&cl,stmp);

    if(alt)
        ajStrAppendC(&cl," -altjobs");

    if(iprlook)
        ajStrAppendC(&cl," -iprlookup");

    if(goterms)
        ajStrAppendC(&cl," -goterms");


    ofn = ajFileGetNameS(outf);
    ajFmtPrintS(&stmp," -o %S",ofn);
    ajFileClose(&outf);
    ajStrAppendS(&cl,stmp);

    
#if 0
   ajFmtPrint("%S\n",cl);
#endif

#if 1
    system(ajStrGetPtr(cl));
#endif


    ajSysFileUnlink(fn);
    
    
    ajStrDel(&cl);
    ajStrDel(&fn);
    ajStrDel(&stmp);
    ajStrDel(&email);
    ajStrDel(&fmt);
    ajStrDel(&trtab);
    ajStrDelarray(&applist);
    ajSeqoutDel(&seqout);
    ajSeqsetDel(&seqset);
    
    embExit();

    return 0;
}
コード例 #5
0
int main(int argc, char **argv)
{
    AjPSeqall seqall;
    AjPSeq seq   = NULL;
    AjPFile inf  = NULL;

    AjPStr strand = NULL;
    AjPStr substr = NULL;
    AjPStr name   = NULL;
    AjPStr mname  = NULL;
    AjPStr tname  = NULL;
    AjPStr pname  = NULL;
    AjPStr line   = NULL;
    AjPStr cons   = NULL;
    AjPStr m      = NULL;
    AjPStr n      = NULL;

    AjPAlign align= NULL; /* JISON, replaces AjPOutfile outf */
    
    ajint type;
    ajint begin;
    ajint end;
    ajulong len;
    ajint i;
    ajint j;

    float **fmatrix=NULL;

    ajint mlen;
    float maxfs;
    ajint thresh;

    float gapopen;
    float gapextend;
    float opencoeff;
    float extendcoeff;

    const char *p;

    ajulong maxarr = 1000;
    ajulong alen;
    float *path;
    ajint *compass;
    size_t stlen;

    embInit("prophet", argc, argv);

    seqall      = ajAcdGetSeqall("sequence");
    inf         = ajAcdGetInfile("infile");
    opencoeff   = ajAcdGetFloat("gapopen");
    extendcoeff = ajAcdGetFloat("gapextend");
    align       = ajAcdGetAlign("outfile");  /*JISON replacing outfile */

    opencoeff   = ajRoundFloat(opencoeff, 8);
    extendcoeff = ajRoundFloat(extendcoeff, 8);

    substr = ajStrNew();
    name   = ajStrNew();
    mname  = ajStrNew();
    tname  = ajStrNew();
    line   = ajStrNew();
    m      = ajStrNewC("");
    n      = ajStrNewC("");

    type = prophet_getType(inf,&tname);
    if(!type)
      ajFatal("Unrecognised profile/matrix file format");

    prophet_read_profile(inf,&pname,&mname,&mlen,&gapopen,&gapextend,&thresh,
			 &maxfs, &cons);
    ajAlignSetMatrixName(align, mname);
    AJCNEW(fmatrix, mlen);

    for(i=0;i<mlen;++i)
    {
	AJCNEW(fmatrix[i], AZ);
	if(!ajReadlineTrim(inf,&line))
	    ajFatal("Missing matrix line");
	p = ajStrGetPtr(line);
	p = ajSysFuncStrtok(p," \t");
	for(j=0;j<AZ;++j)
	{
	    sscanf(p,"%f",&fmatrix[i][j]);
	    p = ajSysFuncStrtok(NULL," \t");
	}
    }

    AJCNEW(path, maxarr);
    AJCNEW(compass, maxarr);

    while(ajSeqallNext(seqall, &seq))
    {
	begin = ajSeqallGetseqBegin(seqall);
	end   = ajSeqallGetseqEnd(seqall);

	ajStrAssignC(&name,ajSeqGetNameC(seq));
	strand = ajSeqGetSeqCopyS(seq);

	ajStrAssignSubC(&substr,ajStrGetPtr(strand),begin-1,end-1);
	len = ajStrGetLen(substr);

	if(len > (ULONG_MAX/(ajulong)(mlen+1)))
	    ajFatal("Sequences too big. Try 'supermatcher'");

	alen = len*mlen;
	if(alen>maxarr)
	{
	    stlen = (size_t) alen;
	    AJCRESIZE(path,stlen);
	    AJCRESIZE(compass,stlen);
	    maxarr=alen;
	}

	ajStrAssignC(&m,"");
	ajStrAssignC(&n,"");

	/* JISON used to be
	prophet_scan_profile(substr,pname,name,mlen,fmatrix,
			     outf,cons,opencoeff,
			     extendcoeff,path,compass,&m,&n,len); */

	/* JISON new call and reset align */
	prophet_scan_profile(substr,name,pname,mlen,fmatrix,
			     align,cons,opencoeff,
			     extendcoeff,path,compass,&m,&n,(ajint)len); 
	ajAlignReset(align);
	
	ajStrDel(&strand);
    }

    for(i=0;i<mlen;++i)
	AJFREE (fmatrix[i]);
    AJFREE (fmatrix);

    AJFREE(path);
    AJFREE(compass);

    ajStrDel(&line);
    ajStrDel(&cons);
    ajStrDel(&name);
    ajStrDel(&pname);
    ajStrDel(&mname);
    ajStrDel(&tname);
    ajStrDel(&substr);
    ajStrDel(&m);
    ajStrDel(&n);
    ajSeqDel(&seq);
    ajFileClose(&inf);

    ajAlignClose(align);
    ajAlignDel(&align);
    ajSeqallDel(&seqall);
    embExit();

    return 0;
}
コード例 #6
0
static void prophet_read_profile(AjPFile inf, AjPStr *name, AjPStr *mname,
				 ajint *mlen, float *gapopen,
				 float *gapextend, ajint *thresh,
				 float *maxs, AjPStr *cons)
{
    const char *p;
    AjPStr line = NULL;

    line = ajStrNew();

    if(!ajReadlineTrim(inf,&line))
	ajFatal("Premature EOF in profile file");
    p = ajStrGetPtr(line);

    if(strncmp(p,"Name",4))
	ajFatal("Incorrect profile/matrix file format");

    p = ajSysFuncStrtok(p," \t");
    p = ajSysFuncStrtok(NULL," \t");
    ajStrAssignC(name,p);

    if(!ajReadlineTrim(inf,&line))
	ajFatal("Premature EOF in profile file");

    p = ajStrGetPtr(line);
    if(strncmp(p,"Matrix",6))
	ajFatal("Incorrect profile/matrix file format");
    p = ajSysFuncStrtok(p," \t");
    p = ajSysFuncStrtok(NULL," \t");
    ajStrAssignC(mname,p);


    if(!ajReadlineTrim(inf,&line))
	ajFatal("Premature EOF in profile file");
    p = ajStrGetPtr(line);

    if(strncmp(p,"Length",6))
	ajFatal("Incorrect profile/matrix file format");
    sscanf(p,"%*s%d",mlen);

    if(!ajReadlineTrim(inf,&line))
	ajFatal("Premature EOF in profile file");
    p = ajStrGetPtr(line);

    if(strncmp(p,"Max_score",9))
	ajFatal("Incorrect profile/matrix file format");
    sscanf(p,"%*s%f",maxs);

    if(!ajReadlineTrim(inf,&line))
	ajFatal("Premature EOF in profile file");
    p = ajStrGetPtr(line);

    if(strncmp(p,"Threshold",9))
	ajFatal("Incorrect profile/matrix file format");
    sscanf(p,"%*s%d",thresh);


    if(!ajReadlineTrim(inf,&line))
	ajFatal("Premature EOF in profile file");
    p = ajStrGetPtr(line);

    if(strncmp(p,"Gap_open",8))
	ajFatal("Incorrect profile/matrix file format");
    sscanf(p,"%*s%f",gapopen);

    if(!ajReadlineTrim(inf,&line))
	ajFatal("Premature EOF in profile file");
    p = ajStrGetPtr(line);

    if(strncmp(p,"Gap_extend",10))
	ajFatal("Incorrect profile/matrix file format");
    sscanf(p,"%*s%f",gapextend);

    if(!ajReadlineTrim(inf,&line))
	ajFatal("Premature EOF in profile file");
    p = ajStrGetPtr(line);

    if(strncmp(p,"Consensus",9))
	ajFatal("Incorrect profile/matrix file format");
    p = ajSysFuncStrtok(p," \t\n");
    p = ajSysFuncStrtok(NULL," \t\n");
    ajStrAssignC(cons,p);

    ajStrDel(&line);

    return;
}
コード例 #7
0
int main(int argc, char **argv)
{
    AjPSeqall seqall;
    AjPSeq seq    = NULL;
    AjPFile outf  = NULL;
    AjPStr strand = NULL;
    AjPStr substr = NULL;
    AjPFeattabOut featout;
    AjPFeattable feattable=NULL;
    ajint begin;
    ajint end;
    ajint len;
    ajint score;

    embInit("cpgreport",argc,argv);

    seqall  = ajAcdGetSeqall("sequence");
    score   = ajAcdGetInt("score");
    outf    = ajAcdGetOutfile("outfile");
    featout = ajAcdGetFeatout("outfeat");


    substr = ajStrNew();


    while(ajSeqallNext(seqall, &seq))
    {
	if (!feattable)
	    feattable = ajFeattableNewDna(ajSeqGetNameS(seq));

	begin = ajSeqallGetseqBegin(seqall);
	end   = ajSeqallGetseqEnd(seqall);

	strand = ajSeqGetSeqCopyS(seq);
	ajStrFmtUpper(&strand);

	ajStrAssignSubC(&substr,ajStrGetPtr(strand),begin-1,end-1);

	len=ajStrGetLen(substr);

	ajFmtPrintF(outf,"\n\nCPGREPORT of %s from %d to %d\n\n",
		    ajSeqGetNameC(seq),begin,begin+len-1);
	ajFmtPrintF(outf,"Sequence              Begin    End Score");
	ajFmtPrintF(outf,"        CpG   %%CG  CG/GC\n");

	cpgreport_cpgsearch(outf,0,len,ajStrGetPtr(substr),ajSeqGetNameC(seq),
			    begin,score,feattable);
	ajStrDel(&strand);
    }


    ajSeqDel(&seq);
    ajStrDel(&substr);
    ajFileClose(&outf);

    ajFeatSortByStart(feattable);
    ajFeattableWrite(featout, feattable);
    ajFeattableDel(&feattable);

    ajFeattabOutDel(&featout);
    ajSeqallDel(&seqall);
    ajStrDel(&cpgreportSource);
    ajStrDel(&cpgreportType);

    embExit();

    return 0;
}
コード例 #8
0
int main(int argc, char **argv)
{
    AjPSeqall  seqall;
    AjPSeq  a;
    AjPStr  substr;
    AjPStr  rname;
    ajint be;
    ajint en;
    ajint len;

    AjBool unfavoured;
    AjBool overlap;
    AjBool allpartials;
    AjPStr menu;
    AjPStr rag;
    ajint  n = 0;
    ajint  r = 0;
    
    AjPFile  outf = NULL;
    AjPReport report    = NULL;
    AjPFeattable TabRpt = NULL;
    AjPStr tmpStr = NULL;
    AjPList  l;
    AjPList  pa;
    AjPFile mfptr   = NULL;

    AjBool nterm = ajFalse;
    AjBool cterm = ajFalse;
    AjBool dorag = ajFalse;

    ajint     ncomp;
    ajint     npart;

    EmbPPropMolwt *mwdata = NULL;
    AjBool mono;
    

    embInit("digest", argc, argv);

    seqall      = ajAcdGetSeqall("seqall");
    menu        = ajAcdGetListSingle("menu");
    dorag       = ajAcdGetBoolean("ragging");
    rag         = ajAcdGetListSingle("termini");
    unfavoured  = ajAcdGetBoolean("unfavoured");
    overlap     = ajAcdGetBoolean("overlap");
    allpartials = ajAcdGetBoolean("allpartials");
    report      = ajAcdGetReport("outfile");
    mfptr       = ajAcdGetDatafile("mwdata");
    mono        = ajAcdGetBoolean("mono");
    
    /* obsolete. Can be uncommented in acd file and here to reuse */

    /* outf      = ajAcdGetOutfile("originalfile"); */

    ajStrToInt(menu, &n);
    --n;

    ajStrToInt(rag, &r);

    if(r==2 || r==4)
	nterm = ajTrue;

    if(r==3 || r==4)
	cterm = ajTrue;


    mwdata = embPropEmolwtRead(mfptr);

    while(ajSeqallNext(seqall, &a))
    {
	substr = ajStrNew();
	be     = ajSeqGetBegin(a);
	en     = ajSeqGetEnd(a);
	ajStrAssignSubC(&substr,ajSeqGetSeqC(a),be-1,en-1);
        ajStrFmtUpper(&substr);

	len = en-be+1;

	l     = ajListNew();
	pa    = ajListNew();
	rname = ajStrNew();

	TabRpt = ajFeattableNewSeq(a);

	embPropCalcFragments(ajStrGetPtr(substr),n,&l,&pa,
			     unfavoured,overlap,
			     allpartials,&ncomp,&npart,&rname,
			     nterm, cterm, dorag, mwdata, mono);

	if(outf)
	    ajFmtPrintF(outf,"DIGEST of %s from %d to %d Molwt=%10.3f\n\n",
			ajSeqGetNameC(a),be,en,
			embPropCalcMolwt(ajSeqGetSeqC(a),0,len-1,mwdata,mono));
	if(!ncomp)
	{
	    if(outf)
		ajFmtPrintF(outf,
			    "Is not proteolytically digested using %s\n",
			    ajStrGetPtr(rname));
	}
	else
	{
	    if(outf)
	    {
		ajFmtPrintF(outf,"Complete digestion with %s "
			    "yields %d fragments:\n",
			    ajStrGetPtr(rname),ncomp);
		digest_print_hits(l,outf,be,ajStrGetPtr(substr));
	    }
	    ajFmtPrintS(&tmpStr,
			"Complete digestion with %S yields %d fragments",
			rname,ncomp);
	    ajReportSetHeaderS(report, tmpStr);
	    digest_report_hits(TabRpt,l,be, ajStrGetPtr(substr));
	    ajReportWrite(report, TabRpt, a);
	    ajFeattableClear(TabRpt);
	}

	if(overlap && !allpartials && npart)
	{
	    if(outf)
	    {
		ajFmtPrintF(outf,
			    "\n\nPartial digest with %s yields %d extras.\n",
			    ajStrGetPtr(rname),npart);
		ajFmtPrintF(outf,"Only overlapping partials shown:\n");
		digest_print_hits(pa,outf,be,ajStrGetPtr(substr));
	    }
	    ajFmtPrintS(&tmpStr,
			"\n\nPartial digest with %S yields %d extras.\n",
			rname,npart);
	    ajFmtPrintAppS(&tmpStr,"Only overlapping partials shown:\n");
	    ajReportSetHeaderS(report, tmpStr);
	    digest_report_hits(TabRpt, pa,be,ajStrGetPtr(substr));
	    ajReportWrite(report, TabRpt, a);
	    ajFeattableClear(TabRpt);
	}

	if(allpartials && npart)
	{
	    if(outf)
	    {
		ajFmtPrintF(outf,
			    "\n\nPartial digest with %s yields %d extras.\n",
			    ajStrGetPtr(rname),npart);
		ajFmtPrintF(outf,"All partials shown:\n");
		digest_print_hits(pa,outf,be,ajStrGetPtr(substr));
	    }
	    ajFmtPrintS(&tmpStr,
			"\n\nPartial digest with %S yields %d extras.\n",
			rname,npart);
	    ajFmtPrintAppS(&tmpStr,"All partials shown:\n");
	    ajReportSetHeaderS(report, tmpStr);
	    digest_report_hits(TabRpt, pa,be, ajStrGetPtr(substr));
	    ajReportWrite(report, TabRpt, a);
	    ajFeattableClear(TabRpt);
	}
    }


    embPropMolwtDel(&mwdata);

    ajReportDel(&report);

    ajFeattableDel(&TabRpt);
    
    ajSeqDel(&a);
    ajSeqallDel(&seqall);

    ajStrDel(&rname);
    ajStrDel(&substr);
    ajListFree(&pa);
    ajListFree(&l);
    ajStrDel(&menu);
    ajStrDel(&rag);

    if(outf)
	ajFileClose(&outf);
    ajFileClose(&mfptr);

    ajStrDel(&tmpStr);

    embExit();

    return 0;
}