first previous next last contents

Writing the Code Itself

The final C code itself is obviously completely different for each extension.

In the example composition package we loop through each contig listed in our -contigs command line argument running a separate function that returns a Tcl list containing the total number of characters processed and the number of A, C, G, T and unknown nucleotides. Each list in turn is then added as an item to another list which is used for the final result.

    /* Do the actual work */
    Tcl_DStringInit(&dstr);
    for (i = 0; i < num_contigs; i++) {
        result = doit(args.io, contigs[i].contig, contigs[i].start,
                      contigs[i].end);
        if (NULL == result) {
            xfree(contigs);
            return TCL_ERROR;
        }

        Tcl_DStringAppendElement(&dstr, result);
    }

    Tcl_DStringResult(interp, &dstr);

    xfree(contigs);
    return TCL_OK;
}

The above is the end of the tcl_composition function. doit is our main algorithm written in C (which has no knowledge of Tcl). We use the Tcl dynamic strings routines to build up the final return value. The complete C code for this package can be found in the appendices.

If a command has persistent data about a contig (such as a plot containing the composition) the registration scheme should be used to keep this data up to date whenever database edits are made. See section Contig Registration Scheme.


first previous next last contents
This page is maintained by staden-package. Last generated on 1 March 2001.
URL: http://www.mrc-lmb.cam.ac.uk/pubseq/manual/scripting_205.html