Skip to content

Commit

Permalink
Merge pull request #99 from dictyBase/fix/deprecated-field
Browse files Browse the repository at this point in the history
Pulling fix/deprecated-field into develop
  • Loading branch information
kodiakhq[bot] authored Aug 14, 2023
2 parents 9c40ab0 + d4dcd78 commit 26deaf4
Show file tree
Hide file tree
Showing 7 changed files with 37,220 additions and 29,563 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ on:
- master
jobs:
lint:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: check out code
uses: actions/checkout@v3
- name: set up golang
uses: actions/setup-go@v4
with:
go-version: 1.20.4
go-version: '1.20'
cache: false
- name: run linter
uses: golangci/golangci-lint-action@v3
Expand Down
196 changes: 164 additions & 32 deletions graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,36 @@ func TestGraphProperties(t *testing.T) {
grph, err := BuildGraph(rdr)
assert.NoError(err, "expect no error from building the graph")
assert.Equal(grph.ID(), "so.owl", "expect graph Id to match")
assert.Equal(grph.IRI(), "http://purl.obolibrary.org/obo/so.owl", "expect to match graph IRI")
assert.Equal(
grph.IRI(),
"http://purl.obolibrary.org/obo/so.owl",
"expect to match graph IRI",
)

mta := grph.Meta()
ver := "http://purl.obolibrary.org/obo/so/so-xp/releases/2015-11-24/so-xp.owl/so.owl"
ver := "http://purl.obolibrary.org/obo/so/2021-11-22/so.owl"
assert.Equal(mta.Version(), ver, "expect to match version")
assert.Lenf(mta.BasicPropertyValues(), 5, "expected 5 got %d", len(mta.BasicPropertyValues()))
assert.Equalf(mta.Namespace(), "sequence", "expected sequence namespace got %s", mta.Namespace())
assert.Lenf(
mta.BasicPropertyValues(),
5,
"expected 5 got %d",
len(mta.BasicPropertyValues()),
)
assert.Equalf(
mta.Namespace(),
"sequence",
"expected sequence namespace got %s",
mta.Namespace(),
)
clst := grph.TermsByType("CLASS")
assert.Lenf(clst, 2432, "expected 2432 classes got %d", len(clst))
assert.Lenf(clst, 2729, "expected 2432 classes got %d", len(clst))
propt := grph.TermsByType("PROPERTY")
assert.Lenf(propt, 83, "expected 83 properties got %d", len(propt))
assert.Lenf(propt, 71, "expected 83 properties got %d", len(propt))
rels := grph.Relationships()
assert.Lenf(rels, 2919, "expect 2919 relationships got %d", len(rels))
assert.Lenf(rels, 3128, "expect 2919 relationships got %d", len(rels))
}

func TestGraphClassTerm(t *testing.T) {
func TestGraphClassTerm(t *testing.T) { //nolint:funlen
t.Parallel()
assert := require.New(t)
rdr, err := getReader()
Expand All @@ -69,19 +83,65 @@ func TestGraphClassTerm(t *testing.T) {
term := "SO_0000340"
assert.Truef(grph.ExistsTerm(NodeID(term)), "expect to find term %s", term)
cht := grph.GetTerm(NodeID(term))
assert.Equalf(cht.ID(), NodeID(term), "expect to match term %s got %s", term, cht.ID())
assert.Equalf(cht.Label(), "chromosome", "expect to match chromosome got %s", cht.Label())
assert.Equalf(cht.RdfType(), "CLASS", "expect to match rdf type CLASS got %s", cht.RdfType())
assert.Equalf(cht.IRI(), "http://purl.obolibrary.org/obo/SO_0000340", "expect to match IRI got %s", cht.IRI())
assert.Equalf(cht.Meta().Namespace(), "sequence", "expect meta namespace to be sequence got %s", cht.Meta().Namespace())
assert.Equalf(
cht.ID(),
NodeID(term),
"expect to match term %s got %s",
term,
cht.ID(),
)
assert.Equalf(
cht.Label(),
"chromosome",
"expect to match chromosome got %s",
cht.Label(),
)
assert.Equalf(
cht.RdfType(),
"CLASS",
"expect to match rdf type CLASS got %s",
cht.RdfType(),
)
assert.Equalf(
cht.IRI(),
"http://purl.obolibrary.org/obo/SO_0000340",
"expect to match IRI got %s",
cht.IRI(),
)
assert.Equalf(
cht.Meta().Namespace(),
"sequence",
"expect meta namespace to be sequence got %s",
cht.Meta().Namespace(),
)
sub := cht.Meta().Subsets()
assert.GreaterOrEqualf(len(sub), 1, "expect 1 or more subsets got %d", len(sub))
assert.GreaterOrEqualf(
len(sub),
1,
"expect 1 or more subsets got %d",
len(sub),
)
assert.Regexpf("SOFA", sub[0], "expect to match SOFA got %s", sub[0])
pval := cht.Meta().BasicPropertyValues()
assert.GreaterOrEqualf(len(pval), 1, "expect 1 or more properties got %d", len(pval))
assert.Equalf(pval[0].Value(), "sequence", "expect the value to be SEQ got %s", pval[0].Value())
assert.GreaterOrEqualf(
len(pval),
1,
"expect 1 or more properties got %d",
len(pval),
)
assert.Equalf(
pval[0].Value(),
"sequence",
"expect the value to be SEQ got %s",
pval[0].Value(),
)
cmc := cht.Meta().Comments()
assert.GreaterOrEqualf(len(cmc), 1, "expect 1 or more meta comments got %d", len(cmc))
assert.GreaterOrEqualf(
len(cmc),
1,
"expect 1 or more meta comments got %d",
len(cmc),
)
assert.Regexpf("MGED", cmc[0], "expect to match MGED got %s", cmc[0])
}

Expand All @@ -96,9 +156,23 @@ func TestGraphDeprecatedTerm(t *testing.T) {
term := "SO_1000100"
assert.Truef(grph.ExistsTerm(NodeID(term)), "expect to match %s term", term)
cht := grph.GetTerm(NodeID(term))
assert.Equalf(cht.ID(), NodeID(term), "expect to match %s got %s", term, cht.ID())
assert.Equal(cht.Label(), "mutation_causing_polypeptide_N_terminal_elongation")
assert.Equalf(cht.RdfType(), "CLASS", "expect to be CLASS but got %s", cht.RdfType())
assert.Equalf(
cht.ID(),
NodeID(term),
"expect to match %s got %s",
term,
cht.ID(),
)
assert.Equal(
cht.Label(),
"mutation_causing_polypeptide_N_terminal_elongation",
)
assert.Equalf(
cht.RdfType(),
"CLASS",
"expect to be CLASS but got %s",
cht.RdfType(),
)
assert.Equal(cht.IRI(), "http://purl.obolibrary.org/obo/SO_1000100")
assert.Truef(cht.IsDeprecated(), "expect %s to be deprecated", cht.ID())
}
Expand All @@ -111,17 +185,50 @@ func TestGraphPropertyTerm(t *testing.T) {
grph, err := BuildGraph(rdr)
assert.NoError(err, "expect no error from building the graph")

assert.True(grph.ExistsTerm(NodeID("derives_from")), "expect to find derives_from")
assert.True(
grph.ExistsTerm(NodeID("derives_from")),
"expect to find derives_from",
)
dft := grph.GetTerm(NodeID("derives_from"))
assert.Equalf(dft.ID(), NodeID("derives_from"), "expect to match derives_from got %s", dft.ID())
assert.Equalf(dft.IRI(), "http://purl.obolibrary.org/obo/so#derives_from", "expect to match IRI got %s", dft.IRI())
assert.Equalf(dft.Meta().Namespace(), "sequence", "expect sequence namespace got %s", dft.Meta().Namespace())
assert.Equalf(
dft.ID(),
NodeID("derives_from"),
"expect to match derives_from got %s",
dft.ID(),
)
assert.Equalf(
dft.IRI(),
"http://purl.obolibrary.org/obo/so#derives_from",
"expect to match IRI got %s",
dft.IRI(),
)
assert.Equalf(
dft.Meta().Namespace(),
"sequence",
"expect sequence namespace got %s",
dft.Meta().Namespace(),
)
subs := dft.Meta().Subsets()
assert.GreaterOrEqualf(len(subs), 1, "expect 1 or more subsets got %d", len(subs))
assert.GreaterOrEqualf(
len(subs),
1,
"expect 1 or more subsets got %d",
len(subs),
)
assert.Regexpf("SOFA", subs[0], "expect SOFA to match got %s", subs[0])
props := dft.Meta().BasicPropertyValues()
assert.GreaterOrEqualf(len(props), 1, "expect 1 or more props got %d", len(props))
assert.Equalf(props[0].Value(), "sequence", "expect sequence value got %s", props[0].Value())
assert.GreaterOrEqualf(
len(props),
1,
"expect 1 or more props got %d",
len(props),
)
assert.Equalf(
props[0].Value(),
"sequence",
"expect sequence value got %s",
props[0].Value(),
)
}

func TestGraphParentTraversal(t *testing.T) {
Expand All @@ -136,12 +243,22 @@ func TestGraphParentTraversal(t *testing.T) {
parents := termPipe(grph.Parents(NodeID(term)))
assert.Lenf(parents, 2, "expect 2 parents got %d", len(parents))
for _, pterm := range []string{"SO_0000704", "SO_0001411"} {
assert.Containsf(parents, NodeID(pterm), "expect %s to be in the parent", pterm)
assert.Containsf(
parents,
NodeID(pterm),
"expect %s to be in the parent",
pterm,
)
}
ancestors := termPipe(grph.Ancestors(NodeID(term)))
assert.Lenf(ancestors, 5, "expect 5 ancestors got %d", len(ancestors))
for _, aterm := range []string{"SO_0000704", "SO_0001411", "SO_0005855", "SO_0000001", "SO_0000110"} {
assert.Containsf(ancestors, NodeID(aterm), "expect %s to be in the ancestors", aterm)
assert.Containsf(
ancestors,
NodeID(aterm),
"expect %s to be in the ancestors",
aterm,
)
}
}

Expand All @@ -156,7 +273,12 @@ func TestGraphChildrenTraversal(t *testing.T) {
children := termPipe(grph.Children(NodeID(term)))
assert.Lenf(children, 4, "expect 4 children got %d", len(children))
for _, cterm := range []string{"SO_0000548", "SO_0000455", "SO_0000451", "SO_0000693"} {
assert.Containsf(children, NodeID(cterm), "expect %s to be in the children", cterm)
assert.Containsf(
children,
NodeID(cterm),
"expect %s to be in the children",
cterm,
)
}
desc := termPipe(grph.Descendents(NodeID(term)))
assert.Lenf(desc, 9, "expect 9 descendents got %s", len(desc))
Expand All @@ -171,7 +293,12 @@ func TestGraphChildrenTraversal(t *testing.T) {
"SO_0000697",
"SO_0000710",
} {
assert.Containsf(desc, NodeID(dterm), "expect %s to be present in descendents", term)
assert.Containsf(
desc,
NodeID(dterm),
"expect %s to be present in descendents",
term,
)
}
descDFS := termPipe(grph.DescendentsDFS(NodeID(term)))
assert.Lenf(descDFS, 9, "expect 9 descendents got %s", len(descDFS))
Expand All @@ -186,7 +313,12 @@ func TestGraphChildrenTraversal(t *testing.T) {
"SO_0000697",
"SO_0000710",
} {
assert.Containsf(descDFS, NodeID(dterm), "expect %s to be present in descendents", dterm)
assert.Containsf(
descDFS,
NodeID(dterm),
"expect %s to be present in descendents",
dterm,
)
}
}

Expand Down
12 changes: 8 additions & 4 deletions graph/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,14 @@ func buildTermMeta(jsm *schema.JSONMeta) *model.MetaOptions {
meta := buildBaseMeta(jsm)
if jsm.Synonyms != nil && len(jsm.Synonyms) > 0 {
var syn []*model.Synonym
for _, js := range jsm.Synonyms {
if len(js.Xrefs) > 0 {
syn = append(syn, model.NewSynonymWithRefs(js.Pred, js.Val, js.Xrefs))
for _, jsyn := range jsm.Synonyms {
if len(jsyn.Xrefs) > 0 {
syn = append(
syn,
model.NewSynonymWithRefs(jsyn.Pred, jsyn.Val, jsyn.Xrefs),
)
} else {
syn = append(syn, model.NewSynonym(js.Pred, js.Val))
syn = append(syn, model.NewSynonym(jsyn.Pred, jsyn.Val))
}
}
meta.Synonyms = syn
Expand Down Expand Up @@ -168,6 +171,7 @@ func buildBaseMeta(jsm *schema.JSONMeta) *model.MetaOptions {
}
mop.Xrefs = xref
}
mop.Deprecated = jsm.Deprecated

return mop
}
2 changes: 1 addition & 1 deletion graph/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (n *node) IsDeprecated() bool {
}
}

return false
return n.meta.IsDeprecated()
}

// HasMeta check for presence of any metadata.
Expand Down
6 changes: 6 additions & 0 deletions model/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type MetaOptions struct {
Comments []string
Subsets []string
Version string
Deprecated bool
}

// Meta is a container for hosting sets of PropertyValue objects.
Expand Down Expand Up @@ -126,3 +127,8 @@ func (m *Meta) Namespace() string {

return ""
}

// IsDeprecated returns a boolean indicating whether the meta information is deprecated.
func (m *Meta) IsDeprecated() bool {
return m.opt.Deprecated
}
1 change: 1 addition & 0 deletions schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type JSONMeta struct {
Comments []string `json:"comments"`
Definition *JSONDefintion `json:"definition"`
Version string `json:"version"`
Deprecated bool `json:"deprecated"`
Xrefs []struct {
Val string `json:"val"`
} `json:"xrefs"`
Expand Down
Loading

0 comments on commit 26deaf4

Please sign in to comment.