|
| 1 | +// |
| 2 | +// Lollipops diagram generation framework for genetic variations. |
| 3 | +// Copyright (C) 2015 Jeremy Jay <[email protected]> |
| 4 | +// |
| 5 | +// This program is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU General Public License as published by |
| 7 | +// the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// This program is distributed in the hope that it will be useful, |
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +// GNU General Public License for more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU General Public License |
| 16 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +package data |
| 19 | + |
| 20 | +import ( |
| 21 | + "encoding/json" |
| 22 | + "os" |
| 23 | + "strings" |
| 24 | +) |
| 25 | + |
| 26 | +// MotifNames has human-readable names |
| 27 | +// - mostly from http://pfam.xfam.org/help#tabview=tab9 |
| 28 | +var MotifNames = map[string]string{ |
| 29 | + "disorder": "Disordered region", |
| 30 | + "low_complexity": "Low complexity region", |
| 31 | + "sig_p": "Signal peptide region", |
| 32 | + "coiled_coil": "Coiled-coil motif", |
| 33 | + "transmembrane": "Transmembrane region", |
| 34 | +} |
| 35 | + |
| 36 | +// GraphicFeature is a generic representation of various feature responses |
| 37 | +type GraphicFeature struct { |
| 38 | + Color string `json:"colour"` |
| 39 | + Text string `json:"text"` |
| 40 | + Type string `json:"type"` |
| 41 | + Start json.Number `json:"start"` |
| 42 | + End json.Number `json:"end"` |
| 43 | + Link string `json:"href"` |
| 44 | + Metadata GraphicMetadata `json:"metadata"` |
| 45 | +} |
| 46 | + |
| 47 | +type GraphicMetadata struct { |
| 48 | + Description string `json:"description"` |
| 49 | + Identifier string `json:"identifier"` |
| 50 | +} |
| 51 | + |
| 52 | +type GraphicResponse struct { |
| 53 | + Length json.Number `json:"length"` |
| 54 | + Metadata GraphicMetadata `json:"metadata"` |
| 55 | + Motifs []GraphicFeature `json:"motifs"` |
| 56 | + Regions []GraphicFeature `json:"regions"` |
| 57 | +} |
| 58 | + |
| 59 | +func GetLocalGraphicData(filename string) (*GraphicResponse, error) { |
| 60 | + f, err := os.Open(filename) |
| 61 | + if err != nil { |
| 62 | + return nil, err |
| 63 | + } |
| 64 | + pf := &GraphicResponse{} |
| 65 | + err = json.NewDecoder(f).Decode(pf) |
| 66 | + f.Close() |
| 67 | + for i, x := range pf.Motifs { |
| 68 | + if x.Link != "" && !strings.Contains(x.Link, "://") { |
| 69 | + x.Link = "http://pfam.xfam.org" + x.Link |
| 70 | + pf.Motifs[i] = x |
| 71 | + } |
| 72 | + } |
| 73 | + for i, x := range pf.Regions { |
| 74 | + if x.Link != "" && !strings.Contains(x.Link, "://") { |
| 75 | + x.Link = "http://pfam.xfam.org" + x.Link |
| 76 | + pf.Regions[i] = x |
| 77 | + } |
| 78 | + } |
| 79 | + return pf, err |
| 80 | +} |
0 commit comments