Created
April 2, 2020 17:32
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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