In many detective novels, the ominous aroma of bitter almonds foreshadows a swift demise. The kernels of wild almond varieties—and also the pits of peaches, cherries and other stone fruits—have chemical compounds that contain cyanide. Almond breeders have long endeavored to cultivate varieties that lack the potent poison, a process that can be expensive and time-consuming.

“You eat the flesh of the peach, you eat the flesh of the apple, but you don’t eat the flesh of the almond,” says plant biochemist Raquel Sánchez Pérez of the University of Copenhagen and the University Campus of Espinardo in Murcia, Spain. “It was very important for us to find out how these different compounds accumulated in the seeds.”

Sánchez Pérez and her colleagues have now sequenced the first complete almond genome. Nearly 28,000 genes and roughly 246 million sets of DNA letters, or base pairs—almost 95 percent of the genes—are represented in the genomic sequence, the researchers reported online Thursday in Science. Charting the nut’s genome allowed researchers to identify the protein that regulates the genes responsible for producing the toxin found in bitter wild almond varieties. The research may help farmers more efficiently breed out the toxin, which sometimes pops up in new domestic varieties of almonds and other crops.

Known to scientists as amygdalin, the toxin is a type of chemical compound called a cyanogenic glucoside. The cyanide-based poison is responsible for the acrid taste found in wild almond kernels and other fruits within the Rosaceae family. Amygdalin reacts with enzymes in the intestines, and consuming enough of it can be deadly.

Over the course of two years, Sánchez Pérez and her team received bimonthly shipments of almonds during the growing season, between March and August. They compared sections of DNA from cell nuclei in bitter and sweet almond trees, focusing on five specific proteins called transcription factors. They discovered that one of the proteins, bHLH2, held the key to regulating how and when amygdalin is produced.

“It made me laugh that, in the end, a very simple thing made such a difference,” Sánchez Pérez says. In wild almond varieties, the bHLH2 protein attaches to the DNA of two genes that spur amygdalin production, making them bitter. In sweet, domesticated varieties, a mutation in the bHLH2 protein—caused by swapped amino acids, the components that make up proteins—prevents it from binding to these genes, stopping them from making amygdalin.

Unlike other members of the Rosaceae family, which have fleshy fruit-covered seeds and were traditionally grown in highly irrigated areas, almonds were cultivated along the parched slopes of the Fertile Crescent in the Middle East. The first signs of sweet almond cultivation can be traced back up to 4,000 years ago. Humanity’s fixation with the nut can be tracked through the ages. Almonds are repeatedly referenced in the Bible, andRoman author Pliny the Elder notes their acrid taste in his massive A.D. 77–79 tome Natural History. The writings of the theologian Basil of Caesaria mention early Greek breeders successfully ridding the nut of its bitter taste by inserting plugs of pine into the tree’s trunk. This practice very likely stressed the trees, preventing them from producing the toxin.

Modern-day breeders have refined the process, and the crop has become incredibly lucrative. Central California is the world’s largest producer of sweet almonds, shipping more than two dozen varieties of the nut around the world. According to the Almond Board of California, the state exported roughly 2.25 billion pounds of sweet almonds from 2017 to 2018 and the crop generates more than $21 billion in revenue every year.

The publication of the almond genome could make it easier to cultivate the nut and identify which trees will produce sweet or bitter kernels. Currently breeders must wait three or four years for a tree to fruit before they find out. But now that this “sweetness gene” has been identified, scientists can pluck a leaf off of a months-old sapling, analyze its genetic makeup and discard undesirable varieties. Taste is “one of the primary things that breeders are looking for when they’re evaluating almonds,” says Dianne Velasco, a geneticist at the University of California, Davis, who was not involved in the study. The new finding is “going to reduce the time and expense of breeding.”

Almond breeders can also scan the genetic material for information about other traits such as resistance to pests or when a tree will bloom during the flowering season. This is particularly helpful for regions heavily impacted by climate change, including Spain—where breeders are already beginning to see shifts in the growth cycle, with many almond varieties flowering later and later in the year.

According to geneticist and plant-breeder Thomas Gradziel of U.C. Davis, amygdalin is not all bad. Although the toxin is absent in sweet almond kernels, it can still be found in the leaves and bark, rendering the tree distasteful to potential pests. The flavor that bitter almonds produce, he notes, can be found in popular food items such as amaretto and marzipan. In these cases the cyanide has been filtered out, leaving only the bitter flavor, says Gradziel, who was not involved in the new work.

Mapping the almond’s genome and understanding the genes that control the release and accumulation of the nut’s toxins may have implications for other plants. Compounds like amygdalin are found in other valuable staple crops, such as cassava. Many have suggested that the gnarled root, prized for its ability to grow in harsh, tropical environments, may be a key crop in reducing hunger throughout the world. Gradziel says the new discovery could help breeders to develop cassavas that only have toxins in their leaves, stems and skin and not within the roots themselves.