Skip to content

Instantly share code, notes, and snippets.

@tricead
Created April 2, 2020 17:32
Show Gist options
  • Save tricead/ede173af884db4b16dc990aca30467c3 to your computer and use it in GitHub Desktop.
Save tricead/ede173af884db4b16dc990aca30467c3 to your computer and use it in GitHub Desktop.
A script to filter the MRCONSO table in the UMLS metathesaurus by the TUI semantic value in the MRSTY table
import csv
mrconso = open("/Path/MRCONSO.RRF", 'r')
mrsty = open("/Path/MRSTY.RRF", 'r')
cuituidict = {}
for line in mrsty.readlines():
splitline = line.split("|")
cui = splitline[0]
tui = splitline[1]
if(cuituidict.get(cui) == None):
cuituidict[cui] = [tui]
else:
cuituidict[cui].append(tui)
mrsty.close()
with open("/Path/LabResultsMRCONSO.RRF", 'w+', newline='') as LabResults:
LabResults_writer = csv.writer(LabResults, delimiter='|', )
for line in mrconso.readlines():
splitline = line.split("|")
cui = splitline[0]
if("T034" in cuituidict[cui]):
splitline[18] = splitline[18].strip("\n")
LabResults_writer.writerow(splitline)
mrconso.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment