mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
27 lines
636 B
Go
27 lines
636 B
Go
|
package obiseq
|
||
|
|
||
|
// ".ABCDEFGHIJKLMNOPQRSTUVWXYZ#![]"
|
||
|
var __revcmp_dna__ = []byte(".TVGHEFCDIJMLKNOPQYSAABWXRZ#!][")
|
||
|
|
||
|
// Reverse complements a DNA sequence.
|
||
|
// If the inplace parametter is true, that operation is done in place.
|
||
|
func (sequence BioSequence) ReverseComplement(inplace bool) BioSequence {
|
||
|
|
||
|
if !inplace {
|
||
|
sequence = sequence.Copy()
|
||
|
}
|
||
|
|
||
|
s := sequence.sequence.sequence.Bytes()
|
||
|
|
||
|
for i, j := sequence.Length()-1, 0; i >= j; i-- {
|
||
|
|
||
|
s[j], s[i] = __revcmp_dna__[s[i]&31]|(s[i]&0x20),
|
||
|
__revcmp_dna__[s[j]&31]|(s[j]&0x20)
|
||
|
j++
|
||
|
}
|
||
|
|
||
|
sequence.sequence.id.WriteString("_revcomp")
|
||
|
|
||
|
return sequence
|
||
|
}
|