Skip to content

Commit

Permalink
use local file from command line and get latest version without githu…
Browse files Browse the repository at this point in the history
…b api which has rate limits
  • Loading branch information
tamerh committed Oct 17, 2019
1 parent 459900c commit 041a67a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
23 changes: 22 additions & 1 deletion biobtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ var config *conf.Conf
var defaultDataset = "uniprot,go,eco,efo,hgnc,chebi,taxonomy,interpro,ensembl"

//var defaultDataset = "uniprot,go,eco,efo,hgnc,chebi,taxonomy,interpro,hmdb,literature_mappings,chembl,ensembl"

//var defaultDataset = "efo"

var allDatasets = []string{"uniprot", "go", "eco", "efo", "hgnc", "chebi", "taxonomy",
"interpro", "hmdb", "literature_mappings", "ensembl",
"uniparc", "uniref50", "uniref90", "uniref100", "my_data", "uniprot_unreviewed",
"ensembl_bacteria", "ensembl_fungi", "ensembl_metazoa", "ensembl_plants", "ensembl_protists",
"chembl_document", "chembl_assay", "chembl_activity", "chembl_molecule", "chembl_target", "chembl_target_component", "chembl_cell_line"}

func main() {

app := cli.NewApp()
Expand Down Expand Up @@ -99,6 +104,14 @@ func main() {
},
}

// add dataset local flags
for _, dataset := range allDatasets {
app.Flags = append(app.Flags, cli.StringFlag{
Name: dataset + ".file",
Hidden: true,
})
}

app.Commands = []cli.Command{
{
Name: "start",
Expand Down Expand Up @@ -268,6 +281,14 @@ func runUpdateCommand(c *cli.Context) error {
runtime.GOMAXPROCS(cpu)
}

// check local file path settings
for _, dset := range allDatasets {
if len(c.GlobalString(dset+".file")) > 0 {
config.Dataconf[dset]["path"] = c.GlobalString(dset + ".file")
config.Dataconf[dset]["useLocalFile"] = "yes"
}
}

update.NewDataUpdate(d, ts, sp, spatterns, config, chunkIdxx).Update()

elapsed := time.Since(start)
Expand Down
29 changes: 5 additions & 24 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
var fileBufSize = 65536
var channelOverflowCap = 100000

const latestReleasePath = "https://api.github.com/repos/tamerh/biobtree/releases/latest"
const latestReleasePath = "https://github.com/tamerh/biobtree/releases/latest"

type Conf struct {
Appconf map[string]string
Expand All @@ -31,10 +31,6 @@ type Conf struct {
versionTag string
}

type gitLatestRelease struct {
Tag string `json:"tag_name"`
}

type gitContent struct {
Name string `json:"name"`
RawURL string `json:"download_url"`
Expand Down Expand Up @@ -342,27 +338,12 @@ func (c *Conf) checkForNewVersion() {
log.Println("Warn: Versions data could not recieved.")
return
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
log.Println("Warn: Versions data could not recieved from github api.")
return
}

data, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println("Warn: Versions data could not recieved from github api.")
return
}

latestRelease := gitLatestRelease{}
if err := json.Unmarshal(data, &latestRelease); err != nil {
log.Println("Warn: Versions data could not parsed.")
return
}
finalURL := resp.Request.URL.String()
splitteURL := strings.Split(finalURL, "/")

if latestRelease.Tag != c.versionTag {
log.Println("Warning: There is a new biobtree version available to download")
if len(splitteURL) > 0 && splitteURL[len(splitteURL)-1] != c.versionTag {
log.Println("New biobtree version " + splitteURL[len(splitteURL)-1] + " is available to download")
}

}
Expand Down
5 changes: 2 additions & 3 deletions conf/source.dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,9 @@
"my_data": {
"id": "14",
"name": "my_data",
"path": "./my_data/my_data.xml.gz",
"path": "",
"url": "",
"useLocalFile": "yes",
"active": "false"
"useLocalFile": "yes"
},
"chembl_document": {
"name": "chembl_document",
Expand Down
6 changes: 5 additions & 1 deletion update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,16 @@ func (d *DataUpdate) Update() (uint64, uint64) {
go g.update()
break
case "my_data":
if config.Dataconf[data]["active"] == "true" {

if len(config.Dataconf[data]["path"]) > 0 {
d.wg.Add(1)
u := uniprot{source: data, d: d}
d.datasets2 = append(d.datasets2, data)
go u.update()
} else {
log.Fatal("Missing source path for my_data ")
}

break
case "literature_mappings":
d.wg.Add(1)
Expand Down

0 comments on commit 041a67a

Please sign in to comment.