| 1 |
package vcfgo |
| 2 |
|
| 3 |
func leftalign(pos int, ref []byte, alt []byte, seq []byte) (int, []byte, []byte, error) { |
| 4 |
/* actually this isn't necessary |
| 5 |
if !bytes.HasSuffix(seq, ref) { |
| 6 |
return 0, ref, alt, errors.New("leftalign: sequence should end with ref") |
| 7 |
} |
| 8 |
*/ |
| 9 |
subseq := seq[:len(seq)-len(ref)] |
| 10 |
|
| 11 |
quit := false |
| 12 |
j := len(subseq) |
| 13 |
|
| 14 |
for j > 0 && !quit { |
| 15 |
quit = true |
| 16 |
if ref[len(ref)-1] == alt[len(alt)-1] { |
| 17 |
ref = ref[:len(ref)-1] |
| 18 |
alt = alt[:len(alt)-1] |
| 19 |
quit = false |
| 20 |
} |
| 21 |
if len(ref) == 0 || len(alt) == 0 { |
| 22 |
j-- |
| 23 |
// use j + 1 to get a slice. |
| 24 |
ref = append(subseq[j:j+1], ref...) |
| 25 |
alt = append(subseq[j:j+1], alt...) |
| 26 |
quit = false |
| 27 |
|
| 28 |
} |
| 29 |
|
| 30 |
} |
| 31 |
return pos - (len(subseq) - j), ref, alt, nil |
| 32 |
} |
| 33 |
|
| 34 |
func lefttrim(pos int, ref []byte, alt []byte) (int, []byte, []byte, error) { |
| 35 |
if 1 == len(ref) && len(alt) == 1 { |
| 36 |
return pos, ref, alt, nil |
| 37 |
} |
| 38 |
|
| 39 |
n := 0 |
| 40 |
minLen := len(ref) |
| 41 |
if len(alt) < minLen { |
| 42 |
minLen = len(alt) |
| 43 |
} |
| 44 |
|
| 45 |
for n+1 < minLen && alt[n] == ref[n] { |
| 46 |
n++ |
| 47 |
} |
| 48 |
|
| 49 |
alt, ref = alt[n:], ref[n:] |
| 50 |
pos += n |
| 51 |
return pos, ref, alt, nil |
| 52 |
} |