Skip to content

Commit

Permalink
Python files to add terms to both the concepts and relations.
Browse files Browse the repository at this point in the history
This step is necessary so that data uploaded to Neo4j can be easily searched for.
  • Loading branch information
Pradeep Vemulakonda committed Jun 27, 2015
1 parent 607fd0e commit 06799d3
Show file tree
Hide file tree
Showing 13 changed files with 321,257 additions and 0 deletions.
Empty file added __init__.py
Empty file.
321,156 changes: 321,156 additions & 0 deletions conceptOutFile.csv

Large diffs are not rendered by default.

Empty file added config/__init__.py
Empty file.
Binary file added config/__init__.pyc
Binary file not shown.
Binary file added config/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file added config/__pycache__/read_config.cpython-35.pyc
Binary file not shown.
4 changes: 4 additions & 0 deletions config/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[FileSection]
descfile = snomed_files/sct2_Description_Snapshot-en-AU_AU1000168_20150531.txt
conceptfile = snomed_files/sct2_Concept_Snapshot_AU1000168_20150531.txt
relfile = snomed_files/sct2_Relationship_Snapshot_AU1000168_20150531.txt
20 changes: 20 additions & 0 deletions config/read_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import configparser
import os

class SnomedConfig:
Config = configparser.ConfigParser()
Config.read(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'config.ini'))

def ConfigSectionMap(self, section):
configMap = {}
options = self.Config.options(section)
for option in options:
try:
configMap[option] = self.Config.get(section, option)
if configMap[option] == -1:
DebugPrint("skip: %s" % option)
except:
print("exception on %s!" % option)
configMap[option] = None
return configMap

Binary file added config/read_config.pyc
Binary file not shown.
38 changes: 38 additions & 0 deletions import_Concepts_tsv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from config.read_config import SnomedConfig
import csv
import os

sc = SnomedConfig().ConfigSectionMap("FileSection")
dir = os.path.dirname(__file__)
descFile = os.path.join(dir, sc["descfile"])
conceptFile = os.path.join(dir, sc["conceptfile"])

with open(descFile, "rt", encoding='utf-8') as tsvin, open("new.csv", "wb") as tsvout:
dictReader = csv.DictReader(tsvin, delimiter="\t")
csv.writer(tsvout)

desc_result = dict(
(v['conceptId'], v['term']) for v in dictReader
)


with open(conceptFile, 'rt', encoding='utf-8') as infile:
with open('conceptOutFile.csv', 'wt', encoding='utf-8') as outfile:
reader = csv.DictReader(infile, delimiter="\t")
print(reader.fieldnames)
# Use the same field names for the output file.
fieldnames = ['id', 'effectiveTime', 'active', 'moduleId', 'definitionStatusId', 'term']
writer = csv.DictWriter(outfile, fieldnames)
writer.writeheader()

# Iterate over the products in the input.

for concept in reader:
print(concept)
result = desc_result.get(concept['id'], " ")

# Update the product info.
concept['term'] = result

# Write it to the output file.
writer.writerow(concept)
39 changes: 39 additions & 0 deletions import_Rel_tsv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from config.read_config import SnomedConfig
import csv
import os

sc = SnomedConfig().ConfigSectionMap("FileSection")
dir = os.path.dirname(__file__)
descFile = os.path.join(dir, sc["descfile"])
conceptFile = os.path.join(dir, sc["conceptfile"])
relFile = os.path.join(dir, sc["relfile"])

with open(descFile, "rt", encoding='utf-8') as tsvin, open("new.csv", "wb") as tsvout:
dictReader = csv.DictReader(tsvin, delimiter="\t")
csv.writer(tsvout)

desc_result = dict(
(v['conceptId'], v['term']) for v in dictReader
)


with open(relFile, 'rt', encoding='utf-8') as infile:
with open('relOutFile.csv', 'wt', encoding='utf-8') as outfile:
reader = csv.DictReader(infile, delimiter="\t")
print(reader.fieldnames)
# Use the same field names for the output file.
fieldnames = ['id', 'effectiveTime', 'active', 'moduleId', 'sourceId', 'destinationId', 'relationshipGroup', 'typeId', 'characteristicTypeId', 'modifierId', 'term']
writer = csv.DictWriter(outfile, fieldnames)
writer.writeheader()

# Iterate over the products in the input.

for rel in reader:
print(rel)
result = desc_result.get(rel['typeId'], " ")

# Update the product info.
rel['term'] = result

# Write it to the output file.
writer.writerow(rel)
Empty file added load/__init__.py
Empty file.
Binary file added load/import_tsv.pyc
Binary file not shown.

0 comments on commit 06799d3

Please sign in to comment.