http://qs1969.pair.com?node_id=306353

Itatsumaki has asked for the wisdom of the Perl Monks concerning the following question:

Howdy brothers,

I have (what I think is) an interesting project. I want to take a chromosome, with its characteristic banding partners, and manipulate programmatically the colours of each band. I would *love* to do this rapidly enough to output via CGI, but I could do it statically if its slow. That part isn't critical.

Look at this picture to see an example of a chromosome map. I want to be able to dynamically find the bands and change their colours based on other criteria (while perhaps inserting a sharp dividing land between each band for clarity).

I have no clue what tools to start with to do this sort of thing in Perl. I have no idea how to segment the image. My instinct to avoid that problem is:

  1. Manually segment each picture into bands
  2. Re-colour bands separately
  3. Piece bands together with separating lines

Even that's beyond my skills, so I'm looking for guidance to modules (I'm stuck on Win32 btw), resources, or non-Perl tools to link into on this. Any advice very welcome.

-Tats

Replies are listed 'Best First'.
Re: Dynamic Chromosome Mapping
by injunjoel (Priest) on Nov 11, 2003 at 21:19 UTC
    Greetings all,
    Though this is not really a Perl question per se...( it is Biology related so I'll give it a shot)
    I would suggest one method for getting your desired result. You could do this all with HTML styles in a table. This way you could create the graphic for your centromere and telomeres then insert those into the table at the ends or where ever your centromere lies. You could then use the bgcolor attribute of the <td> tag to switch colors based on your criteria (and provide popups for explainations and such if you wanted using JavaScript). This way you are creating the chromosome map with HTML and you don't have to worry about learning GD or Image::Magick to manipulate images, there will only be 3 graphics tops and they will always stay the same. Not to mention if you write this logic well enough perhaps your colleagues might be able to use it to.
    Does that make sense?
    let me know if you have questions.
    -injunjoel
      Yes,

      As the graphic is a vertical one you could, 4 example: cut every segment in a .gif or .png image. And (with perl) use a table to fix them in every cell of the same column. Those segments might be transparent with only their particular white background. Later, every table´s cell would have a different class name that would address to certain characteristics in it's background color. But since the picture's background color is always white, and only the solid is transparent. By changing the cell's background, programatically, you could change the segment's color.

      Your script should change the CSS class color, and by this, you might change that segment's color. Or you might need to change several classes' colors, and that is the same effect with a lot of table cells with that same color.

      That's a real interesting approach, I'll look into that. Thanks!
Re: Dynamic Chromosome Mapping
by shockme (Chaplain) on Nov 11, 2003 at 21:20 UTC
    James Tisdall, the author of Mastering Perl for Bioinformatics, has a two part article on perl.com here and here.

    If things get any worse, I'll have to ask you to stop helping me.

Re: Dynamic Chromosome Mapping
by simonm (Vicar) on Nov 11, 2003 at 21:40 UTC
    You could do this using GD and color fills. Prepare a set of initial GIF files, with each band painted a different arbitrary color, and note the coordinates of a pixel in each band. Using GD, load the image, and then use the fill() method to fill the proper color around each of those coordinates.
Re: Dynamic Chromosome Mapping
by biosysadmin (Deacon) on Nov 12, 2003 at 01:35 UTC
    Could you provide a bit more information? For example, what kind of data are you using as input for this problem? Are you planning on using raw sequence data and then simulating a Giemsa stain with based on G+C content and other factors? Or are you correlating images of stained chromosomes with sequence or some other kind of data?
    To a me, this is a very cool project, I'd definitely like to hear more about it. No matter what sort of data you're using, I would thinkg about using bioperl, as it's very likely that they have a module for doing at least some of what you're interested in. I highly recommend the GD package for this sort of stuff, and the Tisdale articles mentioned above can be relevant if you're manipulating megabases of nucleotide data.

    I wish you luck. :)

      Sure, here's some more info on it. A variety of different factors have been shown to display chromosomal dependencies in the last few years. For instance, there is a profound chromosomal dependence of gene-expression, a strong tendency towards co-expression of neighbouring genes, chromosome-wide patterns in mutation rates (SNPs), and of course in GC content (e.g. isochores).

      There are a variety of different ways to slice these things up statistically and experimentally, but it seems to me that the most evident display technique for any of these is just to show a chromosome, along with some colour coding to indicates regions where this phenomenon occur together, or... don't. You can imagine a figure showing the 20+ chromosomes with their particular data sets....

      So, the underlying colour coding will be variable. My first pass attempt is just to colour according to cytogenic bands. So, just as that link I gave showed a physical chromosome (that's Rat-1, I think), I would show that. Then, as a first attempt I would colour different bands differently according to, say, how many SNPs they had in them.

      It would be a highly intuitive display technique for all biologists, and if I can code it reasonably well, it should be flexible enough to be extended easily to any data set.

      I don't believe there is anything in BioPerl to deal with chromosomes, but I'll post to that list and see what they say.

      Thanks for the interest!

Re: Dynamic Chromosome Mapping (link)
by Itatsumaki (Friar) on Nov 12, 2003 at 22:11 UTC

    Stefan Böhringer has a set of modules available to handle it. I haven't tried it yet, but from the pictures in the gallery it looks great.

    -Tats