Skip to content

Commit

Permalink
input trees from -i treebase://<id>
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlemoine committed Jan 30, 2018
1 parent cffdc00 commit bdb34dd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions io/utils/readfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bufio"
"bytes"
"compress/gzip"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -54,6 +56,18 @@ func GetReader(inputfile string) (io.Closer, *bufio.Reader, error) {
return nil, nil, err
}
f = ioutil.NopCloser(bytes.NewReader(b))
} else if isTreeBase(inputfile) {
var res *http.Response
treebaseid := strings.TrimPrefix(inputfile, "treebase://")
url := fmt.Sprintf("https://treebase.org/treebase-web/tree_for_phylowidget/TB2:%s", treebaseid)
if res, err = http.Get(url); err != nil {
return nil, nil, err
}
if res.Header.Get("Content-Type") != "text/plain" {
return nil, nil, errors.New("Error while querying Tree Base, may be wrong ID")
}

f = res.Body
} else {
if f, err = OpenFile(inputfile); err != nil {
return nil, nil, err
Expand All @@ -80,3 +94,7 @@ func isHttpFile(file string) bool {
func isItol(file string) bool {
return strings.HasPrefix(file, "itol://")
}

func isTreeBase(file string) bool {
return strings.HasPrefix(file, "treebase://")
}

0 comments on commit bdb34dd

Please sign in to comment.