BACKGROUND
the nematode, caenorhabditis elegans, has been used extensively for tackling fundamental questions in biology, including the modeling of aspects of human disease, drug screening and development  <cit> .
it was the first complex animal genome to be sequenced  <cit> .
its high fecundity, short life cycle and the availability of many mutants facilitate the exploration of gene function, while its complete cell lineage and transparency are useful in studies of development.
the discovery of the rna interference method for selective gene knockdown by fire and mello  <cit>  and the ease of delivery, via escherichia coli on which the worms feed, of specifically-targeted double-stranded rna has paved the way for genome-wide rnai screens  <cit> .
however, despite the facility with which large-scale genetic and chemical screens can be applied to c. elegans, the lack of automation of phentoyping has limited its use in highly automated screening applications.
to fully harness the potential of the growing number of c. elegans disease models for discovering new drugs, it is therefore necessary to develop automated methods of assaying locomotor phenotypes.
for example, screening for new anthelmintics using c. elegans or parasitic worms could be accelerated if automated phenotyping could be deployed in screening chemical libraries.
parasitic nematodes present a major challenge to both human and animal health  <cit>  so automation could also assist in accelerating screening for the discovery of new antiparasitic drugs.
in addition, automation would enhance the utility of c. elegans models mimicking aspects of human nervous system and neuromuscular diseases.
assays of c. elegans motility frequently deploy the "thrashing assay".
this is performed by placing worms in liquid medium and counting the number of lateral swimming movements , thereby quantifying an important aspect of locomotion.
the effects on locomotion of genetic manipulations and/or drugs can thus be studied with little training, yielding a numerical output that is easy to relate to behaviour.
the manual assay, however, suffers two major disadvantages.
first, it is very time consuming.
each measurement takes at least  <dig> s to perform, making it unsuitable for high-throughput assays.
in addition, since it requires a human operator, it can be prone to errors in counting, especially at high thrashing rates  with the added hazard of investigator repetitive strain.
these difficulties, when set against the tremendous potential for drug/chemical discovery if c. elegans could be used for automated chemical and genetic screens, point to the urgent need for a simple, automated system of counting thrashes.
current approaches to automating the thrashing assay follow two general strategies  <cit> .
the first is to emulate the human measurement using computer vision.
typically, the worm is distinguished from the background and its shape estimated.
the body angles through which the worms pass are then determined, from which the frequency of thrashing can be measured.
this approach provides a readout that can be compared directly with manually-derived values.
only two such analyses, designed specifically for the thrashing assay, have been described.
in both cases, several parameters in addition to thrashing rate have been measured  <cit>  but the software for these analyses has not been published.
several tools for the analysis of nematode locomotion on agar, rather than in fluid, have been made available which could be applied to analyzing thrashing worms  <cit> .
although providing extra information additional to thrashing rate, this strategy is subject to several difficulties.
for example, its accuracy depends on precise morphometry, which in turn depends upon accurately distinguishing the worm from its background .
these processes are usually highly sensitive to recording conditions and can fail under uneven illumination.
even after accurate morphometric data have been obtained, estimating thrashing frequency from the data presents further problems.
the most obvious method, that of counting the peaks in a graph of angle against time, can be confounded by the presence of random fluctuations in the measured angle, and setting the threshold to distinguish real peaks from noise in different experimental trials can be difficult.
the alternative method of using fourier analysis to derive the strongest component in the frequency domain can fail at low frequencies, where the signal components are hard to distinguish from the dc signal.
a second approach replaces the manual assay with an alternative, less direct method of estimating thrashing frequency.
for instance, simonetta and golombek  <cit>  measured thrashing of several worms simultaneously by recording the interruption of an infrared beam.
although such indirect measures do have potential for automation and high-throughput screening, the output of such an assay is not easily related to manual methods, making the results difficult to validate and to interpret biologically.
implementation
here we present a method of automatically measuring thrashes per minute, but without using morphometry or even segmentation of the worm from the background.
in our approach, the covariance matrix of film frames of thrashing worms is used to measure the time interval between frames that are statistically similar.
our algorithm follows three steps .
first, the presence of the image background is reduced using principal components analysis <cit> .
to accomplish this, a movie of the worm, consisting of d m × n pixel images, is loaded into a m × n × d 3-dimensional array, which is then transformed into a  <dig> dimensional matrix, with each frame being contained in a single column.
the first principal component of this matrix accounts for more than 99% of the variance.
examination of the image data contained in this component showed that it represents, as would be expected, the background of the images, while the remaining components are attributable to the worm conformation .
thus, subtracting the first principal component from the 2-dimensional matrix reduces the presence of background, after which the movie can be reconstructed.
after reduction of the background, the next step is to calculate the covariance matrix.
the covariance matrix of the films after removal of the first principal component shows a diagonal band of high values, representing the variance of each frame, with similar, parallel bands of lower peak heights .
these parallel bands represent frames with high covariance separated by frames with low covariance.
the number of frames separating the peaks correspond to the interval between similar images and hence to the interval between similar worm conformations.
the third step in our algorithm consists of deriving the thrashing frequency from the covariance matrix.
we compared two methods of automating the measurement of the interval between these peaks.
first, we tried converting the covariance matrix into the frequency domain using the discrete fourier transform.
this gave accurate measurements of the peak interval at high thrashing rates, but at low rates the peaks corresponding to thrashes became hard to distinguish without human intervention.
we therefore adopted the peakdet.m routine generously released into the public domain by mr. eli billauer  in which frames separating peaks greater than 50% of the total range of data are counted for each point along the diagonal of the covariance matrix.
the thrashing frequency is taken as the product of the median of these values and twice the film acquisition frequency.
the median is preferred over the mean, as the former is less sensitive to the effect of outliers.
this median is multiplied by twice the acquisition frequency because the strongest covariance is between worm conformations at the same phase of swimming, which represents the movement between two thrashes, as one thrash is counted as a single side-to-side movement.
this method has proved robust at all thrashing rates up to about  <dig> s- <dig>  this upper limit being presumably determined by the film acquisition frequency.
data acquisition
c. elegans were raised at 21°c under standard laboratory conditions on agar plates seeded with a lawn of e. coli  on which they feed.
the following c. elegans strains were used: n <dig> wild-type , as well as nicotinic acetylcholine receptor mutants unc- <dig>  unc- <dig>  lev- <dig>  acr- <dig>  lev- <dig>  unc- <dig> and unc- <dig>  all strains were handled according to standard procedures .
haemonchus contortus l <dig> larvae were kindly supplied by dr. adrian wolstenholme of university of bath.
worms were synchronously grown to early adult stage and placed in individual wells of a 96-well microtiter plate containing  <dig> μl m <dig> with or without drug.
after a  <dig> min exposure period to m <dig>  thrashes were counted at 21°c for  <dig> s. a single thrash was defined as a complete change in the direction of bending at the mid body.
worms were either counted and filmed at the same time, or filmed and subsequently counted from the movies.
manual counting was performed independently by two trained experimenters.
for automated analysis, each experiment was processed as a batch.
in accordance with accepted practice, during manual thrash counts the data for a particular worm was dropped if the worm remained still for >  <dig> s, or if the worm was visibly damaged.
in automated assays, all worms were included.
worms were filmed using an xli  <dig> mpixel camera attached to a nikon smz  <dig> dissecting microscope and the  <dig> ×  <dig> pixel images acquired at  <dig> frames s- <dig> using xli imaging software.
before filming, the image was magnified and positioned so that the circular well of the microtitre plate occupied the field of view.
movies were stored in the microsoft "wmv" format and subsequently analysed using the matlab software package running on a desktop pc running under windows xp.
to speed computation, images were reduced to 20% of their resolution.
RESULTS
to assess the performance of the system, we carried out a series of thrashing assays on wild-type  worms along with several mutants of the levamisole receptor , which have a range of effects on motility.
we used the x <dig> allele of the unc- <dig> mutant because the mutation which opens up the dicysteine loop mimics a mutation producing the same effect in patients with one form of human congenital myasthenia  <cit> .
plotting the individual machine counts for all these receptor mutants against manual counts revealed a linear relationship between these measurements with a correlation coefficient greater than  <dig>  , suggesting that the machine performance was comparable to manual measurement.
when individual scores obtained using machine and manual methods are compared , it can be seen that the automated system tends to slightly overestimate the thrashing frequency, but if the median of each trial is taken , the effect of these outliers is limited and the system compares very favourably with manual counts .
to test the usefulness of our method in analyzing the effects of drugs on motility, we performed a thrashing analysis of the dose-dependence of the actions of the anthelmintic drug, levamisole, on wild-type  worms, comparing counts obtained by a human observer with those obtained using our automated covariance method.
both approaches revealed a similar dose-dependent inhibition of thrashing frequency .
because the method makes no assumptions about the shape of the worms, it is adaptable for use with other nematode species.
we repeated our measurement of levamisole effects using 3rd instar larvae of the parasitic nematode, haemonchus contortus.
the parasite's swimming behaviour at low rates often involves the animal completely coiling up on itself, which would represent an insurmountable difficulty for most, if not all, machine-vision approaches.
the algorithm revealed a dose-dependent action of levamisole closely resembling that measured manually .
discussion
our method of automating thrashing assays has a number of advantages over traditional machine-vision approaches.
avoiding the use of morphometry speeds computation.
as implemented in our matlab script, the method is capable of analyzing a previously recorded  <dig> s movie off-line in less than  <dig> s, and can therefore be applied to directly-acquired images without the need to store movies.
this is an important consideration in developing high-throughput screens, as moving images place high demands on computer storage space.
in addition, errors introduced by failures in accurately distinguishing the worm from its background or in abstracting morphometric parameters are avoided.
finally, because it makes no assumptions about the shape of the worms, it is robustly adaptable for use with other species, as shown here by our study on the parasitic worm, h. contortus.
we have implemented this novel method using films of single worms in individual wells of a 96-well plate so that its output with manual assays can be directly compared.
deployed in this way, it can only be applied to one worm at a time, as the presence of more than one worm in the field of view  will make it difficult to derive an accurate measurement of thrashing frequency from the covariance matrix.
however, adaptations of the same principle could be used to increase the number of worms that can be measured simultaneously.
for example, an array of cameras could be used to acquire data from several wells simultaneously.
alternatively, if the worms can somehow be spatially restricted, for example, in plate wells, a large number of worms could be monitored simultaneously with a single camera if the images are split to cover each worm separately.
CONCLUSIONS
here we present a method for automating an established swimming  assay widely used for measuring locomotor phenotypes of the model genetic organism, caenorhabditis elegans.
measurements of the frequency of thrashing and their reliability compare well with manual counting over the entire range of thrashing rates likely to be encountered in studying c. elegans.
thus, our method of automating worm thrashing assays using covariance is robust, reliable and fast.
deployed in a fully automated system incorporating liquid-handling systems to deliver worms in suspension to microplates and computer-controlled positioning of the plate, this method should facilitate large-scale chemical and genetic screens for effects on motility.
availability and requirements
project name: automated thrashing assay using covariance
operating system: platform independent
programming language: matlab script
other requirements: matlab, peakdet.m
licence: gnu gpl
any restrictions to use by non-acedemics: licence needed
authors' contributions
dbs guided the development of the study and its application to screening, sdb conceived of, developed and tested the software.

 the nematode, caenorhabditis elegans, has been used extensively for tackling fundamental questions in biology, including the modeling of aspects of human disease, drug screening and development. it was the first complex animal genome to be sequenced. its high fecundity, short life cycle and the availability of many mutants facilitate the exploration of gene function, while its complete cell lineage and transparency are useful in studies of development. the discovery of the rna interference method for selective gene knockdown by fire and mello and the ease of delivery, via escherichia coli on which the worms feed, of specifically-targeted double-stranded rna has paved the way for genome-wide rnai screens. however, despite the facility with which large-scale genetic and chemical screens can be applied to c. elegans, the lack of automation of phentoyping has limited its use in highly automated screening applications. to fully harness the potential of the growing number of c. elegans disease models for discovering new drugs, it is therefore necessary to develop automated methods of assaying locomotor phenotypes. for example, screening for new anthelmintics using c. elegans or parasitic worms could be accelerated if automated phenotyping could be deployed in screening chemical libraries. parasitic nematodes present a major challenge to both human and animal health so automation could also assist in accelerating screening for the discovery of new antiparasitic drugs. in addition, automation would enhance the utility of c. elegans models mimicking aspects of human nervous system and neuromuscular diseases. assays of c. elegans motility frequently deploy the "thrashing assay". this is performed by placing worms in liquid medium and counting the number of lateral swimming movements, thereby quantifying an important aspect of locomotion. the effects on locomotion of genetic manipulations and/or drugs can thus be studied with little training, yielding a numerical output that is easy to relate to behaviour. the manual assay, however, suffers two major disadvantages. first, it is very time consuming. each measurement takes at least s to perform, making it unsuitable for high-throughput assays. in addition, since it requires a human operator, it can be prone to errors in counting, especially at high thrashing rates with the added hazard of investigator repetitive strain. these difficulties, when set against the tremendous potential for drug/chemical discovery if c. elegans could be used for automated chemical and genetic screens, point to the urgent need for a simple, automated system of counting thrashes. current approaches to automating the thrashing assay follow two general strategies. the first is to emulate the human measurement using computer vision. typically, the worm is distinguished from the background and its shape estimated. the body angles through which the worms pass are then determined, from which the frequency of thrashing can be measured. this approach provides a readout that can be compared directly with manually-derived values. only two such analyses, designed specifically for the thrashing assay, have been described. in both cases, several parameters in addition to thrashing rate have been measured but the software for these analyses has not been published. several tools for the analysis of nematode locomotion on agar, rather than in fluid, have been made available which could be applied to analyzing thrashing worms. although providing extra information additional to thrashing rate, this strategy is subject to several difficulties. for example, its accuracy depends on precise morphometry, which in turn depends upon accurately distinguishing the worm from its background. these processes are usually highly sensitive to recording conditions and can fail under uneven illumination. even after accurate morphometric data have been obtained, estimating thrashing frequency from the data presents further problems. the most obvious method, that of counting the peaks in a graph of angle against time, can be confounded by the presence of random fluctuations in the measured angle, and setting the threshold to distinguish real peaks from noise in different experimental trials can be difficult. the alternative method of using fourier analysis to derive the strongest component in the frequency domain can fail at low frequencies, where the signal components are hard to distinguish from the dc signal. a second approach replaces the manual assay with an alternative, less direct method of estimating thrashing frequency. for instance, simonetta and golombek measured thrashing of several worms simultaneously by recording the interruption of an infrared beam. although such indirect measures do have potential for automation and high-throughput screening, the output of such an assay is not easily related to manual methods, making the results difficult to validate and to interpret biologically. implementation here we present a method of automatically measuring thrashes per minute, but without using morphometry or even segmentation of the worm from the background. in our approach, the covariance matrix of film frames of thrashing worms is used to measure the time interval between frames that are statistically similar. our algorithm follows three steps. first, the presence of the image background is reduced using principal components analysis. to accomplish this, a movie of the worm, consisting of d m × n pixel images, is loaded into a m × n × d 3-dimensional array, which is then transformed into a dimensional matrix, with each frame being contained in a single column. the first principal component of this matrix accounts for more than 99% of the variance. examination of the image data contained in this component showed that it represents, as would be expected, the background of the images, while the remaining components are attributable to the worm conformation. thus, subtracting the first principal component from the 2-dimensional matrix reduces the presence of background, after which the movie can be reconstructed. after reduction of the background, the next step is to calculate the covariance matrix. the covariance matrix of the films after removal of the first principal component shows a diagonal band of high values, representing the variance of each frame, with similar, parallel bands of lower peak heights. these parallel bands represent frames with high covariance separated by frames with low covariance. the number of frames separating the peaks correspond to the interval between similar images and hence to the interval between similar worm conformations. the third step in our algorithm consists of deriving the thrashing frequency from the covariance matrix. we compared two methods of automating the measurement of the interval between these peaks. first, we tried converting the covariance matrix into the frequency domain using the discrete fourier transform. this gave accurate measurements of the peak interval at high thrashing rates, but at low rates the peaks corresponding to thrashes became hard to distinguish without human intervention. we therefore adopted the peakdet.m routine generously released into the public domain by mr. eli billauer in which frames separating peaks greater than 50% of the total range of data are counted for each point along the diagonal of the covariance matrix. the thrashing frequency is taken as the product of the median of these values and twice the film acquisition frequency. the median is preferred over the mean, as the former is less sensitive to the effect of outliers. this median is multiplied by twice the acquisition frequency because the strongest covariance is between worm conformations at the same phase of swimming, which represents the movement between two thrashes, as one thrash is counted as a single side-to-side movement. this method has proved robust at all thrashing rates up to about s- this upper limit being presumably determined by the film acquisition frequency. data acquisition c. elegans were raised at 21°c under standard laboratory conditions on agar plates seeded with a lawn of e. coli on which they feed. the following c. elegans strains were used: n wild-type, as well as nicotinic acetylcholine receptor mutants unc- unc- lev- acr- lev- unc- and unc- all strains were handled according to standard procedures. haemonchus contortus l larvae were kindly supplied by dr. adrian wolstenholme of university of bath. worms were synchronously grown to early adult stage and placed in individual wells of a 96-well microtiter plate containing μl m with or without drug. after a min exposure period to m thrashes were counted at 21°c for s. a single thrash was defined as a complete change in the direction of bending at the mid body. worms were either counted and filmed at the same time, or filmed and subsequently counted from the movies. manual counting was performed independently by two trained experimenters. for automated analysis, each experiment was processed as a batch. in accordance with accepted practice, during manual thrash counts the data for a particular worm was dropped if the worm remained still for > s, or if the worm was visibly damaged. in automated assays, all worms were included. worms were filmed using an xli mpixel camera attached to a nikon smz dissecting microscope and the × pixel images acquired at frames s- using xli imaging software. before filming, the image was magnified and positioned so that the circular well of the microtitre plate occupied the field of view. movies were stored in the microsoft "wmv" format and subsequently analysed using the matlab software package running on a desktop pc running under windows xp. to speed computation, images were reduced to 20% of their resolution.  to assess the performance of the system, we carried out a series of thrashing assays on wild-type worms along with several mutants of the levamisole receptor, which have a range of effects on motility. we used the x allele of the unc- mutant because the mutation which opens up the dicysteine loop mimics a mutation producing the same effect in patients with one form of human congenital myasthenia. plotting the individual machine counts for all these receptor mutants against manual counts revealed a linear relationship between these measurements with a correlation coefficient greater than, suggesting that the machine performance was comparable to manual measurement. when individual scores obtained using machine and manual methods are compared, it can be seen that the automated system tends to slightly overestimate the thrashing frequency, but if the median of each trial is taken, the effect of these outliers is limited and the system compares very favourably with manual counts. to test the usefulness of our method in analyzing the effects of drugs on motility, we performed a thrashing analysis of the dose-dependence of the actions of the anthelmintic drug, levamisole, on wild-type worms, comparing counts obtained by a human observer with those obtained using our automated covariance method. both approaches revealed a similar dose-dependent inhibition of thrashing frequency. because the method makes no assumptions about the shape of the worms, it is adaptable for use with other nematode species. we repeated our measurement of levamisole effects using 3rd instar larvae of the parasitic nematode, haemonchus contortus. the parasite's swimming behaviour at low rates often involves the animal completely coiling up on itself, which would represent an insurmountable difficulty for most, if not all, machine-vision approaches. the algorithm revealed a dose-dependent action of levamisole closely resembling that measured manually. discussion our method of automating thrashing assays has a number of advantages over traditional machine-vision approaches. avoiding the use of morphometry speeds computation. as implemented in our matlab script, the method is capable of analyzing a previously recorded s movie off-line in less than s, and can therefore be applied to directly-acquired images without the need to store movies. this is an important consideration in developing high-throughput screens, as moving images place high demands on computer storage space. in addition, errors introduced by failures in accurately distinguishing the worm from its background or in abstracting morphometric parameters are avoided. finally, because it makes no assumptions about the shape of the worms, it is robustly adaptable for use with other species, as shown here by our study on the parasitic worm, h. contortus. we have implemented this novel method using films of single worms in individual wells of a 96-well plate so that its output with manual assays can be directly compared. deployed in this way, it can only be applied to one worm at a time, as the presence of more than one worm in the field of view will make it difficult to derive an accurate measurement of thrashing frequency from the covariance matrix. however, adaptations of the same principle could be used to increase the number of worms that can be measured simultaneously. for example, an array of cameras could be used to acquire data from several wells simultaneously. alternatively, if the worms can somehow be spatially restricted, for example, in plate wells, a large number of worms could be monitored simultaneously with a single camera if the images are split to cover each worm separately.  here we present a method for automating an established swimming assay widely used for measuring locomotor phenotypes of the model genetic organism, caenorhabditis elegans. measurements of the frequency of thrashing and their reliability compare well with manual counting over the entire range of thrashing rates likely to be encountered in studying c. elegans. thus, our method of automating worm thrashing assays using covariance is robust, reliable and fast. deployed in a fully automated system incorporating liquid-handling systems to deliver worms in suspension to microplates and computer-controlled positioning of the plate, this method should facilitate large-scale chemical and genetic screens for effects on motility. availability and requirements project name: automated thrashing assay using covariance operating system: platform independent programming language: matlab script other requirements: matlab, peakdet.m licence: gnu gpl any restrictions to use by non-acedemics: licence needed authors' contributions dbs guided the development of the study and its application to screening, sdb conceived of, developed and tested the software. 
we demonstrate that a covariance-based method yields a fast, reliable, automated measurement of c. elegans motility which can replace the far more time-consuming, manual method. the "thrashing assay", in which nematodes are placed in liquid and the frequency of lateral swimming movements estimated, is a well-established method for measuring motility in the genetic model organism caenorhabditis elegans as well as in parasitic nematodes. furthermore, the algorithm successfully measured the actions of levamisole on a parasitic nematode, haemonchus contortus, which undergoes complex contorted shapes whilst swimming, without alterations in the code or of any parameters, indicating that it is applicable to different nematode species, including parasitic nematodes. the absence of a morphometry step means that the method can be applied to any nematode that swims in liquid and, together with its speed, this simplicity lends itself to deployment in large-scale chemical and genetic screens. the algorithm used also enabled us to determine a dose-dependent inhibition of thrashing frequency by the anthelmintic drug, levamisole, illustrating the suitability of the system for assaying the effects of drugs and chemicals on motility. we tested the performance of our covariance method in measuring thrashing rates of worms using mutations that affect motility and found that it accurately substituted for laborious, manual measurements over a wide range of thrashing rates. our method uses principal components analysis to remove the background, followed by computation of a covariance matrix of the remaining image frames from which the interval between statistically-similar frames is estimated.
 the "thrashing assay", in which nematodes are placed in liquid and the frequency of lateral swimming movements estimated, is a well-established method for measuring motility in the genetic model organism caenorhabditis elegans as well as in parasitic nematodes. it is used as an index of the effects of drugs, chemicals or mutations on motility and has proved useful in identifying mutants affecting behaviour. however, the method is laborious, subject to experimenter error, and therefore does not permit high-throughput applications. existing automation methods usually involve analysis of worm shape, but this is computationally demanding and error-prone. here we present a novel, robust and rapid method of automatically counting the thrashing frequency of worms that avoids morphometry but nonetheless gives a direct measure of thrashing frequency. our method uses principal components analysis to remove the background, followed by computation of a covariance matrix of the remaining image frames from which the interval between statistically-similar frames is estimated.  we tested the performance of our covariance method in measuring thrashing rates of worms using mutations that affect motility and found that it accurately substituted for laborious, manual measurements over a wide range of thrashing rates. the algorithm used also enabled us to determine a dose-dependent inhibition of thrashing frequency by the anthelmintic drug, levamisole, illustrating the suitability of the system for assaying the effects of drugs and chemicals on motility. furthermore, the algorithm successfully measured the actions of levamisole on a parasitic nematode, haemonchus contortus, which undergoes complex contorted shapes whilst swimming, without alterations in the code or of any parameters, indicating that it is applicable to different nematode species, including parasitic nematodes. our method is capable of analyzing a s movie in less than s and can therefore be deployed in rapid screens.  we demonstrate that a covariance-based method yields a fast, reliable, automated measurement of c. elegans motility which can replace the far more time-consuming, manual method. the absence of a morphometry step means that the method can be applied to any nematode that swims in liquid and, together with its speed, this simplicity lends itself to deployment in large-scale chemical and genetic screens. 