MOZI-AI / annotation-scheme

Human Gene annotation service backend
GNU General Public License v3.0
3 stars 4 forks source link

PATCH: optimize generate-result #106

Closed linas closed 4 years ago

linas commented 4 years ago

Pursuant to comment https://github.com/MOZI-AI/annotation-scheme/issues/98#issuecomment-571891078 and similar to issue #103 the speed of biogrid annotation can be more than doubled, with the code below. Viz, before, the patch, perf is this:

Time: 2945.8490 secs. calls: 75 avg: 39277986.8 usec/call for find-output-interactors
Time: 2067.2802 secs. calls: 46366 avg:  44586.1 usec/call for generate-result

after patching, its this:

Time: 1409.3709 secs. calls: 75 avg: 18791612.0 usec/call for find-output-interactors
Time: 330.18767 secs. calls: 45971 avg:   7182.5 usec/call for generate-result

The patch is this (i'm not making a pull req, because it requires additional cleanup for production code) Also, plenty more optimization opportunities are readily available in this code-block.

(define-public (xgenerate-result gene-a gene-b prot go)
      (let* (
            [output (find-pubmed-id gene-a gene-b)]
            [res (filter
               (lambda (ggg) (not (reported-genes ggg)))
               (list gene-a gene-b))]
            [pairs (reported-grid-pairs (Set gene-a gene-b))]

            [interaction (if (= 1 (string->number (cog-name prot)))
                (ListLink
                  (build-interaction gene-a gene-b output "interacts_with")
                  (build-interaction (find-protein-form gene-a) (find-protein-form gene-b) output "inferred_interaction"))
                (build-interaction gene-a gene-b output "interacts_with"))]
            [namespace (if (null? (cog-outgoing-set go)) '() (car (cog-outgoing-set go)))]
            [parent (if (null? (cog-outgoing-set go)) '() (cadr (cog-outgoing-set go)))]
          )

and the rest of the function is more-or-less same as before, except:

linas commented 4 years ago

135 contains one bug fix mentioned above.

linas commented 4 years ago

Closing, because #133 was merged.