In the warm, foul-smelling environment of a compost heap, tiny roundworms eat bacteria. But some of these microbes produce toxins and the worms avoid them. In the laboratory, scientists, curious about how the roundworms can tell what dinner is and what is dangerous, often place them on mats of various bacteria to see if they wriggle away. A type of microbe, Pseudomonas aeruginosa, makes them scurry reliably.

But how do the worms, common laboratory animals of the species Caenorhabditis elegans, know to do this? Dipon Ghosh, then a PhD student in Cell and Molecular Physiology at Yale University, wondered if this was because they could sense the toxins the bacteria produced. Or could it have something to do with the fact that P. aeruginosa mats are a brilliant shade of blue?

Given that roundworms have no eyes, cells that obviously detect light, or even one of the well-known genes for photosensitive proteins, this seemed a bit of a stretch. However, it was not difficult to conduct an experiment to test the hypothesis: Dr. Ghosh, who is now a postdoctoral fellow at the Massachusetts Institute of Technology, put some worms on P. aeruginosa spots. Then he turned off the light.

To the surprise of his advisor Michael Nitabach, the worms’ flight in front of the bacteria was significantly slower in the dark, as if they could not see, which was preventing the roundworms from recognizing that they were in danger.

“When he showed me the results of the first experiments, I was shocked,” said Dr. Nitabach, who studies the molecular basis of neural circuits that control behavior at the Yale School of Medicine.

In a series of follow-up experiments described in an article published Thursday in Science, Dr. Ghosh, Dr. Nitabach and her colleagues found that some roundworms clearly respond to and perceive this distinctive pigment – and flee from it – without the benefit of any known visual system.

How they accomplish this perceptual feat remains a mystery, but the results suggest that the worms may have hacked other cellular warning systems to create some sort of color vision.

Nematodes like C. elegans have an aversion to ultraviolet light and certain wavelengths of visible light, as previous work has shown, and too much light can affect the lifespan of worms. The researchers generally viewed this behavior as a way to avoid stressful sun exposure.

But to control the foraging behavior with color – that was a new idea. To see if a change in bacterial color would have any effect, Dr. Ghosh next worms for a mutant strain of P. aeruginosa that was more beige than blue.

This time the worms didn’t move faster, regardless of whether it was light or dark in the laboratory. This indicated that they lacked additional clues as to the color of the bacteria.

He also put the blue pigment – a toxin called pyocyanin – on E. coli, a common source of food for the worms. But instead of enjoying the bacteria, he found that if they were well lit, they quickly fled from the microbes.

Other experiments showed that although the worms could see something unpleasant about the toxin without the color being there, they really did move when blue was visible.

The researchers tested dozen of roundworm strains and found that while some did not respond to blue, others were extremely sensitive to it, leaving a mat of harmless E. coli when the light shone the right color.

To understand how the eyeless creatures perceived this, the researchers compared the genomes of worms that responded strongly to color with those that ignored them. They were able to locate multiple regions of the genome that correlated with behavior.

Then they developed worms with mutations in genes in those regions to see if the creatures’ color-recognition abilities were impaired. In fact, they discovered two genes, jkk-1 and lec-3, that appeared to affect the worms’ behavior when they were mutated.

It is not yet known how these two genes, which code for proteins with no apparent connection to sight, are related to worms’ enigmatic talent. You can be part of a long bucket brigade of proteins that relay the message from one to the next that something blue is around until it reaches the worm’s neurons and sets the creature moving.

However, the proteins have historically been labeled in cellular responses to stressors such as ultraviolet light in human and mouse cells, says Dr. Ghosh.

If researchers can figure out how the roundworms recognize color, they will gain new insights into surprising behavior and an overview of how organisms without a traditional visual system may still perceive visible light. It may also be that an evolutionarily old method of avoiding stressors was tuned to the color blue.