brentp / vcfgo

a golang library to read, write and manipulate files in the variant call format.

Repository from Github https://github.combrentp/vcfgoRepository from Github https://github.combrentp/vcfgo

Possible opt: splitGT fmt.Sprintf -> strconv.Itoa

akotlar opened this issue · comments

Line beginning: ai := fmt.Sprintf("%d", i). Not sure if this is a better solution.

func splitGT(m interface{}, i int) ([]interface{}, error) {
	ml := m.([]interface{})
	out := make([]interface{}, len(ml))
	ai := fmt.Sprintf("%d", i)
	for i, allelei := range ml {
		allele := allelei.(string)
		if allele == "0" {
			out[i] = "0"
		}
		if ai == allele {
			out[i] = "1"
		} else {
			out[i] = "."
		}
	}
	return out, nil
}

thanks! feel free to open pull-requests if you see any others.

Thanks!