Extending the use of WormTools to Drosophila Pupae


I am trying to adapt worm tools for a slightly diffrent, much less challenging application than for worms.
I wondered if anybody had suggestions about how I might best do this.

I would like to further an automated pathway to measure Drosophila pupae (it not necessary that all pupae are identified and if a proportion are skipped it is fine).

The images are of Drosophila puape attached to a transparent piece of plastic . All pupae are always in the same plane and never overlap, orientation is random they have a very standard shape (3-4 mm long). The pupae look like they have two axis of symmetry, but there are some small unimportant differences at the ends.

While the identify primary objects works very very well for identifying isolated puape, it does not work so well when the pupae are very close to each other. It is a behavioral property of Drosophila pupation that some fraction like to align themselves and the arrows highlight where this has a happened.
image.pdf (143 KB)
Given that identification of non-overlapping puape looks to be a much simpler problem than the one solved for worms I was wondering if anybody thought the ‘UntangleWorms’ model could be used delineate individual pupae in clusters. I had a very quick go at making a training set file on default settings. But it does not do a good job in my largely ignorant hands.

Any help would be greatly appreciated.



I have attached a zip file with the pipeline image and training set.
Guy.zip (89.1 KB)

Hi Guy,

Your images look good, but unfortunately, we’ve run into this sort of issue before with using worm untangling on short stubby objects. The toolbox works best on objects with a large length-to width ratio (like C. elegans) but doesn’t do as well. However, I can suggest the following:

  • in the .xml file, increase the value.
  • Specify “Process all clusters” for “Maximum complexity” in UntangleWorms.
  • Oddly(?), unchecking the “use training set weights” seemed to perform better.


Dear Mark

Thanks for a lot for the reply. I did what you suggested in increasing the in the TrainingSetFile.xml to 100.

I also improved the training file by basing it on more individuals (32, which is still less than the 60 recommended).

and set ‘process all clusters’

Like you the best results were with the ‘use training set weights’ box unchecked.

I guess all the parameters from the TrainingSetFile.xml are used when the box in unchecked except for the u]weights’ ‘overlap weight’ and the ‘leftover weight’, these appeared to work best for me at 100 and 10 respectively.

This gave me really good results on the image the training set was based (only 3 problem pupae)

Trying another unrelated image with many more clusters gave equally good results. (only 1 problem pupae)

Though it is clear that the outlines from the IdentifyPrimaryObjects model trace the actual the edge of objects better than the objects resulting from the UntangleWorms module. The UntangleWorm does however much more reliably identify more pupae.

This is more than good enough for my purposes, though I guess it can be further improved by enlarging variability of the training set and maybe a bit more fine tuning of the above parameters .

So thanks for all your help and to you and your colleagues for putting together such a useful and flexible program


Pipeline attachedguy2.zip (180 KB)

I have two further questions if anybody can help.

While the worm tool box is giving me very good results I wondered if anybody can explain in simplistic terms how I might think about trying to fit ellipses rather than the complex model in the TrainingSetFile.
Given that to model puape is much simpler than wiggly worms, do you have any idea what parameters in the UntangleWorm module could be reduced to make it run faster e.g. is there any advantage in having 21 control points in the model?



Regarding fitting an ellipse, there is a function in CellProfiler that almost does this; the ‘IdentifyDeadWorms’ tries to fit a diamond-like shape to a binary image (same input as for the UntangleWorms). I tried it, but was not really successful. Enabling other shapes than diamonds for this fitting would require some coding, but is definitely doable.

Regarding the number of control points in the model; Yes, it is a very good idea to reduce this to 4, or even less. It should affect processing speed, but I’m not sure it will be significant.

I also noted your comment that the outlines of the pupae were better after IdentifyPrimaryObject than following the worm untangling. You could combine the two by using the Morph module to shrink the output objects from UntangleWorms, and then use them as seeds in IdentifySecondaryObjects. I believe it should improve the positioning of the outlines.