File: normalize.go

package info (click to toggle)
golang-github-brentp-vcfgo 0.0~git20250902.a31336c-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,940 kB
  • sloc: makefile: 5; sh: 1
file content (52 lines) | stat: -rw-r--r-- 1,047 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package vcfgo

func leftalign(pos int, ref []byte, alt []byte, seq []byte) (int, []byte, []byte, error) {
	/* actually this isn't necessary
	if !bytes.HasSuffix(seq, ref) {
		return 0, ref, alt, errors.New("leftalign: sequence should end with ref")
	}
	*/
	subseq := seq[:len(seq)-len(ref)]

	quit := false
	j := len(subseq)

	for j > 0 && !quit {
		quit = true
		if ref[len(ref)-1] == alt[len(alt)-1] {
			ref = ref[:len(ref)-1]
			alt = alt[:len(alt)-1]
			quit = false
		}
		if len(ref) == 0 || len(alt) == 0 {
			j--
			// use j + 1 to get a slice.
			ref = append(subseq[j:j+1], ref...)
			alt = append(subseq[j:j+1], alt...)
			quit = false

		}

	}
	return pos - (len(subseq) - j), ref, alt, nil
}

func lefttrim(pos int, ref []byte, alt []byte) (int, []byte, []byte, error) {
	if 1 == len(ref) && len(alt) == 1 {
		return pos, ref, alt, nil
	}

	n := 0
	minLen := len(ref)
	if len(alt) < minLen {
		minLen = len(alt)
	}

	for n+1 < minLen && alt[n] == ref[n] {
		n++
	}

	alt, ref = alt[n:], ref[n:]
	pos += n
	return pos, ref, alt, nil
}