Exemple #1
0
// Transform return Burrows-Wheeler-Transform of s
func (fmi *FMIndex) Transform(s []byte) ([]byte, error) {
	bwt, rotations, err := bwt.Transform(s, fmi.EndSymbol)
	if err != nil {
		return nil, err
	}
	fmi.BWT = bwt
	fmi.M = rotations
	fmi.CountOfLetters = byteutil.CountOfByte(fmi.BWT)
	fmi.Alphabet = byteutil.AlphabetFromCountOfByte(fmi.CountOfLetters)
	fmi.C = ComputeC(fmi.M, fmi.Alphabet)
	fmi.Occ = ComputeOccurrence(fmi.BWT, fmi.Alphabet)
	return bwt, nil
}
Exemple #2
0
// Transform returns Burrows–Wheeler transform  of a byte slice.
// See https://en.wikipedia.org/wiki/Burrows%E2%80%93Wheeler_transform
func Transform(s []byte, es byte) ([]byte, [][]byte, error) {
	count := byteutil.CountOfByte(s)
	if _, ok := count[es]; ok {
		return nil, nil, ErrEndSymbolExisted
	}
	s = append(s, es)
	n := len(s)

	rotations := make([][]byte, n)
	i := 0
	for j := 0; j < n; j++ {
		rotations[i] = append(s[n-j:], s[0:n-j]...)
		i++
	}
	sort.Sort(byteutil.SliceOfByteSlice(rotations))

	bwt := make([]byte, n)
	i = 0
	for _, t := range rotations {
		bwt[i] = t[n-1]
		i++
	}
	return bwt, rotations, nil
}