Specifically, SRL 4 in the USA has license restrictions between SRL 1 and 2 when
used in the United States. We create a new scale (SRLUS) where SRL to SRLUS mapping is:
(0->0, 1->1, 4->2, 2->3, 3->4)."
- (declare (fixnum srl))
+ (declare (type (integer 0 100) srl))
(cond
+ ((<= srl 1) srl)
((= srl 4) 2)
((= srl 2) 3)
((= srl 3) 4)
(t srl)))
+(defvar *vff-position-hash* (make-hash-table :size 100 :test 'eq))
+
+(defmacro vff (filename fieldname record)
+ (let ((pos (gensym "POS-"))
+ (found (gensym "FOUND-"))
+ (key (kmrcl:ensure-keyword (concatenate 'string filename "^" fieldname))))
+ `(locally (declare (optimize (speed 3) (safety 0)))
+ (multiple-value-bind (,pos ,found) (gethash ,key *vff-position-hash*)
+ (declare (ignore ,found))
+ (if ,pos
+ (locally (declare (type (integer 0 100000) ,pos))
+ (nth ,pos ,record))
+ (let ((,pos (position-field-file ,filename ,fieldname)))
+ (unless ,pos
+ (error "Did not find fieldname ~A in filename ~A." ,fieldname ,filename))
+ (locally (declare (type (integer 0 100000) ,pos))
+ (setf (gethash ,key *vff-position-hash*) ,pos)
+ (nth ,pos ,record))))))))
+
(let ((pfstr-hash nil) ;; Preferred concept strings by CUI
(cui-lrl-hash nil) ;; LRL by CUI
(lui-lrl-hash nil) ;; LRL by LUI
(declare (fixnum counter)
(ignorable counter))
(with-umls-file (line "MRCONSO.RRF")
- (let* ((cui (parse-ui (nth 0 line)))
- (lui (parse-ui (nth 3 line)))
- (sui (parse-ui (nth 5 line)))
- (sab (nth 11 line))
- (srl (parse-integer (nth 15 line)))
- (srlus (srl-to-srlus srl)))
+ (let* ((cui (parse-ui (vff "MRCONSO.RRF" "CUI" line)))
+ (lui (parse-ui (vff "MRCONSO.RRF" "LUI" line)))
+ (sui (parse-ui (vff "MRCONSO.RRF" "SUI" line)))
+ (sab (vff "MRCONSO.RRF" "SAB" line))
+ (srl (parse-integer (vff "MRCONSO.RRF" "SRL" line)))
+ (srlus (srl-to-srlus srl))
+ (cuisui (make-cuisui cui sui)))
#+sbcl
(when (= 0 (mod (incf counter) 100000)) (sb-ext:gc :full t))
;; pfstr deprecated by KPFENG field in MRCONSO
#+nil
(unless (gethash cui pfstr-hash) ;; if haven't stored pfstr for cui
- (when (and (string-equal (nth 1 line) "ENG") ; LAT
- (string-equal (nth 2 line) "P") ; ts
- (string-equal (nth 4 line) "PF")) ; stt
- (setf (gethash cui pfstr-hash) (nth 14 line))))
+ (when (and (string-equal (vff "MRCONSO.RRF" "LAT" line) "ENG")
+ (string-equal (vff "MRCONSO.RRF" "TS" line) "P")
+ (string-equal (vff "MRCONSO.RRF" "STT" line) "PF"))
+ (setf (gethash cui pfstr-hash) (vff "MRCONSO.RRF" "STR" line))))
(set-lrl-hash cui srl cui-lrl-hash)
(set-lrl-hash lui srl lui-lrl-hash)
(set-lrl-hash sui srl sui-lrl-hash)
- (set-lrl-hash (make-cuisui cui sui) srl cuisui-lrl-hash)
+ (set-lrl-hash cuisui srl cuisui-lrl-hash)
(set-lrl-hash cui srlus cui-lrlus-hash)
(set-lrl-hash lui srlus lui-lrlus-hash)
(set-lrl-hash sui srlus sui-lrlus-hash)
- (set-lrl-hash (make-cuisui cui sui) srlus cuisui-lrlus-hash)
+ (set-lrl-hash cuisui srlus cuisui-lrlus-hash)
(multiple-value-bind (val found) (gethash sab sab-srl-hash)
(declare (ignore val))
(unless found
'(("KCON" "SELECT CUI,STR FROM MRCONSO WHERE STT='PF' AND TS='P' AND ISPREF='Y' AND LAT='ENG'"))
"Custom tables to create")
-(defmacro vff (filename fieldname record)
- (let ((pos (gensym "POS-"))
- (key (kmrcl:ensure-keyword (concatenate 'string filename "^" fieldname))))
- `(let ((,pos (position-field-file ,filename ,fieldname ,key)))
- (unless ,pos
- (error "Did not find fieldname ~A in filename ~A." ,fieldname ,filename))
- (locally (declare (type (integer 0 100000) ,pos))
- (nth ,pos ,record)))))
-
(defparameter +custom-cols+
'(#+nil ("MRCONSO.RRF" "KPFSTR" "TEXT"
(slot-value (find-ucol "STR" "MRCONSO.RRF") 'max)
- (lambda (x) (pfstr-hash (parse-ui (nth 0 x)))))
+ (lambda (x) (pfstr-hash (parse-ui (vff "MRCONSO.RRF" "CUI" x)))))
;; Set to 1 if term is prefered term for english
("MRCONSO.RRF" "KPFENG" "TINYINT" 0
- (lambda (x) (if (and (string-equal (nth 1 x) "ENG") ; LAT
- (string-equal (nth 2 x) "P") ; ts
- (string-equal (nth 4 x) "PF")) ; stt
+ (lambda (x) (if (and (string-equal (vff "MRCONSO.RRF" "LAT" x) "ENG")
+ (string-equal (vff "MRCONSO.RRF" "TS" x) "P")
+ (string-equal (vff "MRCONSO.RRF" "STT" x) "PF"))
"1"
"0")))
("MRCONSO.RRF" "KCUISUI" "BIGINT" 0
(parse-ui (vff "MRXNS_ENG.RRF" "CUI" x))
(parse-ui (vff "MRXNS_ENG.RRF" "SUI" x)))))))
- #+nil ("MRREL.RRF" "KPFSTR2" "TEXT" 1024 (lambda (x) (pfstr-hash (parse-ui (nth 4 x)))))
- #+nil ("MRCOC.RRF" "KPFSTR2" "TEXT" 1024 (lambda (x) (pfstr-hash (parse-ui (nth 2 x)))))
+ #+nil ("MRREL.RRF" "KPFSTR2" "TEXT" 1024 (lambda (x) (pfstr-hash (parse-ui (vff "MRREL.RRF" "CUI2" x)))))
+ #+nil ("MRCOC.RRF" "KPFSTR2" "TEXT" 1024 (lambda (x) (pfstr-hash (parse-ui (vff "MRCOC.RRF" "CUI2" x)))))
("MRSAT.RRF" "KCUILUI" "BIGINT" 0
(lambda (x) (write-to-string (make-cuilui