[gt-users] Feature announcement: track ordering functionality added

Sascha Steinbiss steinbiss at zbh.uni-hamburg.de
Sat Oct 3 17:45:29 CEST 2009


Hi everyone,

as the request had come up quite frequently, I have added support for
arbitrary ordering of tracks to AnnotationSketch in the current git
master/unstable version.

In analogy to the track selector function, it is now possible to
associate a track ordering function with a GtLayout object. This track
ordering function must be a string comparator function:

int (*GtTrackOrderingFunc)(const char *s1, const char *s2, void *data);

It is possible to pass user data to the function via the 'data'
parameter. 's1' and 's2' are track identifier strings, such as the ones
returned by a track selector function. By default they are the types of
the root level feature nodes of the blocks in each track. By returning
numeric values, an order is imposed on the strings, and as a result, on
the tracks these strings refer to. Return a negative value if the track
with ID 's1' should appear before the track with ID 's2' and a positive
value if 's1' should appear after 's2'. Returning a value of 0 will
result in an undefined ordering of the tracks.

For example, this track ordering function outputs all tracks reverse
lexicographically ordered by their track ID strings:

int rev_order_func(const char *s1, const char *s2, GT_UNUSED void *data)
{
  return strcmp(s1, s2) * -1;
}

A track ordering function can be registered in a GtLayout by:

gt_layout_set_track_ordering_func(layout, rev_order_func, NULL);

When the layout is sketched on a GtCanvas later, the track ordering
function will be used to determine the order in which to draw each
track. If no ordering function is set, or if it is NULL, simple
lexicographic ordering will be used as a default.

This functionality is also available in the scripting language bindings.
Here is the Ruby code for implementing above example:

layout.set_track_ordering_func(lambda { |s1, s2|  return s2 <=> s1 })

The Ruby code block will then be called from the C library when it needs
to determine an order. Note that there is no data parameter in the
Ruby/Python bindings, please use Ruby/Python globals or pass a closure
to supply external user data.

If there are any comments or suggestions, feel free to post.
Have a nice weekend,
Sascha

-- 
Sascha Steinbiss
Center for Bioinformatics
University of Hamburg
Bundesstr. 43
20146 Hamburg
Germany

Email:  steinbiss at zbh.uni-hamburg.de
URL:    http://www.zbh.uni-hamburg.de/steinbiss
Phone:  +49 (40) 42838 7322
FAX:    +49 (40) 42838 7312



More information about the gt-users mailing list