(in-package :cl-user) (defun each-enzyme-synonyms (function) (and (config :enzyme) (with-open-file (f (config :enzyme)) (loop with collecting = :nothing with id and names and entrez for line = (read-line f nil :eof) until (eq line :eof) do (when (equal line "///") (when entrez (funcall function (mapcar 'car entrez) (regex-replace-all "(^EC )|(\\s{2}.*)" id "") names)) (setq collecting :nothing names nil id nil entrez nil)) (loop for (field value) in (all-matches line "^([A-Z]*)\\s+(.*)" 1 2) do (cond ((string= field "NAME") (setq collecting :names)) ((string= field "ENTRY") (setq id value)) ((and (eq collecting :names) (not (string= field ""))) (setq collecting :nothing)) ((#"matches" value "^HSA:.*") (setq collecting :entrez)) ((and (eq collecting :entrez) (#"matches" value "^\\S{3}:.*")) (setq collecting :nothing))) (when (eq collecting :names) (push (regex-replace-all ";$" value "") names)) (when (eq collecting :entrez) (let ((them (all-matches value "(\\d+)\\((.*?)\\)" 1 2))) (setq entrez (append entrez them)))))))))