Showing posts with label autocoding. Show all posts
Showing posts with label autocoding. Show all posts

Wednesday, February 13, 2008

Ruby, Perl and Python medical autocoders

In the past two days on this blog, I've provided very short, fast, and accurate medical autocoders in Ruby and Perl. I thought I might as well offer the equivalent Python script. The Python script runs about twice as fast as either the Ruby or the Perl script.

The Ruby, Perl and Python scripts and their equivalent output are provided at:

http://www.julesberman.info/coded.htm

They are distributed under a GNU license.

All three scripts use a public domain file of 20,000 PubMed Citations, available at:

http://www.julesberman.info/tumorabs.txt

They all use an external tumor nomenclature contained within the Neoplasm Classification and available as a gzipped XML file distributed under a GNU license at:

http://www.julesberman.info/neoclxml.gz

- Jules Berman
Science is not a collection of facts. Science is what facts teach us; what we can learn about our universe, and ourselves, by deductive thinking. From observations of the night sky, made without the aid of telescopes, we can deduce that the universe is expanding, that the universe is not infinitely old, and why black holes exist. Without resorting to experimentation or mathematical analysis, we can deduce that gravity is a curvature in space-time, that the particles that compose light have no mass, that there is a theoretical limit to the number of different elements in the universe, and that the earth is billions of years old. Likewise, simple observations on animals tell us much about the migration of continents, the evolutionary relationships among classes of animals, why the nuclei of cells contain our genetic material, why certain animals are long-lived, why the gestation period of humans is 9 months, and why some diseases are rare and other diseases are common. In “Armchair Science”, the reader is confronted with 129 scientific mysteries, in cosmology, particle physics, chemistry, biology, and medicine. Beginning with simple observations, step-by-step analyses guide the reader toward solutions that are sometimes startling, and always entertaining. “Armchair Science” is written for general readers who are curious about science, and who want to sharpen their deductive skills.

Monday, February 11, 2008

Fast, accurate medical autocoding with Ruby

In the field of biomedical informatics, it is often necessary to extract medical terms from text and attach a nomenclature concept code to the extracted term. By doing so, concepts of interest contained in text can be retrieved regardless of the choice of words used to describe a concept. For example, hepatocellular carcinoma, liver cell cancer, liver cancer, and hcc might all be given the same code number in a neoplasm nomenclature. Documents using any of these terms can be collected and merged if all of the terms are annotated with the same concept code.

Many people think that it is difficult to write autocoding software [that can parse text, extract terms, and code terms].

Many people think that it is impossible to write fast autocoding software. People accept autocoder speeds that code a typical pathology report at a rate of 1 report (about 1 kilobyte) per second.

Both of these notions are false. A superb autocoder can be written in a few dozen lines of Ruby code. This short coder is fast, coding 20,000 citations in about 21 seconds on a 2.8 GHz desktop CPU with 512 Megabytes RAM). This is a rate of about 100 kilobytes per second. A faster (but more complex) coder has been written by the author using the doublet method.

The output of the coder is virtually perfect. I have prepared a web file that permits anyone to browse through 20,000 abstract titles and inspect the named neoplasms in the abstract text that were coded by the Ruby script. It is available at:

http://www.julesberman.info/coded.htm"

Doubters can autocode the same list of abstract titles to determine if they can write an autocoder that is as simple, fast or accurate as this short Ruby autocoder.

Here is my Ruby script. For more information about using Ruby for autocoding and for many other biomedical projects, you may want to read my Ruby book.

As with all of my scripts, the following disclaimer applies. This script is provided by its creator, Jules J. Berman, "as is", without warranty of any kind, expressed or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. in no event shall the author or copyright holder be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.

Note that this script requires two external files, neocl.xml, the neoplasm classification in XML format, available for download as a gzipped file from:

http://www.julesberman.info/neoclxml.gz


It also requires tumorabs.txt, available at:

http://www.julesberman.info/tumorabs.txt


#!/usr/bin/ruby
text = File.open("neocl.xml", "r")
literalhash = Hash.new
text.each do
|line|
next if (line !~ /\"(C[0-9]{7})\"/)
line =~ /\"(C[0-9]{7})\"/
code = $1;
line =~ /\"\> ?(.+) ?\<\//
phrase = $1;
if (phrase =~ /[a-z]/)
literalhash[phrase] = code
#puts phrase
end
end
text.close
puts "Neoplasm code hash has been created. Autocoding will start now"
absfile = File.open("tumorabs.txt", "r")
outfile = File.open("tumorabs.out", "w")
absfile.each do
|sentence|
sentence.chomp!
sentence.gsub!(/omas/, "oma")
sentence.gsub!(/tumo[u]?rs/, "tumor")
outfile.puts "\nAbstract title..." + sentence.capitalize + "."
cum_array = Array.new
sentence_array = sentence.split
length = sentence_array.size
length.times do
(1..sentence_array.size).each do
|place_length|
phrase = sentence_array.slice(0,place_length).join(" ")
if literalhash.has_key?(phrase)
outfile.puts "Neoplasm term..." + phrase.capitalize + " " + literalhash[phrase]
end
end
sentence_array.shift
end
end
exit

Here is an example citation, followed by autocoded neoplasm terms.

Abstract title...Obstructive jaundice associated burkitt lymphoma mimicking pancreatic carcinoma.
Neoplasm term...Jaundice C0000000
Neoplasm term...Burkitt lymphoma C7188000
Neoplasm term...Lymphoma C7065000
Neoplasm term...Pancreatic carcinoma C3850000
Neoplasm term...Carcinoma C0000000

Note that only names of neoplasms are coded. Neoplasm-related terms (not strictly the name of any particular neoplasms, are captures with the general code, C0000000.

- Jules Berman

Saturday, July 7, 2007

Synonymy in the Neoplasm Classification

The Developmental Lineage Classification and Taxonomy of Neoplasms contains (on 7/7/07), 130,359 classified neoplasm terms distributed over 5,826 concepts, yielding an average exceeding 20 terms per concept. An example are the synonymous terms for adenocarcinoma of the prostate.

prostate with adenoca
adenoca arising in prostate
adenoca involving prostate
adenoca arising from prostate
adenoca of prostate
adenoca of the prostate
prostate with adenocarcinoma
adenocarcinoma arising in prostate
adenocarcinoma involving prostate
adenocarcinoma arising from prostate
adenocarcinoma of prostate
adenocarcinoma of the prostate
adenocarcinoma arising in the prostate
adenocarcinoma involving the prostate
adenocarcinoma arising from the prostate
prostate with ca
ca arising in prostate
ca involving prostate
ca arising from prostate
ca of prostate
ca of the prostate
prostate with cancer
cancer arising in prostate
cancer involving prostate
cancer arising from prostate
cancer of prostate
cancer of the prostate
cancer arising in the prostate
cancer involving the prostate
cancer arising from the prostate
prostate with carcinoma
carcinoma arising in prostate
carcinoma involving prostate
carcinoma arising from prostate
carcinoma of prostate
carcinoma of the prostate
carcinoma arising in the prostate
carcinoma involving the prostate
carcinoma arising from the prostate
prostate adenoca
prostate adenocarcinoma
prostate ca
prostate cancer
prostate carcinoma
prostatic cancer
prostatic carcinoma
prostatic adenocarcinoma
prostate gland adenocarcinoma
adenocarcinoma of the prostate gland
adenocarcinoma of prostate gland
prostate gland carcinoma
carcinoma of the prostate gland
carcinoma of prostate gland

This kind of synonymy is needed if you want to implement autocoding software that will successfully capture all of the cancer terms included in a sampled text.


In June, 2014, my book, entitled Rare Diseases and Orphan Drugs: Keys to Understanding and Treating the Common Diseases was published by Elsevier. The book builds the argument that our best chance of curing the common diseases will come from studying and curing the rare diseases.



I urge you to read more about my book. There's a generous preview of the book at the Google Books site. If you like the book, please request your librarian to purchase a copy of this book for your library or reading room.

- Jules J. Berman, Ph.D., M.D. tags: common disease, orphan disease, orphan drugs, rare disease, medical terminology, medical transcription, nomenclature, terminology, pitfalls in medical terminology