| 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 feat |
| 6 | |
| 7 | import ( |
| 8 | "strings" |
| 9 | ) |
| 10 | |
| 11 | const ( |
| 12 | Undefined Moltype = iota - 1 |
| 13 | DNA |
| 14 | RNA |
| 15 | Protein |
| 16 | ) |
| 17 | |
| 18 | var ( |
| 19 | moltypeToString = [...]string{ |
| 20 | "DNA", "RNA", "Protein", |
| 21 | } |
| 22 | stringToMoltype map[string]Moltype = map[string]Moltype{} |
| 23 | ) |
| 24 | |
| 25 | func init() { |
| 26 | for m, s := range moltypeToString { |
| 27 | stringToMoltype[strings.ToLower(s)] = Moltype(m) |
| 28 | stringToMoltype[s] = Moltype(m) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | // Moltype represents the molecule type of a source of sequence data. |
| 33 | type Moltype int8 |
| 34 | |
| 35 | // Return a string representation of a Moltype. |
| 36 | func (m Moltype) String() string { |
| 37 | if m == Undefined { |
| 38 | return "Undefined" |
| 39 | } |
| 40 | return moltypeToString[m] |
| 41 | } |
| 42 | |
| 43 | // ParseMoltype allows conversion from a string to a Moltype. |
| 44 | func ParseMoltype(s string) Moltype { |
| 45 | if m, ok := stringToMoltype[s]; ok { |
| 46 | return m |
| 47 | } |
| 48 | |
| 49 | return Undefined |
| 50 | } |