Debian Codegraph @

io/featio/featio_test.go

raw
1 // Copyright ©2011-2013 The bíogo Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package featio_test
6
7 import (
8 "github.com/biogo/biogo/io/featio"
9 "github.com/biogo/biogo/io/featio/gff"
10 "github.com/biogo/biogo/seq"
11
12 "bytes"
13 "testing"
14
15 "gopkg.in/check.v1"
16 )
17
18 // Helpers
19 func floatPtr(f float64) *float64 { return &f }
20
21 // Tests
22 func Test(t *testing.T) { check.TestingT(t) }
23
24 type S struct{}
25
26 var _ = check.Suite(&S{})
27
28 func (s *S) TestReadGFF(c *check.C) {
29 for i, g := range []struct {
30 gff string
31 feat []*gff.Feature
32 }{
33 {
34 gff: `SEQ1 EMBL atg 103 105 . + 0
35 SEQ1 EMBL exon 103 172 . + 0
36 SEQ1 EMBL splice5 172 173 . + .
37 SEQ1 netgene splice5 172 173 0.94 + .
38 SEQ1 genie sp5-20 163 182 2.3 + .
39 SEQ1 genie sp5-10 168 177 2.1 + .
40 SEQ2 grail ATG 17 19 2.1 - 0
41 `,
42 feat: []*gff.Feature{
43 {SeqName: "SEQ1", Source: "EMBL", Feature: "atg", FeatStart: 102, FeatEnd: 105, FeatScore: nil, FeatFrame: gff.Frame0, FeatStrand: seq.Plus},
44 {SeqName: "SEQ1", Source: "EMBL", Feature: "exon", FeatStart: 102, FeatEnd: 172, FeatScore: nil, FeatFrame: gff.Frame0, FeatStrand: seq.Plus},
45 {SeqName: "SEQ1", Source: "EMBL", Feature: "splice5", FeatStart: 171, FeatEnd: 173, FeatScore: nil, FeatFrame: gff.NoFrame, FeatStrand: seq.Plus},
46 {SeqName: "SEQ1", Source: "netgene", Feature: "splice5", FeatStart: 171, FeatEnd: 173, FeatScore: floatPtr(0.94), FeatFrame: gff.NoFrame, FeatStrand: seq.Plus},
47 {SeqName: "SEQ1", Source: "genie", Feature: "sp5-20", FeatStart: 162, FeatEnd: 182, FeatScore: floatPtr(2.3), FeatFrame: gff.NoFrame, FeatStrand: seq.Plus},
48 {SeqName: "SEQ1", Source: "genie", Feature: "sp5-10", FeatStart: 167, FeatEnd: 177, FeatScore: floatPtr(2.1), FeatFrame: gff.NoFrame, FeatStrand: seq.Plus},
49 {SeqName: "SEQ2", Source: "grail", Feature: "ATG", FeatStart: 16, FeatEnd: 19, FeatScore: floatPtr(2.1), FeatFrame: gff.Frame0, FeatStrand: seq.Minus},
50 },
51 },
52 } {
53 sc := featio.NewScanner(
54 gff.NewReader(
55 bytes.NewBufferString(g.gff),
56 ),
57 )
58
59 var j int
60 for sc.Next() {
61 f := sc.Feat()
62 c.Check(f, check.DeepEquals, g.feat[j], check.Commentf("Test: %d Line: %d", i, j+1))
63 j++
64 }
65 c.Check(sc.Error(), check.Equals, nil)
66 c.Check(j, check.Equals, len(g.feat))
67 }
68 }
69
70 func (s *S) TestReadFromFunc(c *check.C) {
71 for i, g := range []struct {
72 gff string
73 feat []*gff.Feature
74 }{
75 {
76 gff: `SEQ1 EMBL atg 103 105 . + 0
77 SEQ1 EMBL exon 103 172 . + 0
78 SEQ1 EMBL splice5 172 173 . + .
79 SEQ1 netgene splice5 172 173 0.94 + .
80 SEQ1 genie sp5-20 163 182 2.3 + .
81 SEQ1 genie sp5-10 168 177 2.1 + .
82 SEQ2 grail ATG 17 19 2.1 - 0
83 `,
84 feat: []*gff.Feature{
85 {SeqName: "SEQ1", Source: "EMBL", Feature: "atg", FeatStart: 102, FeatEnd: 105, FeatScore: nil, FeatFrame: gff.Frame0, FeatStrand: seq.Plus},
86 {SeqName: "SEQ1", Source: "EMBL", Feature: "exon", FeatStart: 102, FeatEnd: 172, FeatScore: nil, FeatFrame: gff.Frame0, FeatStrand: seq.Plus},
87 {SeqName: "SEQ1", Source: "EMBL", Feature: "splice5", FeatStart: 171, FeatEnd: 173, FeatScore: nil, FeatFrame: gff.NoFrame, FeatStrand: seq.Plus},
88 {SeqName: "SEQ1", Source: "netgene", Feature: "splice5", FeatStart: 171, FeatEnd: 173, FeatScore: floatPtr(0.94), FeatFrame: gff.NoFrame, FeatStrand: seq.Plus},
89 {SeqName: "SEQ1", Source: "genie", Feature: "sp5-20", FeatStart: 162, FeatEnd: 182, FeatScore: floatPtr(2.3), FeatFrame: gff.NoFrame, FeatStrand: seq.Plus},
90 {SeqName: "SEQ1", Source: "genie", Feature: "sp5-10", FeatStart: 167, FeatEnd: 177, FeatScore: floatPtr(2.1), FeatFrame: gff.NoFrame, FeatStrand: seq.Plus},
91 {SeqName: "SEQ2", Source: "grail", Feature: "ATG", FeatStart: 16, FeatEnd: 19, FeatScore: floatPtr(2.1), FeatFrame: gff.Frame0, FeatStrand: seq.Minus},
92 },
93 },
94 } {
95 sc := featio.NewScannerFromFunc(
96 gff.NewReader(
97 bytes.NewBufferString(g.gff),
98 ).Read,
99 )
100
101 var j int
102 for sc.Next() {
103 f := sc.Feat()
104 c.Check(f, check.DeepEquals, g.feat[j], check.Commentf("Test: %d Line: %d", i, j+1))
105 j++
106 }
107 c.Check(sc.Error(), check.Equals, nil)
108 c.Check(j, check.Equals, len(g.feat))
109 }
110 }