This repository has been archived by the owner on Feb 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OBOIndexing.go
78 lines (68 loc) · 1.71 KB
/
OBOIndexing.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
package HPO
import (
"bufio"
"fmt"
"io"
"os"
"strings"
"github.com/artonge/Tamalou/indexing"
)
func indexOBO() error {
// Open the obo file
file, err := os.Open("datas/hpo/hp.obo")
if err != nil {
return fmt.Errorf("Error in HPO's obo connector init\n Error ==> %v", err)
}
// Create a new Scanner to parse the file
scanner := bufio.NewScanner(file)
err = indexing.IndexDocs(index, func() (indexing.Indexable, error) {
return nextTerm(scanner)
})
return err
}
// Return the next term
func nextTerm(scanner *bufio.Scanner) (*hpoOBOStruct, error) {
// Go to the next [Term]
for scanner.Scan() {
if scanner.Text() == "[Term]" {
break
}
}
// Init the new term
term := new(hpoOBOStruct)
// Continue the file parsing from the last position
for scanner.Scan() {
switch scanner.Text() {
// End of a Term
case "":
return term, nil
// Properties of a Term
default:
lineParts := strings.SplitN(scanner.Text(), ": ", 2)
switch lineParts[0] {
case "id":
term.ID = lineParts[1]
case "alt_id":
term.AltIDs = append(term.AltIDs, lineParts[1])
case "name":
term.Name = lineParts[1]
case "def":
term.Definition = lineParts[1]
case "comment":
term.Comment = lineParts[1]
case "synonym":
term.Synonymes = append(term.Synonymes, lineParts[1])
case "xref":
term.Xrefs = append(term.Xrefs, lineParts[1])
case "is_a":
term.IsA = lineParts[1]
case "is_obsolete": // use with consider ?
term.Obsolete = true
case "created_by", "property_value", "replaced_by", "creation_date", "subset", "is_anonymous", "consider":
default:
fmt.Println("Warning: Unexpected field <", lineParts[0], "> during obo file parsing")
}
}
}
return term, io.EOF
}