/
dgidb-transform.go
116 lines (105 loc) · 3.01 KB
/
dgidb-transform.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"encoding/json"
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
// "github.com/golang/protobuf/jsonpb"
)
type Meta struct {
CurrentPage int32 `json:"current_page,omitempty"`
// PerPage int32 `json:"per_page,omitempty"`
TotalPages int32 `json:"total_pages,omitempty"`
Links struct {
Next string `json:"next,omitempty"`
Previous string `json:"previous,omitempty"`
} `json:"links,omitempty"`
}
type Record struct {
ID string `json:"id,omitempty"`
GeneName string `json:"gene_name,omitempty"`
EntrezID int32 `json:"entrez_id,omitempty"`
DrugName string `json:"drug_name,omitempty"`
ChemblID string `json:"chembl_id,omitempty"`
Publications []int32 `json:"publications,omitempty"`
InteractionTypes []string `json:"interaction_types,omitempty"`
Sources []string `json:"sources,omitempty"`
Attributes []Attribute `json:"attributes,omitempty"`
InteractionClaims []InteractionClaim `json:"interaction_claims,omitempty"`
}
type Attribute struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
Sources []string `json:"sources,omitempty"`
}
type InteractionClaim struct {
Source string `json:"source,omitempty"`
Drug string `json:"drug,omitempty"`
Gene string `json:"gene,omitempty"`
IntractionTypes []string `json:"interaction_types,omitempty"`
Attributes []Attribute `json:"attributes,omitempty"`
}
// CompoundIDs represents a subset of mappings from:
// https://www.ebi.ac.uk/unichem/rest/src_compound_id/{compound_id}/{source_id}
//
// Sources described here:
// https://www.ebi.ac.uk/unichem/ucquery/listSources
type CompoundID struct {
// source_id 1
ChEMBL string `json:"chembl,omitempty"`
// source_id 22
PubChem string `json:"pubchem,omitempty"`
// source_id 2
DrugBank string `json:"drugbank,omitempty"`
// source_id 7
ChEBI string `json:"chebi,omitempty"`
}
func main() {
inputFile := ""
outputFile := ""
flag.StringVar(&inputFile, "input", inputFile, "input file")
flag.StringVar(&outputFile, "output", outputFile, "output file path")
flag.Parse()
var out io.WriteCloser
var err error
if outputFile != "" {
outputFile, err = filepath.Abs(outputFile)
if err != nil {
panic(err)
}
d := filepath.Dir(outputFile)
err = os.MkdirAll(d, 0755)
if err != nil {
panic(err)
}
out, err = os.Create(outputFile)
if err != nil {
panic(err)
}
} else {
out = os.Stdout
}
defer out.Close()
file, err := os.Open(inputFile)
if err != nil {
panic(err)
}
defer file.Close()
// writer := json.NewEncoder(out)
// scanner := bufio.NewScanner(file)
// for scanner.Scan() {
// interaction := Record{}
// err = json.Unmarshal(scanner.Bytes(), &interactions)
// if err != nil {
// panic(err)
// }
// err = writer.Encode(cid)
// if err != nil {
// panic(err)
// }
// }
}