Created
November 23, 2011 06:25
-
-
Save harishtella/1388020 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; actually makes the call to c/first-n to create the limited sorted | |
;; sample | |
(defn top-n-seq [sample-name n] | |
(let [fields ["?aa" "?v" "?j" "?name" "?nc"] | |
sample-name-seqs (<- fields | |
(tcr-seqs :>> fields) | |
(= ?name sample-name))] | |
(c/first-n sample-name-seqs n :sort ["?nc"] :reverse true))) | |
;; makes two sample sets from tcr-seqs and finds matches | |
(defn matching-seqs-limited [x-name y-name x-count y-count] | |
(let [seqs-x (top-n-seqs x-name x-count) | |
seqs-y (top-n-seqs y-name y-count)] | |
(<- [?aa ?v ?j ?x-name ?y-name] | |
(seqs-x ?aa ?v ?j ?x-name _) | |
(seqs-y ?aa ?v ?j ?y-name _)))) | |
;; a regular clojure function that makes a query, | |
;; executes it, and returns a tuple (vector) result | |
;; | |
;; counts the number of matches returned by 'matches' | |
;; | |
;; I added 'fake-generator' so I can get a 0 for ?total-count | |
;; when 'matches' is empty. | |
(defn count-matching-seqs-limited [x-name y-name x-count y-count] | |
(let [matches (matching-seqs-limited x-name y-name x-count y-count) | |
fake-generator [[x-name y-name]] | |
query-res (??<- [?x-name ?y-name ?total-count] | |
(fake-generator ?x-name ?y-name) | |
(matches !!aa _ _ ?x-name ?y-name) | |
(c/!count !!aa :> ?total-count))] | |
(first query-res))) | |
;; 'source-query' gives me tuples with 2 names and 2 counts. | |
;; The counts are for how many tuples to sample from 'tcr-seqs' | |
;; with the respective sample name | |
(def names-with-match-count | |
(<- [?x-name ?y-name ?match-count] | |
(source-query ?x-name ?y-name ?x-count ?y-count) | |
(count-matching-seqs-limited | |
:< ?x-name ?y-name ?x-count ?y-count | |
:> _ _ ?match-count))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment