Scientists have unlocked the genetic codes of California’s most distinguished, longest-lasting residents — coast redwood and giant sequoia trees — in what is a major breakthrough in the quest to protect the magnificent forests from the ravages of climate change, researchers announced Tuesday.

The sequencing of the towering conifers’ genomes is being presented as a transformational moment for the ancient groves because it will allow scientists to figure out which trees are best suited for a warmer, more volatile future.

“This is the fundamental modern resource that enables genetic discovery going forward,” said David Neale, a UC Davis plant scientist and the lead researcher for the project, which he called “a 23andMe for trees.”

“The justification of this whole research program is discovering the genetic basis — how trees are adapted to their environment and how they might adapt to a changing environment,” he said. “Now the discovery begins.”

The five-year, $2.6 million Redwood Genome Project, funded by San Francisco’s Save the Redwoods League, was started in 2017 and is the most intensive scientific study ever done on the state’s famous primeval forests.

Unlocking the genetic code for the gargantuan trees was no easy task. It required a specialized supercomputer to analyze the DNA extracted from tissues taken from a coast redwood tree in Butano State Park, in San Mateo County, and a giant sequoia tree from Sequoia Kings Canyon National Park, east of Fresno.

It turns out the coast redwood genome has six sets of chromosomes and 27 billion base pairs of DNA. That’s nine times the size of the human genome, which has a meager two sets of chromosomes. It even puts to shame the giant sequoia, which has more than 8 billion base pairs of DNA and is roughly three times the size of the human genome.

The coast redwood is the second-largest genome ever sequenced. The largest belongs to the axolotl, a North American salamander whose genome has more than 28 billion base pairs, giving it a remarkable ability to not only regenerate limbs but also grow back internal organs, according to the researchers.

The complexity of the redwood genome is a product of evolutionary adaptations that helped the trees adjust to changing conditions over thousands of years, but researchers say there is no shame in a small genome. As they say, the length of the wand doesn’t indicate how much magic is in the stick.

“You think of plants generally — they don't have brains, so they can’t be that complicated, but a redwood has to stay in the same place for thousands of years and fight off everything that comes its way,” said Steven Salzberg, a professor of biomedical engineering at Johns Hopkins University in Baltimore, who skippered the sequencing work. “It has to have a pretty robust ability to fight off fungi, microbes, insects, beetles, and a vast array of temperatures and humidities.”

The plan now is to analyze the genes in multiple trees, identify their genetic traits and determine why some thrive and others don’t. Ultimately, the researchers hope to develop genetic variation models for the various groves of old growth.

“Now we can screen for genetic diversity and make restoration decisions,” said Emily Burns, the director of science for Save the Redwoods League. “We want to know which genes are influential for drought tolerance and fire resistance. It’s the road map for how we are going to conserve the species in the future.”

The effort to identify flaws and fight sickness in trees is the same scientific process that led to cures for diseases like sickle cell anemia after the human genome was sequenced in 2000, the scientists said.

The work is important because old-growth trees once covered mountainous regions in the Sierra Nevada range and along the California coast all the way to the Oregon border. Since the 1850s, loggers have been cutting them down, including a massive stand in Oakland that researchers say might have contained the largest trees in the world.

In all, about 95 percent of California’s old growth has been wiped out over the past century-plus, a staggering loss when one considers how old many of these trees were. The tree-ring record taken from the last remaining old-growth trees — a historic catalog used to track climatic and weather events — can reliably be traced back to the year A.D. 328.

One tree in Redwood National and State Parks, near Crescent City (Del Norte County), is 2,520 years old. The largest of the Sierra sequoia giants, which generally live longer than their coastal cousins, is 3,240 years old, according to a Save the Redwoods League study.

North Coast redwood trees were used to build the cities of the West and rebuild San Francisco after the 1906 earthquake and fire. Save the Redwoods League was formed in 1918 to protect the imperiled trees, but the trees kept falling to the ax until environmental activists stopped the logging over the past few decades.

The old-growth trees, which store three times more carbon than other types of trees, are often found these days in isolated clumps surrounded by logged, overgrown and unhealthy woodlands. The redwood ecosystem, which sustains plants and wildlife, many of which live high in the tree canopy, is threatened by warmer temperatures and the kinds of catastrophic fires that have raged through the state in recent years.

“There may be a deeper resistance to the threats they will face in the future that is hidden out of sight, buried in their genomic sequences,” Burns said. “I think it’s going to be a new age of forestry and conservation with this information at our disposal.”

Peter Fimrite is a San Francisco Chronicle staff writer. Email: pfimrite@sfchronicle.com. Twitter: @pfimrite

Learn more The coast redwood and giant sequoia sequence data are available through the UC Davis website at https://bit.ly/2KWpRd4.