github.com/vertgenlab/gonomics@v1.0.0/cigar/tools.go (about) 1 package cigar 2 3 // AddCigar adds a cigar struct to the end of a slice, but is smart about checking 4 // to see if the addition is the same operation that is present at the end of the 5 // existing slice and just increasing the run length of that entry. 6 func AddCigar(cigs []Cigar, newCig Cigar) []Cigar { 7 if len(cigs) == 0 { 8 cigs = append(cigs, newCig) 9 } else if cigs[len(cigs)-1].Op == newCig.Op { 10 cigs[len(cigs)-1].RunLength += newCig.RunLength 11 } else { 12 cigs = append(cigs, newCig) 13 } 14 return cigs 15 } 16 17 // CatCigar cats two cigars together, but is smart about checking to see if the 18 // last element of the first slice is the same operation as the first element 19 // of the second slice. In this case it will compress that struct into a single 20 // element with a longer run length. 21 func CatCigar(cigs []Cigar, newCigs []Cigar) []Cigar { 22 if len(newCigs) == 0 || newCigs == nil { 23 return cigs 24 } else if len(cigs) == 0 { 25 return newCigs 26 } else { 27 cigs = AddCigar(cigs, newCigs[0]) 28 cigs = append(cigs, newCigs[1:]...) 29 return cigs 30 } 31 }