Debian Codegraph @

align/pals/features.go

raw symbols SCIP
1 // Copyright ©2012 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 pals
6
7 import (
8 "github.com/biogo/biogo/feat"
9 "github.com/biogo/biogo/seq"
10 "github.com/biogo/graph"
11
12 "fmt"
13 )
14
15 // A Contig is a base feature type. Other features in the pals package point to this type in
16 // their location fields.
17 type Contig string
18
19 // Name returns the value of the receiver as a string.
20 func (c Contig) Name() string { return string(c) }
21
22 // Description returns the string "contig".
23 func (c Contig) Description() string { return "contig" }
24
25 // Start returns the value 0.
26 func (c Contig) Start() int { return 0 }
27
28 // End returns the value 0.
29 func (c Contig) End() int { return 0 }
30
31 // Len returns the value 0.
32 func (c Contig) Len() int { return 0 }
33
34 // Location returns a nil feat.Feature.
35 func (c Contig) Location() feat.Feature { return nil }
36
37 // String returns the value of the receiver as a string.
38 func (c Contig) String() string { return string(c) }
39
40 // A Feature is a description of a pals feature interval.
41 type Feature struct {
42 ID string
43 From int
44 To int
45 Loc feat.Feature
46 Pair *Pair
47 }
48
49 func (f *Feature) Name() string {
50 if f == nil {
51 return "<nil>"
52 }
53 return f.ID
54 }
55
56 // Description returns the string "pals feature".
57 func (f *Feature) Description() string { return "pals feature" }
58 func (f *Feature) Start() int { return f.From }
59 func (f *Feature) End() int { return f.To }
60 func (f *Feature) Len() int { return f.To - f.From }
61 func (f *Feature) Location() feat.Feature { return f.Loc }
62
63 func (f *Feature) String() string {
64 if f == nil {
65 return "<nil>"
66 }
67 return fmt.Sprintf("%s[%d,%d)", f.Loc.Name(), f.From, f.To)
68 }
69
70 // Mate returns the feature pair mate of the receiver.
71 func (f *Feature) Mate() *Feature {
72 switch f {
73 case f.Pair.A:
74 return f.Pair.B
75 case f.Pair.B:
76 return f.Pair.A
77 }
78 return nil
79 }
80
81 // A Pile is a collection of features covering a maximal (potentially contiguous, depending on
82 // the value of overlap used for creation of the Piler) region of copy count > 0.
83 //
84 // The graph.Node interface support of Pile is subject to change.
85 // TODO(kortschak): Replace biogo/graph use with gonum/graph.
86 type Pile struct {
87 From int
88 To int
89 Strand seq.Strand
90 Loc feat.Feature
91 Images []*Feature
92 graph.Node
93 }
94
95 func (p *Pile) Name() string {
96 if p == nil {
97 return "<nil>"
98 }
99 return fmt.Sprintf("%s[%d,%d)", p.Loc.Name(), p.From, p.To)
100 }
101
102 // Description returns the string "pile".
103 func (p *Pile) Description() string { return "pile" }
104 func (p *Pile) Start() int { return p.From }
105 func (p *Pile) End() int { return p.To }
106 func (p *Pile) Len() int { return p.To - p.From }
107 func (p *Pile) Location() feat.Feature { return p.Loc }
108
109 func (p *Pile) String() string {
110 if p == nil {
111 return "<nil>"
112 }
113 return fmt.Sprintf("{%s[%d,%d): %v}", p.Loc.Name(), p.From, p.To, p.Images)
114 }