-
Notifications
You must be signed in to change notification settings - Fork 2
/
genesearch.go
67 lines (53 loc) · 1.83 KB
/
genesearch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"database/sql"
"flag"
"fmt"
"log"
"os"
test "github.com/shusson/genesearch/test"
elasticutil "github.com/shusson/genesearch/util"
indexers "github.com/shusson/genesearch/indexers"
_ "github.com/go-sql-driver/mysql"
)
func check(err error) {
if err != nil {
panic(err)
}
}
func main() {
var shards int
var replicas int
var coordID int
var sqlURL string
var elasticURL string
var runTests bool
flag.StringVar(&sqlURL, "DSN", "anonymous@tcp(asiadb.ensembl.org:3306)/homo_sapiens_core_87_38", "Specify the Data Resource of the ensembl SQL server you want to connect to. More info: https://github.com/go-sql-driver/mysql#dsn-data-source-name")
flag.StringVar(&elasticURL, "elastic url", "http://127.0.0.1:32840", "Specify the Elastic search server you want to connect to.")
flag.IntVar(&coordID, "coord", 4, "specify coordinate system id. defaults to 4 which is chromosome GRCh38. This value will depend on what release of ensembl is used")
flag.IntVar(&shards, "shards", 1, "specify number of shards. defaults to 1.")
flag.IntVar(&replicas, "replicas", 0, "specify number of replicas. defaults to 0.")
flag.BoolVar(&runTests, "tests", false, "run some functional tets against the elastic search instance")
flag.Usage = func() {
fmt.Printf("Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
if runTests {
test.Run(elasticURL)
return
}
db, err := sql.Open("mysql", sqlURL)
check(err)
defer db.Close()
err = db.Ping()
check(err)
client := elasticutil.Connect(elasticURL,
log.New(os.Stderr, "ELASTIC ", log.LstdFlags),
log.New(os.Stdout, "", log.LstdFlags))
processors := []indexers.Indexer{indexers.GeneIndexer{}, indexers.ChromosomeIndexer{}}
for _, processor := range processors {
processor.BuildIndex(client, shards, replicas)
processor.AddDocuments(db, client, coordID)
}
}