コード例 #1
0
static AjBool extractfeat_MatchPatternTags(const AjPFeature feat,
					   const AjPStr tpattern,
					   const AjPStr vpattern)
{
    AjIList titer;                      /* iterator for feat */
    AjPStr tagnam = NULL;        /* tag structure */
    AjPStr tagval = NULL;        /* tag structure */
    AjBool val = ajFalse;               /* returned value */
    AjBool tval;                        /* tags result */
    AjBool vval;                        /* value result */


    /*
    **  if there are no tags to match, but the patterns are
    **  both '*', then allow this as a match
    */
    if(!ajStrCmpC(tpattern, "*") &&
        !ajStrCmpC(vpattern, "*"))
        return ajTrue;

    /* iterate through the tags and test for match to patterns */
    titer = ajFeatTagIter(feat);

    while(ajFeatTagval(titer, &tagnam, &tagval))
    {
        tval = embMiscMatchPatternDelimC(tagnam, tpattern, ",;|");

        /*
        ** If tag has no value then
        **   If vpattern is '*' the value pattern is a match
        ** Else check vpattern
        */
        if(!ajStrGetLen(tagval))
	{
            if(!ajStrCmpC(vpattern, "*"))
            	vval = ajTrue;
            else
		vval = ajFalse;
        }
	else
            vval = embMiscMatchPatternDelimC(tagval, vpattern, ",;|");

        if(tval && vval)
	{
            val = ajTrue;
            break;
        }
    }
    ajListIterDel(&titer);

    ajStrDel(&tagnam);
    ajStrDel(&tagval);

    return val;
}
コード例 #2
0
static void eprimer3_report(AjPFile outfile, const AjPStr output,
                            ajint numreturn, ajint begin)
{
    AjPStr line = NULL;
    AjPStrTok linetokenhandle;
    char eol[] = "\n\r";
    AjPStrTok keytokenhandle;
    char equals[] = "=";
    AjPStr key   = NULL;
    AjPStr value = NULL;
    AjBool gotsequenceid = AJFALSE;
    AjPTable table;

    linetokenhandle = ajStrTokenNewC(output, eol);

    /* get next line of relevant results */
    while(ajStrTokenNextParseC(&linetokenhandle, eol, &line))
    {
        if(!gotsequenceid)
        {
            /*
            ** Att the start of another sequence's results?
            ** Start storing the results in the table.
            */

            if(ajStrCmpLenC(line, "PRIMER_SEQUENCE_ID=", 19) == 0)
            {
                gotsequenceid = AJTRUE;
                table = ajTablestrNew(TABLEGUESS);

            }
            else
                continue;
        }
        else
        {
            /*
            ** At the end of this sequence? - marked by a '=' in the primer3
            ** output - then output the results.
            */
            if(ajStrCmpC(line, "=") == 0)
            {
                gotsequenceid = AJFALSE;
                eprimer3_output_report(outfile, table, numreturn, begin);
                ajTablestrFree(&table);
                continue;
            }
        }

        /*
        ** store key and value in table and parse values
        ** when have all of the sequence
        ** results in the table because the LEFT, RIGHT
        ** and INTERNAL results for each
        ** resulting primer are interleaved
        */

        keytokenhandle = ajStrTokenNewC(line, equals);

        key = ajStrNew();
        ajStrTokenNextParse(&keytokenhandle, &key);

        value = ajStrNew();
        ajStrTokenNextParse(&keytokenhandle, &value);

        ajDebug("key=%S\tvalue=%S\n", key, value);

        ajTablePut(table,(void *)key, (void *)value);

        ajStrTokenDel(&keytokenhandle);
    }

    ajStrDel(&line);
    ajStrTokenDel(&linetokenhandle);
    ajTablestrFree(&table);

    return;
}
コード例 #3
0
int main(int argc, char **argv)
{
    /* Global details */
    AjBool explain_flag;
    AjBool file_flag;
    AjPStr* task;
    AjBool do_primer;
    AjBool do_hybrid;
    ajint num_return;
    ajint first_base_index;

    /* "Sequence" Input Tags */
    AjPSeqall sequence;
    AjPRange included_region;
    AjPRange target;
    AjPRange excluded_region;
    AjPStr left_input;
    AjPStr right_input;

    /* Primer details */
    AjBool pick_anyway;
    AjPFile mispriming_library;
    float max_mispriming;
    float pair_max_mispriming;
    ajint gc_clamp;
    ajint opt_size;
    ajint min_size;
    ajint max_size;
    float opt_tm;
    float min_tm;
    float max_tm;
    float max_diff_tm;
    float opt_gc_percent;
    float min_gc;
    float max_gc;
    float salt_conc;
    float dna_conc;
    ajint num_ns_accepted;
    float self_any;
    float self_end;
    ajint max_poly_x;

    /* Sequence Quality. These are not (yet) implemented */
    /*
       AjPFile sequence_quality;
       ajint	min_quality;
       ajint	min_end_quality;
       ajint	quality_range_min;
       ajint	quality_range_max;
       */

    /* Product details */
    ajint product_opt_size;
    AjPRange product_size_range;
    float product_opt_tm;
    float product_min_tm;
    float product_max_tm;

    /* Objective Function Penalty Weights for Primers */
    float max_end_stability;

    /* these are not (yet) implemented */
    /*
       float		inside_penalty;
       float		outside_penalty;
    */

    /* Primer penalties */
    /* these are not (yet) implemented */

    /* Internal Oligo "Sequence" Input Tags */
    AjPRange internal_oligo_excluded_region;

    /* Internal Oligo "Global" Input Tags */
    AjPStr internal_oligo_input;
    ajint internal_oligo_opt_size;
    ajint internal_oligo_min_size;
    ajint internal_oligo_max_size;
    float internal_oligo_opt_tm;
    float internal_oligo_min_tm;
    float internal_oligo_max_tm;
    float internal_oligo_opt_gc_percent;
    float internal_oligo_min_gc;
    float internal_oligo_max_gc;
    float internal_oligo_salt_conc;
    float internal_oligo_dna_conc;
    float internal_oligo_self_any;
    float internal_oligo_self_end;
    ajint internal_oligo_max_poly_x;
    AjPFile internal_oligo_mishyb_library;
    float internal_oligo_max_mishyb;

    /*
       ajint		internal_oligo_min_quality;
    */

    /* Internal Oligo penalties */
    /* these are not (yet) implemented */

    /* EMBOSS-wrapper-specific stuff */
    AjPFile	outfile;

    /* other variables */
    AjPStr result = NULL;
    AjPStr strand = NULL;
    AjPStr substr = NULL;
    AjPSeq seq    = NULL;
    ajint begin   = 0;
    ajint end;
    FILE* stream;
    AjPStr taskstr  = NULL;
    const AjPStr program = NULL;

    /* pipe variables */

    int *pipeto;	  /* pipe to feed the exec'ed program input */
    int *pipefrom;	  /* pipe to get the exec'ed program output */

    embInit("eprimer3", argc, argv);

    /* Global details */
    explain_flag     = ajAcdGetBoolean("explainflag");
    file_flag        = ajAcdGetBoolean("fileflag");
    task             = ajAcdGetList("task");
    do_primer        = ajAcdGetToggle("primer");
    do_hybrid        = ajAcdGetToggle("hybridprobe");
    num_return       = ajAcdGetInt("numreturn");
    first_base_index = ajAcdGetInt("firstbaseindex");

    /* "Sequence" Input Tags */
    sequence        = ajAcdGetSeqall("sequence");
    included_region = ajAcdGetRange("includedregion");
    target          = ajAcdGetRange("targetregion");
    excluded_region = ajAcdGetRange("excludedregion");
    left_input      = ajAcdGetString("forwardinput");
    right_input     = ajAcdGetString("reverseinput");

    /* Primer details */
    pick_anyway         = ajAcdGetBoolean("pickanyway");
    mispriming_library  = ajAcdGetInfile("mispriminglibraryfile");
    max_mispriming      = ajAcdGetFloat("maxmispriming");
    pair_max_mispriming = ajAcdGetFloat("pairmaxmispriming");
    gc_clamp            = ajAcdGetInt("gcclamp");
    opt_size            = ajAcdGetInt("osize");
    min_size            = ajAcdGetInt("minsize");
    max_size            = ajAcdGetInt("maxsize");
    opt_tm              = ajAcdGetFloat("otm");
    min_tm              = ajAcdGetFloat("mintm");
    max_tm              = ajAcdGetFloat("maxtm");
    max_diff_tm         = ajAcdGetFloat("maxdifftm");
    opt_gc_percent      = ajAcdGetFloat("ogcpercent");
    min_gc              = ajAcdGetFloat("mingc");
    max_gc              = ajAcdGetFloat("maxgc");
    salt_conc           = ajAcdGetFloat("saltconc");
    dna_conc            = ajAcdGetFloat("dnaconc");
    num_ns_accepted     = ajAcdGetInt("numnsaccepted");
    self_any            = ajAcdGetFloat("selfany");
    self_end            = ajAcdGetFloat("selfend");
    max_poly_x          = ajAcdGetInt("maxpolyx");

    AJCNEW0(pipeto,2);
    AJCNEW0(pipefrom,2);

    /* Sequence Quality */
    /* these are not (yet) implemented */
    /*
       sequence_quality  = ajAcdGetInfile("sequencequality");
       min_quality       = ajAcdGetInt("minquality");
       min_end_quality   = ajAcdGetInt("minendquality");
       quality_range_min = ajAcdGetInt("qualityrangemin");
       quality_range_max = ajAcdGetInt("qualityrangemax");
       */

    /* Product details */
    product_opt_size    = ajAcdGetInt("psizeopt");
    product_size_range  = ajAcdGetRange("prange");
    product_opt_tm      = ajAcdGetFloat("ptmopt");
    product_min_tm      = ajAcdGetFloat("ptmmin");
    product_max_tm      = ajAcdGetFloat("ptmmax");

    /* Objective Function Penalty Weights for Primers */
    max_end_stability   = ajAcdGetFloat("maxendstability");
    /* these are not (yet) implemented */
    /*
       inside_penalty      = ajAcdGetFloat("insidepenalty");
       outside_penalty     = ajAcdGetFloat("outsidepenalty");
    */

    /* Primer penalties */
    /* these are not (yet) implemented */

    /* Internal Oligo "Sequence" Input Tags */
    internal_oligo_excluded_region = ajAcdGetRange("oexcludedregion");
    internal_oligo_input           = ajAcdGetString("oligoinput");

    /* Internal Oligo "Global" Input Tags */
    internal_oligo_opt_size       = ajAcdGetInt("osizeopt");
    internal_oligo_min_size       = ajAcdGetInt("ominsize");
    internal_oligo_max_size       = ajAcdGetInt("omaxsize");
    internal_oligo_opt_tm         = ajAcdGetFloat("otmopt");
    internal_oligo_min_tm         = ajAcdGetFloat("otmmin");
    internal_oligo_max_tm         = ajAcdGetFloat("otmmax");
    internal_oligo_opt_gc_percent = ajAcdGetFloat("ogcopt");
    internal_oligo_min_gc         = ajAcdGetFloat("ogcmin");
    internal_oligo_max_gc         = ajAcdGetFloat("ogcmax");
    internal_oligo_salt_conc      = ajAcdGetFloat("osaltconc");
    internal_oligo_dna_conc       = ajAcdGetFloat("odnaconc");
    internal_oligo_self_any       = ajAcdGetFloat("oanyself");
    internal_oligo_self_end       = ajAcdGetFloat("oendself");
    internal_oligo_max_poly_x     = ajAcdGetInt("opolyxmax");
    internal_oligo_mishyb_library = ajAcdGetInfile("mishyblibraryfile");
    internal_oligo_max_mishyb     = ajAcdGetFloat("omishybmax");
    /*
       internal_oligo_min_quality    = ajAcdGetInt("oligominquality");
    */

    /* Internal Oligo penalties */
    /* these are not (yet) implemented */


    /* EMBOSS-wrapper-specific stuff */
    outfile = ajAcdGetOutfile("outfile");


    ajStrRemoveWhite(&left_input);
    ajStrRemoveWhite(&right_input);

    /*
    ** OK - we will now try to do a separate fork-exec for each sequence.
    */

    result = ajStrNew();

    while(ajSeqallNext(sequence, &seq))
    {
        program = ajAcdGetpathC("primer3_core");

        if(!ajSysExecRedirectC(ajStrGetPtr(program),&pipeto,&pipefrom))
            ajFatal("eprimer3: Could not exec primer3_core");

        stream = eprimer3_start_write(pipeto[1]);

        /* send primer3 Primer "Global" parameters */
        eprimer3_send_bool(stream, "PRIMER_EXPLAIN_FLAG", explain_flag);
        eprimer3_send_bool(stream, "PRIMER_FILE_FLAG", file_flag);

        if(do_hybrid)
        {
            if(!ajStrCmpC(task[0], "1"))
                ajStrAssignC(&taskstr, "pick_pcr_primers_and_hyb_probe");
            else if(!ajStrCmpC(task[0], "2"))
                ajStrAssignC(&taskstr, "pick_left_only");
            else if(!ajStrCmpC(task[0], "3"))
                ajStrAssignC(&taskstr, "pick_right_only");
            else if(!ajStrCmpC(task[0], "4"))
                ajStrAssignC(&taskstr, "pick_hyb_probe_only");

            if (!do_primer)
                ajStrAssignC(&taskstr, "pick_hyb_probe_only");
        }
        else
        {
            if(!ajStrCmpC(task[0], "1"))
                ajStrAssignC(&taskstr, "pick_pcr_primers");
            else if(!ajStrCmpC(task[0], "2"))
                ajStrAssignC(&taskstr, "pick_left_only");
            else if(!ajStrCmpC(task[0], "3"))
                ajStrAssignC(&taskstr, "pick_right_only");
            else if(!ajStrCmpC(task[0], "4"))
                ajStrAssignC(&taskstr, "pick_hyb_probe_only");
        }

        eprimer3_send_string(stream, "PRIMER_TASK", taskstr);
        eprimer3_send_int(stream, "PRIMER_NUM_RETURN", num_return);
        eprimer3_send_int(stream, "PRIMER_FIRST_BASE_INDEX",
                          first_base_index);
        eprimer3_send_bool(stream, "PRIMER_PICK_ANYWAY", pick_anyway);

        /* mispriming library may not have been specified */
        if(mispriming_library)
            eprimer3_send_stringC(stream, "PRIMER_MISPRIMING_LIBRARY",
                                  ajFileGetPrintnameC(mispriming_library));

        eprimer3_send_float(stream, "PRIMER_MAX_MISPRIMING",
                            max_mispriming);
        eprimer3_send_float(stream, "PRIMER_PAIR_MAX_MISPRIMING",
                            pair_max_mispriming);
        eprimer3_send_int(stream, "PRIMER_GC_CLAMP", gc_clamp);
        eprimer3_send_int(stream, "PRIMER_OPT_SIZE", opt_size);
        eprimer3_send_int(stream, "PRIMER_MIN_SIZE", min_size);
        eprimer3_send_int(stream, "PRIMER_MAX_SIZE", max_size);
        eprimer3_send_float(stream, "PRIMER_OPT_TM", opt_tm);
        eprimer3_send_float(stream, "PRIMER_MIN_TM", min_tm);
        eprimer3_send_float(stream, "PRIMER_MAX_TM", max_tm);
        eprimer3_send_float(stream, "PRIMER_MAX_DIFF_TM", max_diff_tm);
        eprimer3_send_float(stream, "PRIMER_OPT_GC_PERCENT",
                            opt_gc_percent);
        eprimer3_send_float(stream, "PRIMER_MIN_GC", min_gc);
        eprimer3_send_float(stream, "PRIMER_MAX_GC", max_gc);
        eprimer3_send_float(stream, "PRIMER_SALT_CONC", salt_conc);
        eprimer3_send_float(stream, "PRIMER_DNA_CONC", dna_conc);
        eprimer3_send_int(stream, "PRIMER_NUM_NS_ACCEPTED",
                          num_ns_accepted);
        eprimer3_send_float(stream, "PRIMER_SELF_ANY", self_any);
        eprimer3_send_float(stream, "PRIMER_SELF_END", self_end);
        eprimer3_send_int(stream, "PRIMER_MAX_POLY_X", max_poly_x);
        eprimer3_send_int(stream, "PRIMER_PRODUCT_OPT_SIZE",
                          product_opt_size);
        eprimer3_send_range2(stream, "PRIMER_PRODUCT_SIZE_RANGE",
                             product_size_range);
        eprimer3_send_float(stream, "PRIMER_PRODUCT_OPT_TM",
                            product_opt_tm);
        eprimer3_send_float(stream, "PRIMER_PRODUCT_MIN_TM",
                            product_min_tm);
        eprimer3_send_float(stream, "PRIMER_PRODUCT_MAX_TM",
                            product_max_tm);
        eprimer3_send_float(stream, "PRIMER_MAX_END_STABILITY",
                            max_end_stability);

        /* send primer3 Internal Oligo "Global" parameters */
        eprimer3_send_int(stream, "PRIMER_INTERNAL_OLIGO_OPT_SIZE",
                          internal_oligo_opt_size);
        eprimer3_send_int(stream, "PRIMER_INTERNAL_OLIGO_MIN_SIZE",
                          internal_oligo_min_size);
        eprimer3_send_int(stream, "PRIMER_INTERNAL_OLIGO_MAX_SIZE",
                          internal_oligo_max_size);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_OPT_TM",
                            internal_oligo_opt_tm);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_MIN_TM",
                            internal_oligo_min_tm);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_MAX_TM",
                            internal_oligo_max_tm);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_OPT_GC_PERCENT",
                            internal_oligo_opt_gc_percent);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_MIN_GC",
                            internal_oligo_min_gc);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_MAX_GC",
                            internal_oligo_max_gc);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_SALT_CONC",
                            internal_oligo_salt_conc);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_DNA_CONC",
                            internal_oligo_dna_conc);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_SELF_ANY",
                            internal_oligo_self_any);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_SELF_END",
                            internal_oligo_self_end);
        eprimer3_send_int(stream, "PRIMER_INTERNAL_OLIGO_MAX_POLY_X",
                          internal_oligo_max_poly_x);

        /*
        ** internal oligo mishybridising library may not have been
        ** specified
        */
        if(internal_oligo_mishyb_library)
            eprimer3_send_stringC(stream,
                                  "PRIMER_INTERNAL_OLIGO_MISHYB_LIBRARY",
                                  ajFileGetPrintnameC(internal_oligo_mishyb_library));

        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_MAX_MISHYB",
                            internal_oligo_max_mishyb);


        /*
        ** Start sequence-specific stuff
        */

        begin = ajSeqallGetseqBegin(sequence) - 1;
        end   = ajSeqallGetseqEnd(sequence) - 1;

        strand = ajSeqGetSeqCopyS(seq);

        ajStrFmtUpper(&strand);
        ajStrAssignSubC(&substr,ajStrGetPtr(strand), begin, end);

        /* send flags to turn on using optimal product size */
        eprimer3_send_float(stream, "PRIMER_PAIR_WT_PRODUCT_SIZE_GT",
                            (float)0.05);
        eprimer3_send_float(stream, "PRIMER_PAIR_WT_PRODUCT_SIZE_LT",
                            (float)0.05);

        /* send primer3 Primer "Sequence" parameters */
        eprimer3_send_string(stream, "SEQUENCE", substr);

        /* if no ID name, use the USA */
        if(ajStrMatchC(ajSeqGetNameS(seq),""))
            eprimer3_send_string(stream, "PRIMER_SEQUENCE_ID",
                                 ajSeqGetUsaS(seq));
        else
            eprimer3_send_string(stream, "PRIMER_SEQUENCE_ID",
                                 ajSeqGetNameS(seq));

        eprimer3_send_range(stream, "INCLUDED_REGION", included_region,
                            begin);
        eprimer3_send_range(stream, "TARGET", target, begin);
        eprimer3_send_range(stream, "EXCLUDED_REGION", excluded_region,
                            begin);
        eprimer3_send_string(stream, "PRIMER_LEFT_INPUT", left_input);
        eprimer3_send_string(stream, "PRIMER_RIGHT_INPUT", right_input);

        /* send primer3 Internal Oligo "Sequence" parameters */
        eprimer3_send_range(stream,
                            "PRIMER_INTERNAL_OLIGO_EXCLUDED_REGION",
                            internal_oligo_excluded_region, begin);
        eprimer3_send_string(stream, "PRIMER_INTERNAL_OLIGO_INPUT",
                             internal_oligo_input);


        /* end the primer3 input sequence record with a '=' */
        eprimer3_send_end(stream);
        /* and close the ouput pipe stream */
        eprimer3_end_write(stream);

        /* read the primer3 output */
        eprimer3_read(pipefrom[0], &result);

        eprimer3_report(outfile, result, num_return, begin);

        ajStrSetClear(&result);

#ifndef WIN32
        close(pipeto[1]);
        close(pipefrom[0]);
#endif
    }	/* end of sequence loop */


    ajStrDel(&result);
    ajSeqDel(&seq);
    ajStrDel(&strand);
    ajStrDel(&substr);
    ajFileClose(&outfile);
    ajStrDel(&taskstr);
    ajStrDelarray(&task);

    ajSeqallDel(&sequence);
    ajSeqDel(&seq);

    ajRangeDel(&included_region);
    ajRangeDel(&target);
    ajRangeDel(&excluded_region);
    ajRangeDel(&product_size_range);
    ajRangeDel(&internal_oligo_excluded_region);

    ajStrDel(&left_input);
    ajStrDel(&right_input);
    ajStrDel(&internal_oligo_input);

    AJFREE(pipeto);
    AJFREE(pipefrom);

    ajFileClose(&mispriming_library);

    embExit();

    return 0;
}