Skip to content

Commit

Permalink
[prune] Replace *AlleleGroup with groupID
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed Sep 4, 2018
1 parent 7d66dbe commit dba743f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type AlleleGroup []string

// CtgAlleleGroupPair stores a pair of the contig and the alleleGroup it resides in
type CtgAlleleGroupPair struct {
ctg string
alleleGroup *AlleleGroup
ctg string
groupID int
}

// Run calls the pruning steps
Expand Down Expand Up @@ -87,13 +87,13 @@ func (r *Pruner) pruneAllelic() {
// of removal may affect end results.
func (r *Pruner) pruneCrossAllelic() {
// Store contig to list of alleleGroups since each contig can be in different alleleGroups
ctgToAlleleGroup := map[string][]*AlleleGroup{}
for _, alleleGroup := range r.alleleGroups {
ctgToAlleleGroup := map[string][]int{}
for groupID, alleleGroup := range r.alleleGroups {
for _, ctg := range alleleGroup {
if gg, ok := ctgToAlleleGroup[ctg]; ok {
gg = append(gg, &alleleGroup)
gg = append(gg, groupID)
} else {
ctgToAlleleGroup[ctg] = []*AlleleGroup{&alleleGroup}
ctgToAlleleGroup[ctg] = []int{groupID}
}
}
}
Expand All @@ -110,15 +110,16 @@ func (r *Pruner) pruneCrossAllelic() {
for i, edge := range r.edges {
if edge.nObservedLinks < getScore(edge.at, edge.bt, ctgToAlleleGroup, scores) ||
edge.nObservedLinks < getScore(edge.bt, edge.at, ctgToAlleleGroup, scores) {
r.edges[i].label = "cross-allelic"
r.edges[i].label = fmt.Sprintf("cross-allelic(%d, %d)", getScore(edge.at, edge.bt, ctgToAlleleGroup, scores),
getScore(edge.bt, edge.at, ctgToAlleleGroup, scores))
pruned++
}
}
log.Noticef("Cross-allelic pairs pruned: %d", pruned)
}

// updateScore takes a potential pair of contigs and update scores
func updateScore(at, bt string, score int, ctgToAlleleGroup map[string][]*AlleleGroup, scores map[CtgAlleleGroupPair]int) {
func updateScore(at, bt string, score int, ctgToAlleleGroup map[string][]int, scores map[CtgAlleleGroupPair]int) {
if gg, ok := ctgToAlleleGroup[bt]; ok {
// Update through all alleleGroups that contig b sits in
for _, bg := range gg {
Expand All @@ -135,7 +136,7 @@ func updateScore(at, bt string, score int, ctgToAlleleGroup map[string][]*Allele
}

// getScore takes a pair of contigs and get the maximum score to the allele group
func getScore(at, bt string, ctgToAlleleGroup map[string][]*AlleleGroup, scores map[CtgAlleleGroupPair]int) int {
func getScore(at, bt string, ctgToAlleleGroup map[string][]int, scores map[CtgAlleleGroupPair]int) int {
if gg, ok := ctgToAlleleGroup[bt]; ok {
maxScore := -1
for _, bg := range gg {
Expand Down

0 comments on commit dba743f

Please sign in to comment.