mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-12-08 16:50:27 +00:00
First commit
This commit is contained in:
26
pkg/obiseq/revcomp.go
Normal file
26
pkg/obiseq/revcomp.go
Normal file
@@ -0,0 +1,26 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user