// calcSNPArr calculate correlation of the first SNP with the rest. // It finds pairs of bases that are from the same read, // compare every two pairs of bases, // and compute several correlations, which is contained in a calculator. // A calculator here is a black box. // calcSNPArr only push inputs into the calculator. func (cmd *cmdCt) calcSNPArr(snpArr []*pileup.SNP, calculator *calc.Calculator, xArr, yArr []float64) { s1 := snpArr[0] m := make(map[string]pileup.Allele) for _, a := range s1.Alleles { if isATGC(a.Base) { m[a.QName] = a } } pairs := make([]AllelePair, len(m)) for k := 0; k < len(snpArr); k++ { s2 := snpArr[k] // double check the lag. // it expects an order array of SNPs. l := s2.Pos - s1.Pos if l >= cmd.maxl { break } else if l < 0 { cmd.panic("SNPs is not in order.") } numPair := cmd.findPairs(m, s2.Alleles, pairs) // check the coverage. // if less than min coverage, skip. if numPair < cmd.minCoverage { continue } k := 0 for i := 0; i < numPair && k < len(xArr); i++ { p1 := pairs[i] for j := i + 1; j < numPair && k < len(xArr); j++ { p2 := pairs[j] x := cmd.diffBases(p1.A.Base, p2.A.Base) y := cmd.diffBases(p1.B.Base, p2.B.Base) xArr[k] = x yArr[k] = y k++ } } calculator.Increment(xArr[:k], yArr[:k], l) } }