Hi,

I don't understand why this doesn't work:

(ns dpa
  (:gen-class)
  (:use [incanter.core :only ( matrix )]
        [clojure.core :only ( defn doseq line-seq println with-open )]
        [clojure.contrib.string :only ( blank? substring? )]
  (:import (java.io BufferedReader FileReader)))

(defn process-dpa-file
  "This makes the matrix of CA coordinates from a pdb file."
  [pdb-file chains]
  (def hold-coords [])
  ((with-open [rdr (BufferedReader. (FileReader. pdb-file))]
      (doseq [^String line (line-seq rdr)]
    ;; Make sure the file line is the correct length
    ;; We only want the atom entries
    ;; We don't want any repeated measurements for an atom
    ;; Is it a CA?
    ;; Are we using this chain?
    (if (and (= (.length line) 80)
             (= (str (.substring line 0 4) (.substring line 26 27)
(.substring line 13 15)) "ATOM CA")
             (substring? (.substring line 21 22) chains))
      ;; This are the CA coordinates
      (def hold-coords (into hold-coords [ (Double. (.substring line
30 37))
                                           (Double. (.substring line 38 45))
                                           (Double. (.substring line 46 53)) ] 
)))))
   (matrix hold-coords 3)))


dpa> (def my-mat (process-dpa-file "/Users/daviddreisigmeyer/MyStuff/
DPA_release_12-JUL-2010/1RD8.pdb" "A") )
No message.
  [Thrown class java.lang.NullPointerException]

Restarts:
 0: [QUIT] Quit to the SLIME top level

Backtrace:
  0: dpa$process_dpa_file.invoke(NO_SOURCE_FILE:1)
  1: clojure.lang.AFn.applyToHelper(AFn.java:165)
  2: clojure.lang.AFn.applyTo(AFn.java:151)
  3: clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:2901)
  4: clojure.lang.Compiler$DefExpr.eval(Compiler.java:361)
  5: clojure.lang.Compiler.eval(Compiler.java:5424)
  6: clojure.lang.Compiler.eval(Compiler.java:5386)
  7: clojure.core$eval.invoke(core.clj:2382)
  8: swank.commands.basic$eval_region.invoke(basic.clj:47)
  9: swank.commands.basic$eval_region.invoke(basic.clj:37)
 10: swank.commands.basic$eval799$listener_eval__800.invoke(basic.clj:
71)
 11: clojure.lang.Var.invoke(Var.java:365)
 12: dpa$eval9236.invoke(NO_SOURCE_FILE)
 13: clojure.lang.Compiler.eval(Compiler.java:5419)
 14: clojure.lang.Compiler.eval(Compiler.java:5386)
 15: clojure.core$eval.invoke(core.clj:2382)
 16: swank.core$eval_in_emacs_package.invoke(core.clj:90)
 17: swank.core$eval_for_emacs.invoke(core.clj:237)
 18: clojure.lang.Var.invoke(Var.java:373)
 19: clojure.lang.AFn.applyToHelper(AFn.java:169)
 20: clojure.lang.Var.applyTo(Var.java:482)
 21: clojure.core$apply.invoke(core.clj:540)
 22: swank.core$eval_from_control.invoke(core.clj:97)
 23: swank.core$eval_loop.invoke(core.clj:102)
 24: swank.core$spawn_repl_thread$fn__484$fn__485.invoke(core.clj:307)
 25: clojure.lang.AFn.applyToHelper(AFn.java:159)
 26: clojure.lang.AFn.applyTo(AFn.java:151)
 27: clojure.core$apply.invoke(core.clj:540)
 28: swank.core$spawn_repl_thread$fn__484.doInvoke(core.clj:304)
 29: clojure.lang.RestFn.invoke(RestFn.java:398)
 30: clojure.lang.AFn.run(AFn.java:24)
 31: java.lang.Thread.run(Thread.java:637)



But, this does work:

(defn process-dpa-file
  "This makes the matrix of CA coordinates from a pdb file."
  [pdb-file chains]
  (def hold-coords [])
  (doseq [^String line (read-lines pdb-file)]
    ;; Make sure the file line is the correct length
    ;; We only want the atom entries
    ;; We don't want any repeated measurements for an atom
    ;; Is it a CA?
    ;; Are we using this chain?
    (if (and (= (.length line) 80)
             (= (str (.substring line 0 4) (.substring line 26 27)
(.substring line 13 15)) "ATOM CA")
             (substring? (.substring line 21 22) chains))
      ;; This are the CA coordinates
      (def hold-coords (into hold-coords [ (Double. (.substring line
30 37))
                                           (Double. (.substring line 38 45))
                                           (Double. (.substring line 46 53)) ] 
))))
  (matrix hold-coords 3))

dpa> (def my-mat (process-dpa-file "/Users/daviddreisigmeyer/MyStuff/
DPA_release_12-JUL-2010/1RD8.pdb" "A") )
#'dpa/my-mat


I'd certainly appreciate any comments on the code in general.  I only
have a Matlab/R/Fortran 95 background.

Thanks,

-Dave

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to