eval (memory-allocate 10000) eval (define eutils "http://eutils.ncbi.nlm.nih.gov/entrez/eutils") eval (define (readncbi-snpid snp) \ (begin \ (define tmpfil "xxx") \ (define esearch "/esearch.fcgi\?db=snp\&term=") \ (system (string-append "wget \"" eutils esearch snp \ "\" -a getsnp.log -O " tmpfil)) \ (define dat (open-input-file tmpfil)) \ (define res '()) \ (let loop ((lin (read-line dat))) \ (if (string? lin) \ (let* ((vars (string-split lin)) (first (car vars))) \ (begin \ (if (string=? (substring first 0 4) "") \ (set! res \ (append res (substring first 4 (- (string-length first) 5))))) \ (loop (read-line dat)) )))) \ (close-input-port dat) \ res)) eval (define (readncbi-snp snpid) \ (define tmpfil "xxx2") \ (define efetch "/efetch.fcgi\?db=snp\&id=") \ (define flat "\&report=FLT") \ (system (string-append "wget \"" eutils efetch snpid flat \ "\" -a getsnp.log -O " tmpfil)) \ (define dat (open-input-file tmpfil)) \ (define rsnum "") \ (define alleles "") \ (define chromosome "") \ (define sequence_position "") \ (define associated_gene "") \ (let ((lin (read-line dat))) \ (set! rsnum (list-ref (string-split lin) 0))) \ (let loop ((lin (read-line dat))) \ (if (string? lin) \ (let ((vars (string-split lin))) \ (if (not (null? vars)) \ (begin \ (if (substring? "alleles=" lin) \ (set! alleles (substring (list-ref vars 2) 8))) \ (if (string=? (list-ref vars 0) "LOC") \ (set! associated_gene (list-ref vars 2))) \ (if (substring? "assembly=" lin) \ (let ((chr (substring (list-ref vars 4) 4)) \ (seq_pos (substring (list-ref vars 6) 8))) \ (set! chromosome chr) \ (if (not (string=? seq_pos "NaN")) \ (set! sequence_position seq_pos)))))) \ (loop (read-line dat))))) \ (close-input-port dat) \ (list rsnum alleles chromosome sequence_position associated_gene)) eval (define (getncbisnp snp) \ (begin \ (define res (readncbi-snp (readncbi-snpid snp))) \ (if (not (null? (car res))) \ (begin \ (display (car res)) \ (display " ") \ (display (caddr res)) \ (display ":") \ (display (list-ref res 3)) \ (display " [") \ (display (cadr res)) \ (display "] ") \ (display (list-ref res 4)) \ (newline))))) macro getNCBIsnp eval (getncbisnp "%1") ;;;; macro example getNCBIsnp rs12684650 ;;;;