-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
260 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// Lollipops diagram generation framework for genetic variations. | ||
// Copyright (C) 2015 Jeremy Jay <[email protected]> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package data | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"strings" | ||
) | ||
|
||
// MotifNames has human-readable names | ||
// - mostly from http://pfam.xfam.org/help#tabview=tab9 | ||
var MotifNames = map[string]string{ | ||
"disorder": "Disordered region", | ||
"low_complexity": "Low complexity region", | ||
"sig_p": "Signal peptide region", | ||
"coiled_coil": "Coiled-coil motif", | ||
"transmembrane": "Transmembrane region", | ||
} | ||
|
||
// GraphicFeature is a generic representation of various feature responses | ||
type GraphicFeature struct { | ||
Color string `json:"colour"` | ||
Text string `json:"text"` | ||
Type string `json:"type"` | ||
Start json.Number `json:"start"` | ||
End json.Number `json:"end"` | ||
Link string `json:"href"` | ||
Metadata GraphicMetadata `json:"metadata"` | ||
} | ||
|
||
type GraphicMetadata struct { | ||
Description string `json:"description"` | ||
Identifier string `json:"identifier"` | ||
} | ||
|
||
type GraphicResponse struct { | ||
Length json.Number `json:"length"` | ||
Metadata GraphicMetadata `json:"metadata"` | ||
Motifs []GraphicFeature `json:"motifs"` | ||
Regions []GraphicFeature `json:"regions"` | ||
} | ||
|
||
func GetLocalGraphicData(filename string) (*GraphicResponse, error) { | ||
f, err := os.Open(filename) | ||
if err != nil { | ||
return nil, err | ||
} | ||
pf := &GraphicResponse{} | ||
err = json.NewDecoder(f).Decode(pf) | ||
f.Close() | ||
for i, x := range pf.Motifs { | ||
if x.Link != "" && !strings.Contains(x.Link, "://") { | ||
x.Link = "http://pfam.xfam.org" + x.Link | ||
pf.Motifs[i] = x | ||
} | ||
} | ||
for i, x := range pf.Regions { | ||
if x.Link != "" && !strings.Contains(x.Link, "://") { | ||
x.Link = "http://pfam.xfam.org" + x.Link | ||
pf.Regions[i] = x | ||
} | ||
} | ||
return pf, err | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// Lollipops diagram generation framework for genetic variations. | ||
// Copyright (C) 2015 Jeremy Jay <[email protected]> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package data | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
const PfamGraphicURL = "http://pfam.xfam.org/protein/%s/graphic" | ||
|
||
func GetPfamGraphicData(accession string) (*GraphicResponse, error) { | ||
queryURL := fmt.Sprintf(PfamGraphicURL, accession) | ||
resp, err := http.Get(queryURL) | ||
if err != nil { | ||
if err, ok := err.(net.Error); ok && err.Timeout() { | ||
fmt.Fprintf(os.Stderr, "Unable to connect to Pfam. Check your internet connection or try again later.") | ||
os.Exit(1) | ||
} | ||
return nil, err | ||
} | ||
respBytes, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if resp.StatusCode != 200 { | ||
return nil, fmt.Errorf("pfam error: %s", resp.Status) | ||
} | ||
|
||
data := []GraphicResponse{} | ||
err = json.Unmarshal(respBytes, &data) | ||
//if err != nil { | ||
// return nil, err | ||
//} | ||
if len(data) != 1 { | ||
return nil, fmt.Errorf("pfam returned invalid result") | ||
} | ||
r := data[0] | ||
for i, x := range r.Motifs { | ||
if x.Link != "" { | ||
x.Link = "http://pfam.xfam.org" + x.Link | ||
r.Motifs[i] = x | ||
} | ||
} | ||
for i, x := range r.Regions { | ||
if x.Link != "" { | ||
x.Link = "http://pfam.xfam.org" + x.Link | ||
r.Regions[i] = x | ||
} | ||
} | ||
return &r, nil | ||
} |
Oops, something went wrong.