Bullying, harassment, drinking, stress: Anne Ramsay paints a bleak picture of her time in uniform. But, she tells Anne Simpson, the story had to be told.

For 14 years, Anne Ramsay belonged to "the biggest gang in the world". She chooses these words not out of bravado but from profound disillusion and hurt. In 2006, her health and self-confidence in ruins, Ramsay turned her back on that gang, claiming a culture of internal bullying, discrimination, cronyism, sectarianism and drinking had contributed substantially to her being diagnosed with post-traumatic stress. And the identity of that gang? The police. "It was the lack of integrity and the politics within the institution that finally made me realise the job wasn't for me," she says.

Raised in Summerston, Glasgow, Ramsay was 21 when she joined the Strathclyde force, having worked in Germany in the hotel and airline industries for three years. "I really wanted to help people, but quite early on it became clear that this was secondary to what was actually expected," she says. "You didn't get patted on the back for arresting criminals. You got patted on the back if you kept your nose clean and did a good report for the superintendent."

Ramsay received excellent appraisals throughout her career: "I think I was a pretty good cop." And she says it wasn't the often grisly aspect of crime detection that broke her spirit. "I actually loved that side of the job."

So why did things become so intolerable? With no small measure of courage, she has confronted that question by writing Girl in Blue, a memoir whose candour will win her few friends among former colleagues.

For legal reasons, its contents are prefaced by the note: "This is a true story and the events I'm describing all took place. However, with the exception of my family, many of the names and the characterisations have been changed to protect the innocent."

The memoir's publication comes as the question of public trust in the police is in the news, following the announcement that Boris Johnson, the mayor of London, has ordered an inquiry into claims of racism at Scotland Yard. "I'm not saying there aren't good cops," says Ramsay. "There are ones who are very efficient and care about their duty to the public. But the gang mentality means the whole ethos is wrong. If you challenge the system, you are pretty much ostracised or seen as the problem."

Ramsay's career began with two years' probation at a small police office in Ayrshire, after which she transferred to community policing in Glasgow, then on to plain-clothes duties and the CID. She has three siblings: her oldest sister, Kim, is a teacher; her brother, James, is an actor; and her second sister is Lynne Ramsay, the film-maker whose distinguished work includes Ratcatcher and Morvern Callar, and who is now filming Lionel Shriver's novel We Need to Talk About Kevin.

We meet in the west end of Glasgow, close to Byres Road, one of Ramsay's old beat locations. She laughs when I suggest that her wraithlike figure hardly seems substantial enough to have given chase to the big, the bad and the ugly.

Ramsay's serious problems within the force began after she requested a transfer to Glasgow. When she first applied to join the police, she had been frank about her brother's early drug-taking and his convictions for stealing to fund the habit. "We came from a good family but my brother, who's now completely clean, got in with a wrong crowd. My parents were heartbroken but I think it made me a better police officer because I could be sympathetic to families going through the same thing." She says, however, that she was sent to Ayrshire to remove her from the Glasgow scene.

As she discovered, that tiny, out-of-the-way posting had its own brand of sexual harassment waiting. She writes: "A few days after I started, Harry and Dean" - not their real names - "came towards me, holding the office stamp, with glints in their eyes. It bore the date and the Strathclyde Police logo." They said all girls had to pass an initiation test: "They get their arse stamped."

"That'll be bloody right' I said, running away from them. I was wearing a skirt and was really worried. Dean ran after me and got me cornered in the police kitchen. And I shouted: Don't come near me with that thing, or I'll get you done for assault.' That frightened him a bit, but it didn't stop him stamping the back of my white short-sleeved police shirt." Later that day, Ramsay retaliated by smearing lipstick over the back of his shirt collar and telling him to explain that to his wife.

Was there anyone to whom she could report the incident? "Not then, because sexual harassment was a pretty unspoken issue at that time, and there weren't the procedures in place to make a complaint. But I've always felt anyway that when you make a complaint, you are the one who ends up being investigated and feeling even more of a victim."

Towards the end of her probation, Ramsay says she encountered a more serious incident of institutional bullying. As a result of her request for a transfer, she was called for an interview to the Pitt Street police headquarters in Glasgow. "As soon as I sat across the desk from the superintendent, I sensed something was wrong," she writes. "His face was grim as granite and he threw a sheaf of papers at me." He yelled at her: "How can you even be thinking of a transfer? Look at your brother's convictions." Ramsay says she felt paralysed with shock.

Her brother's worst crime, she writes, was petty theft - "but the superintendent's reaction was as if he were a mass murderer". Now, recalling that event in our conversation, she tells me: "Suddenly I was being judged for something I hadn't done. My brother's convictions were thrown in my face and I was told I was lucky to have a job." What she couldn't understand was why they had recruited her in the first place if they were now holding her brother's past against her.

Could such aggression have been to test her resolve? Ramsay says she was too distraught and inexperienced to find out - but six months later, without any explanation, the transfer refusal was reversed and she was moved to Partick in Glasgow. She loved her time in the city; relished being on the beat, building a rapport with shop owners and locals.

Ramsay says she tried to steer clear of the off-duty drinking in pubs frequented by criminals. She writes: "I was becoming more and more disenchanted with the behaviour of some of my male colleagues", and cites one particular incident: "A dishevelled officer who had got very drunk the night before had driven himself into work, breathalysed himself in the office and found he was still over the limit. He started pouring black coffee down his throat in the hope he'd sober up before the bosses noticed". Others who were feeling particularly rough, she says, would sometimes bed down in an empty cell. For a while alcohol took its toll on Ramsay, too - although she drank not to socialise but to blot out the pervasive gang mind-set.

Her personal life improved when she met a police officer whom, in the book, she calls Ali. "He was of mixed race and I loved him to bits. We worked in different areas - he was a trained firearms officer and I was in the CID - and we had a great relationship for three years."

All that changed because of the bullying racism contained in an anonymous letter Ali received at the couple's home. "Ultimately, that affected me in my job as well," Ramsay says. Ali was a good officer, she tells me, but he had been marked down in an appraisal by his supervisor, for poor communication and judgment. His reaction had been to challenge the report in a formal complaint to personnel.

"We were devastated, especially because we knew the letter must have come from someone inside the police as it revealed details of his complaint." Ramsay knew that, if the couple reported the letter, things would get worse for Ali. "But if we kept quiet, it felt as if we were condoning something so obviously wrong."

Ali took the complaint to the Commission for Racial Equality (CRE) "because we didn't trust the police enough and thought they might make the letter go missing". Two senior CID officers were assigned to the case by the CRE, and Ramsay's fingerprints and a DNA sample were taken to eliminate her from their inquiries.

"In the end, nothing was really resolved about the letter or about Ali's grievance. But he was so sickened by the whole thing that he no longer wanted to be part of the organisation. He knew that if he did carry on in the police, this would always be hanging over him and would affect his career."

Ramsay was warned to watch her back. "The police had taken against me for a reason that was nothing to do with how I did my job, and the strain of that was so much worse than the stress of dealing with any violent criminal."

Ali resigned, and the stress Ramsay and he had endured destroyed their relationship. But why did Ramsay remain in the force? "That's a difficult question, and to some extent I don't know why. There was much about actual police work that I really enjoyed. And when you have a regular wage, and a mortgage to pay - well, you hang on."

In her book, she writes: "Slowly I began to understand that the police don't need to do anything physical to you to destroy you. The constant threat of what they might do is enough and you end up destroying yourself." Ramsay was saved from that fate by counselling, and clearly by writing her memoir. She was discharged from the police in 2006, and received an unusually high five-year injury award for post-traumatic stress disorder; important recognition, she says, of how much she had suffered.

Like any memoir, Girl in Blue is, of course, one person's version of events. "But I've been honest and I have nothing to hide," Ramsay says.

There are those who will claim her story is merely the bitter rant of someone who failed to make it. Anne Ramsay, though, has already found strength in a truer judgment: that of the police doctor who told her he understood the ordeal she'd travelled through.

Girl in Blue by Anne Ramsay with Diane Taylor (Macmillan, £16.99).