mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
few bug in the graph algorithm
Former-commit-id: b61bdd9f671e2f5e90d32c1beac1ed84efa5e05c
This commit is contained in:
@ -3,6 +3,7 @@ package obikmer
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
|
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
|
||||||
)
|
)
|
||||||
@ -166,9 +167,10 @@ func (g *DeBruijnGraph) MaxNext(index uint64) (uint64, bool) {
|
|||||||
max := uint(0)
|
max := uint(0)
|
||||||
rep := uint64(0)
|
rep := uint64(0)
|
||||||
for _, idx := range ns {
|
for _, idx := range ns {
|
||||||
w, _ := g.graph[idx]
|
w := g.graph[idx]
|
||||||
if w > max {
|
if w > max {
|
||||||
rep = idx
|
rep = idx
|
||||||
|
max = w
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,9 +198,10 @@ func (g *DeBruijnGraph) LongestPath() []uint64 {
|
|||||||
ok := true
|
ok := true
|
||||||
|
|
||||||
starts := g.Heads()
|
starts := g.Heads()
|
||||||
|
log.Println(starts)
|
||||||
for _, idx := range starts {
|
for _, idx := range starts {
|
||||||
lp := make([]uint64, 0, 1000)
|
lp := make([]uint64, 0, 1000)
|
||||||
|
ok = true
|
||||||
w := uint(0)
|
w := uint(0)
|
||||||
for ok {
|
for ok {
|
||||||
nw := g.graph[idx]
|
nw := g.graph[idx]
|
||||||
@ -207,13 +210,13 @@ func (g *DeBruijnGraph) LongestPath() []uint64 {
|
|||||||
idx, ok = g.MaxNext(idx)
|
idx, ok = g.MaxNext(idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("max : %d current %d", wmax, w)
|
||||||
if w > wmax {
|
if w > wmax {
|
||||||
path = lp
|
path = lp
|
||||||
wmax = w
|
wmax = w
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +237,6 @@ func (g *DeBruijnGraph) LongestConsensus(id string) (*obiseq.BioSequence,error)
|
|||||||
return nil, fmt.Errorf("cannot identify optimum path")
|
return nil, fmt.Errorf("cannot identify optimum path")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (g *DeBruijnGraph) Heads() []uint64 {
|
func (g *DeBruijnGraph) Heads() []uint64 {
|
||||||
rep := make([]uint64, 0, 10)
|
rep := make([]uint64, 0, 10)
|
||||||
|
|
||||||
@ -374,3 +376,51 @@ func (graph *DeBruijnGraph) Push(sequence *obiseq.BioSequence) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (graph *DeBruijnGraph) GML() string {
|
||||||
|
buffer := bytes.NewBuffer(make([]byte, 0, 1000))
|
||||||
|
|
||||||
|
buffer.WriteString(
|
||||||
|
`graph [
|
||||||
|
comment "De Bruijn graph"
|
||||||
|
directed 1
|
||||||
|
|
||||||
|
`)
|
||||||
|
|
||||||
|
for idx := range graph.graph {
|
||||||
|
node := graph.DecodeNode(idx)
|
||||||
|
buffer.WriteString(
|
||||||
|
fmt.Sprintf("node [ id \"%s\" ]\n", node),
|
||||||
|
)
|
||||||
|
n := graph.Nexts(uint64(idx))
|
||||||
|
if len(n) == 0 {
|
||||||
|
idx <<= 2
|
||||||
|
idx &= graph.kmermask
|
||||||
|
node := graph.DecodeNode(idx)
|
||||||
|
buffer.WriteString(
|
||||||
|
fmt.Sprintf("node [ id \"%s\" \n label \"%s\" ]\n", node, node),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for idx, weight := range graph.graph {
|
||||||
|
src := graph.DecodeNode(idx)
|
||||||
|
label := decode[idx&3]
|
||||||
|
idx <<= 2
|
||||||
|
idx &= graph.kmermask
|
||||||
|
dst := graph.DecodeNode(idx)
|
||||||
|
|
||||||
|
buffer.WriteString(
|
||||||
|
fmt.Sprintf(`edge [ source "%s"
|
||||||
|
target "%s"
|
||||||
|
color "#00FF00"
|
||||||
|
label "%c[%d]"
|
||||||
|
]
|
||||||
|
|
||||||
|
`, src, dst, label, weight),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
buffer.WriteString("]\n")
|
||||||
|
return buffer.String()
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -63,10 +63,20 @@ func BuildConsensus(seqs obiseq.BioSequenceSlice, quorum float64) (*obiseq.BioSe
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
threshold /= 2
|
||||||
graph.FilterMin(threshold)
|
graph.FilterMin(threshold)
|
||||||
log.Printf("Graph size : %d\n", graph.Len())
|
log.Printf("Graph size : %d\n", graph.Len())
|
||||||
|
|
||||||
|
// file, err := os.Create(
|
||||||
|
// fmt.Sprintf("%s.gml", seqs[0].Source()))
|
||||||
|
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Println(err)
|
||||||
|
// } else {
|
||||||
|
// file.WriteString(graph.GML())
|
||||||
|
// file.Close()
|
||||||
|
// }
|
||||||
|
|
||||||
seq, err := graph.LongestConsensus(seqs[0].Source())
|
seq, err := graph.LongestConsensus(seqs[0].Source())
|
||||||
|
|
||||||
seq.SetCount(len(seqs))
|
seq.SetCount(len(seqs))
|
||||||
|
Reference in New Issue
Block a user