| 1 | // Copyright © 2018-2021 Wei Shen <[email protected]> |
| 2 | // |
| 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | // of this software and associated documentation files (the "Software"), to deal |
| 5 | // in the Software without restriction, including without limitation the rights |
| 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | // copies of the Software, and to permit persons to whom the Software is |
| 8 | // furnished to do so, subject to the following conditions: |
| 9 | // |
| 10 | // The above copyright notice and this permission notice shall be included in |
| 11 | // all copies or substantial portions of the Software. |
| 12 | // |
| 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 19 | // THE SOFTWARE. |
| 20 | |
| 21 | package kmers |
| 22 | |
| 23 | // KmerCodeSlice is a slice of KmerCode, for sorting |
| 24 | type KmerCodeSlice []KmerCode |
| 25 | |
| 26 | // Len return length of the slice |
| 27 | func (codes KmerCodeSlice) Len() int { |
| 28 | return len(codes) |
| 29 | } |
| 30 | |
| 31 | // Swap swaps two elements |
| 32 | func (codes KmerCodeSlice) Swap(i, j int) { |
| 33 | codes[i], codes[j] = codes[j], codes[i] |
| 34 | } |
| 35 | |
| 36 | // Less simply compare two KmerCode |
| 37 | func (codes KmerCodeSlice) Less(i, j int) bool { |
| 38 | return codes[i].Code < codes[j].Code |
| 39 | } |
| 40 | |
| 41 | // func splitKmer(code uint64, k int) (uint64, uint64, uint64, uint64) { |
| 42 | // // -====, k = 4: ---, -, =, === |
| 43 | // return code >> 2, code & 3, code >> (uint(k-1) << 1) & 3, code & ((1 << (uint(k-1) << 1)) - 1) |
| 44 | // } |
| 45 | |
| 46 | // CodeSlice is a slice of Kmer code (uint64), for sorting |
| 47 | type CodeSlice []uint64 |
| 48 | |
| 49 | // Len return length of the slice |
| 50 | func (codes CodeSlice) Len() int { |
| 51 | return len(codes) |
| 52 | } |
| 53 | |
| 54 | // Swap swaps two elements |
| 55 | func (codes CodeSlice) Swap(i, j int) { |
| 56 | codes[i], codes[j] = codes[j], codes[i] |
| 57 | } |
| 58 | |
| 59 | // Less simply compare two KmerCode |
| 60 | func (codes CodeSlice) Less(i, j int) bool { |
| 61 | return codes[i] < codes[j] |
| 62 | } |