Skip to content

Commit

Permalink
Panther download
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlemoine committed Jan 29, 2020
1 parent e684546 commit af1d89b
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions download/panther.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (p *PantherTreeDownloader) Download(id string) (t *tree.Tree, err error) {
geturl := fmt.Sprintf("%s/%s?family=%s", p.server, p.path, id)
var getresponse *http.Response
var responsebody []byte
var answer *PantherAnswer
var answer PantherAnswer

if getresponse, err = http.Get(geturl); err != nil {
return
Expand All @@ -41,17 +41,17 @@ func (p *PantherTreeDownloader) Download(id string) (t *tree.Tree, err error) {
return
}

if err = json.Unmarshal(responsebody, answer); err != nil {
if err = json.Unmarshal(responsebody, &answer); err != nil {
err = fmt.Errorf("%s (%s)", err.Error(), string(responsebody))
return
}

if answer.Error != "" {
err = errors.New(string(answer.Error))
if answer.Search.Error != "" {
err = errors.New(string(answer.Search.Error))
return
}

if t, err = p.treeFromPantherAnswer(answer); err != nil {
if t, err = p.treeFromPantherAnswer(&answer); err != nil {
return
}

Expand All @@ -60,17 +60,16 @@ func (p *PantherTreeDownloader) Download(id string) (t *tree.Tree, err error) {

// PantherAnswer is the root of Panther JSON answer
type PantherAnswer struct {
Search PantherAnswerSearch `json:"search"`
TreeTopology PantherAnswerTreeTopology `json:"tree_topology"`
Error string `json:"error"`
SearchType string `json:"search_type"`
Search PantherAnswerSearch `json:"search"`
}

// PantherAnswerSearch defines information on answer search
type PantherAnswerSearch struct {
Product PantherAnswerProduct `json:"product"`
SearchType string `json:"search_type"`
Parameters PantherAnswerParameters `json:"parameters"`
Product PantherAnswerProduct `json:"product"`
SearchType string `json:"search_type"`
Parameters PantherAnswerParameters `json:"parameters"`
TreeTopology PantherAnswerTreeTopology `json:"tree_topology"`
Error string `json:"error"`
}

// PantherAnswerProduct defines information version and source of the answer
Expand Down Expand Up @@ -118,7 +117,7 @@ func (p *PantherTreeDownloader) treeFromPantherAnswer(answer *PantherAnswer) (t
var nedges, nnodes int = 0, 0

t = tree.NewTree()
err = p.annotationNodeToTree(&answer.TreeTopology.AnnotationNode, t, nil, &nedges, &nnodes)
err = p.annotationNodeToTree(&answer.Search.TreeTopology.AnnotationNode, t, nil, &nedges, &nnodes)
return
}

Expand All @@ -136,14 +135,29 @@ func (p *PantherTreeDownloader) annotationNodeToTree(an *PantherAnswerAnnotation
e.SetLength(an.BranchLength)
}
}
if an.Species != "" {
newNode.SetName(an.Species)
if an.TreeNodeType == "LEAF" {
if an.NodeName != "" {
newNode.SetName(an.NodeName)
} else {
err = fmt.Errorf("One tip has no name -%s-", an.SfID)
}
} else {
if len(an.Children.AnnotationNode) == 0 {
err = fmt.Errorf("One internal node has 0 children -%s-", an.SfID)
}
if an.Species != "" {
newNode.SetName(an.Species)
}
}

if an.EventType != "" {
newNode.AddComment(an.EventType)
}

if an.GeneSymbol != "" {
newNode.AddComment(an.GeneSymbol)
}

if an.Organism != "" {
newNode.AddComment(an.Organism)
}
Expand All @@ -158,9 +172,5 @@ func (p *PantherTreeDownloader) annotationNodeToTree(an *PantherAnswerAnnotation
}
}

if len(an.Children.AnnotationNode) == 0 && an.GeneSymbol == "" {
err = fmt.Errorf("One tip has no gene symbol")
}

return
}

0 comments on commit af1d89b

Please sign in to comment.