Beispiel #1
0
AjBool gFormatGenbank(AjPSeq seq, AjPStr *inseq){
  AjPSeqout     seqout   = NULL;
  AjPFeattabOut featout  = NULL;
  AjPFeattable  feat     = NULL;
  AjPStr        seqline  = NULL;
  AjPStr        featline = NULL;
  AjPFile       seqfile  = NULL;
  AjPFile       featfile = NULL;
  AjPStr        filename = NULL;

  gAssignUniqueName(&filename);
  feat = ajSeqGetFeatCopy(seq);

  if(!feat)
    return ajFalse;

  seqout = ajSeqoutNew();

  if(!ajSeqoutOpenFilename(seqout,filename))
    embExitBad();

  ajSeqoutSetFormatS(seqout,ajStrNewC("genbank"));
  ajSeqoutWriteSeq(seqout,seq);
  ajSeqoutClose(seqout);
  ajSeqoutDel(&seqout);

  seqfile = ajFileNewInNameS(filename);
  ajSysFileUnlinkS(filename);

  featout = ajFeattabOutNew();

  if(!ajFeattabOutOpen(featout,filename))
    return ajFalse;

  ajFeattableWriteGenbank(featout,feat);

  ajFeattableDel(&feat);
  //ajFeattabOutDel(&featout);
  ajFileClose(&(featout->Handle));

  featfile = ajFileNewInNameS(filename);
  ajSysFileUnlinkS(filename);

  while(ajReadline(seqfile,&seqline)){
    if(ajStrMatchC(seqline,"ORIGIN\n")){
      while(ajReadline(featfile,&featline)){
	ajStrAppendS(inseq, featline);
      }
    }
    ajStrAppendS(inseq, seqline);
  }

  ajStrDel(&seqline);
  ajStrDel(&featline);
  ajStrDel(&filename);
  ajFileClose(&seqfile);
  ajFileClose(&featfile);

  return ajTrue;
}
Beispiel #2
0
static void splitter_AddSubSeqFeat(AjPFeattable ftable, ajuint start,
                                   ajuint end, const AjPSeq oldseq)
{
    AjPFeattable old_feattable = NULL;
    AjIList iter = NULL;

    old_feattable = ajSeqGetFeatCopy(oldseq);

    if(!old_feattable)
        return;

    iter = ajListIterNewread(old_feattable->Features);

    while(!ajListIterDone(iter))
    {
        AjPFeature gf = ajListIterGet(iter);

        AjPFeature copy = NULL;


        if (((ajFeatGetEnd(gf) < start + 1) &&
             (gf->End2 == 0 || gf->End2 < start + 1)) ||
            ((ajFeatGetStart(gf) > end + 1) &&
             (gf->Start2 == 0 || gf->Start2 > end + 1)))
        {
            continue;
        }

        copy = ajFeatNewFeat(gf);
        copy->Start = copy->Start - start;
        copy->End = copy->End - start;

        if (copy->Start2 > 0)
            copy->Start2 = copy->Start2 - start;

        if (copy->End2 > 0)
            copy->End2 = copy->End2 - start;

        ajFeatTrimOffRange (copy, 0, 1, end - start + 1, AJTRUE, AJTRUE);

        ajFeattableAdd(ftable, copy);
    }

    ajFeattableDel(&old_feattable);
    ajListIterDel(&iter);

    return;
}
Beispiel #3
0
int main(int argc, char **argv)
{
    AjPSeqall seqall;
    AjPSeqout seqout;
    AjPSeq seq;
    ajint before;
    ajint after;
    AjBool join;
    AjPFeattable featab;
    AjBool featinname;
    AjPStr describe;

    /* feature filter criteria */
    AjPStr source = NULL;
    AjPStr feattype   = NULL;
    ajint sense;
    float minscore;
    float maxscore;
    AjPStr tag  = NULL;
    AjPStr value = NULL;
    AjBool testscore = AJFALSE;

    embInit("extractfeat", argc, argv);
    
    seqall     = ajAcdGetSeqall("sequence");
    seqout     = ajAcdGetSeqout("outseq");
    before     = ajAcdGetInt("before");
    after      = ajAcdGetInt("after");
    join       = ajAcdGetBoolean("join");
    featinname = ajAcdGetBoolean("featinname");
    describe   = ajAcdGetString("describe");
    
    /* feature filter criteria */
    source   = ajAcdGetString("source");
    feattype = ajAcdGetString("type");
    sense    = ajAcdGetInt("sense");
    minscore = ajAcdGetFloat("minscore");
    maxscore = ajAcdGetFloat("maxscore");
    tag      = ajAcdGetString("tag");
    value    = ajAcdGetString("value");
    
    testscore = (minscore || maxscore);
    if(minscore && !maxscore)
        if(minscore > maxscore)
            maxscore = minscore;
    if(!minscore && maxscore)
        if(minscore > maxscore)
            minscore = maxscore;

    while(ajSeqallNext(seqall, &seq))
    {
	/* get the feature table of the sequence */
	featab = ajSeqGetFeatCopy(seq);

        /* delete features in the table that don't match our criteria */
        extractfeat_FeatureFilter(featab, source, feattype, sense,
				  testscore, minscore, maxscore, tag, value);

        /* extract the features */
        extractfeat_FeatSeqExtract(seq, seqout, featab, before,
				   after, join, featinname, describe);

        ajFeattableDel(&featab);

    }
    
    ajSeqoutClose(seqout);
    
    ajSeqoutDel(&seqout);
    ajSeqallDel(&seqall);
    ajSeqDel(&seq);

    ajStrDel(&describe);
    ajStrDel(&source);
    ajStrDel(&feattype);
    ajStrDel(&tag);
    ajStrDel(&value);

    embExit();

    return 0;
}