For posterity: got it working! Here is how (just ignore all the gene
amino window size like words, they are specific for my code)

(add-classpath "file:///linuxhome/tmp/boris/automaton.jar")
(import '(brics.automaton.RegExp))
(import '(brics.automaton.Automaton))
(import '(brics.automaton.RunAutomaton))
(import '(brics.automaton.AutomatonMatcher))

(defn genes-to-single-regexp
  "makes the possible recombinations from the genes Ag
pathway,
   and returns a single regexp (using brics automaton) to
detect
   epitopes"
  [genes]
  (let [make-regexp (fn [gene] (.toAutomaton
(dk.brics.automaton.RegExp. (reduce str (map #(str "[ " (reduce str %)
"]") gene)))))]
    (dk.brics.automaton.RunAutomaton. (reduce (fn [rx1,rx2] (.union
rx1 rx2))
                                              (map (fn [n] (make-
regexp n))
                                                   (set (map #(merge-
genes %)
                                                             (for [x
(first genes) y (second genes) z (third genes)] (list x y z))))))
true)))


(defn find-all-epi
  "turns the rx and string into a
matcher.
   don't know if it is a good idea to keep
matchers
   or not. Now just forgetting about them after I made them"
  [rx string]
  (let [matcher (.newMatcher rx string)]
    (count (take-while #(= true %) (repeatedly (fn [] (.find
matcher)))))))




On Dec 10 2008, 9:27 am, bOR_ <boris.sch...@gmail.com> wrote:
> Hired a monkey to hit random keys on my keyboard, and eventually
> figured out how to get the automaton working.
>
> RegExp r = new RegExp("ab(c|d)*");
> Automaton a = r.toAutomaton();
> String s = "abcccdc";
> System.out.println("Match: " + a.run(s)); // prints: true
>
> (add-classpath "file:///home/boris/projects/chapter4/automaton.jar")
> (import '(brics.automaton.RegExp))
> (import '(brics.automaton.Automaton))
> (import '(brics.automaton.RunAutomaton)) ; didn't succeed yet in
> figuring out how to call this one.
>
> (def r (.toAutomaton (dk.brics.automaton.RegExp. "[ab][c][abc][d]")))
> (def s "acbd")
> (.run r s)
>
> Next part of the exploration is to figure out how to get it to find
> substrings in a large string.
--~--~---------~--~----~------------~-------~--~----~
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
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