HOW did a Cork greengrocer’s daughter in the 19th century defy all the odds to become a doctor? Charwoman Sophia Bishop was laying out the body of Dr James Barry, on July 25, 1865, when she screamed. Her master was a woman.

The eminent ‘Dr Barry’ was Margaret Ann Bulkley, daughter of Jeremiah Bulkley, a greengrocer on the South Mall who supplemented his income by working at the weigh house. But the recklessness of his elder son destituted the family and Jeremiah was locked up in the Debtors’ Prison in Dublin. Their only hope was his wife’s brother, James Barry, the famous Cork artist and professor of painting at London’s Royal Academy.

The artist died in 1806, leaving money to the Bulkleys, who moved to London. Barry’s friends took the family under their wing. Margaret began lessons with the physician, Edward Frye. Margaret, a bright child, dreamed of becoming a doctor. But no women were allowed to enter university.

The friends devised a daring plan that would have appealed to Uncle James, who was a great fan of Mary Wollstonecraft’s book A Vindication of the Rights of Women (1792). Margaret’s mother would disguise her as a boy, take her to Edinburgh and enrol her at the university medical school, one of the most famous in Europe. In 1809, aged 14, Margaret was taken to Edinburgh by sea. She was dressed as a boy, in a thick overcoat.

She had a new name, a combination of her uncle’s, and those of two friends, both party to the deception: General Francisco de Miranda, from Venezuela, and David Stuart Erskine, a keen supporter of women’s education. Exit Margaret Bulkley. Enter James Miranda Stuart Barry.

Like all other new students, James Barry had a medical that was evidently so superficial that ‘his’ gender was not discovered, and he won admission. He proved a brilliant student, and swept through his exams, receiving his MD in 1812.

The plan was for him to go with General Miranda to Venezuela, where female doctors were allowed to practise; but there was one hitch — the general was now in prison. Barry would have to continue in his male role. From Edinburgh, he went to London and spent six months at St Thomas’s Hospital. After passing the Royal College of Surgeons exam, he enlisted as a surgeon in the British Army.

Serving in Europe, India, South Africa and Canada, he was promoted through the ranks to become inspector general in charge of military hospitals — the most senior medical position in the British Army. He became a highly acclaimed surgeon, and championed better food, sanitation and medical care for soldiers, prisoners and lepers.

Barry’s first posting, in 1816, was to the Cape of Good Hope. There, he acquired a black poodle, called Psyche; a goat, which he took around with him so he could drink its milk; and a black servant, who would stay with him for the next 50 years. Each morning, the servant’s task was to lay out six small towels that Barry would use as bandages to disguise his curves and broaden his shoulders. But this was not enough to stop Barry from attracting attention: even with his three-inch soles, he was tiny, just over five feet. His small hands, smooth skin, squeaky voice and mincing manner made him effeminate. And when Governor Charles Somerset gave Barry private apartments, some people suspected the two were in a homosexual relationship.

Yet Barry was accepted as male. He swore like a trooper, and was quite a ladies’ man, behaving so flirtatiously with women that one husband accused him of paying “improper attentions” to his wife.

While in Cape Town, in 1826, he performed an emergency Caesarean section while the patient was lying on a kitchen table — the first ever to be documented. Although anaesthetics and antiseptics had not yet been invented, both mother and child survived. Forty years later, in 1866, a future prime minister of South Africa was named James Barry Munnik Hertzog in the surgeon’s honour.

Barry was renowned for his fiery temper, and he fought two duels. During the Crimean War, his bullish manner made him very unpopular with Florence Nightingale. “He behaved like a brute,” she wrote, “the most hardened creature I ever met throughout the army.”

After Barry’s death, from dysentery, aged 70, Bishop let the story out; but, by then, Barry had been given a full military funeral. The General Register Office asked Barry’s doctor why he had issued a death certificate describing Barry as ‘male’. When he replied he had no reason to suspect he was a woman, Bishop retorted he was “a pretty poor doctor not to know this”. Another doctor who had treated Barry, for a chest infection in Canada, said that the bedroom was always in darkness when he examined him.

Barry’s deathbed sex secret rocked the Victorian establishment. The army had been fooled, and placed an embargo on Barry’s military record for a hundred years — hoping the scandal would pass. Instead, there was a frenzy to discover the true identity of one of the day’s most respected surgeons.

All this because Bishop had ignored Barry’s final wish. The doctor had insisted that he should not be changed out of the clothes in which he died. Instead, Bishop had examined his body closely and had literally uncovered his secret: Barry was a “perfect female”. And there was more: she had stretch marks on her stomach, evidence of an earlier pregnancy. Bulkley could have done what most women of that time did: married and had children. But she was determined to become a doctor. This meant living a huge lie, but she became the first woman to graduate in medicine — an honour usually accorded to Elizabeth Garrett Anderson, in 1865, the year Barry died. A war hero and medical pioneer, Margaret Ann Bulkley saved the lives of soldiers, and gave life to the

unborn.

GENDER BIAS: ‘sex swap’ stories from history and on film

-Frances Louisa Clayton (inset, right) enlisted as Union soldier ‘Jack Williams’ in the American Civil War (1861-65). She walked with a ‘masculine stride,’ and gambled, drank, smoked cigars, and swore. An estimated 400 women did likewise.

-Dora Ratjen competed for Germany in the women’s high jump at the 1936 Olympics. Although he concealed his maleness from other athletes, in 1938 a train conductor reported a passenger with a moustache, dressed in a grey two-piece, tights and slingbacks. Ratjen was arrested, examined and pronounced male.

-In Tootsie (1982), unemployed Dustin Hoffman (right) adopts a new identity as a woman to land a job. As the female lead in a soap opera, she quickly becomes a sensation as Dorothy Michaels.

-Robin Williams, in Mrs Doubtfire (1993), gets his brother to make him up as a woman so he can get a housekeeper’s job at the home of his estranged wife to keep in touch with his children.

-Glenn Close (right) plays the title role in Albert Nobbs (2011), an elf-like hotel waiter with a stiff walk and low monotonic voice, living in late 19th century Ireland. Nobbs was a woman who changed gender to find work.