mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Make obiconsensus using the count of the sequences
Former-commit-id: 7fc5292aeb225843a86cd85591a5405e35125e3d
This commit is contained in:
@ -64,7 +64,7 @@ func MakeOptions(setters []WithOption) Options {
|
|||||||
csv_keys: make([]string, 0),
|
csv_keys: make([]string, 0),
|
||||||
csv_auto: false,
|
csv_auto: false,
|
||||||
paired_filename: "",
|
paired_filename: "",
|
||||||
source: "",
|
source: "unknown",
|
||||||
with_feature_table: false,
|
with_feature_table: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@ func (g *DeBruijnGraph) Weight(index uint64) int {
|
|||||||
return int(val)
|
return int(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (graph *DeBruijnGraph) append(sequence []byte, current uint64) {
|
func (graph *DeBruijnGraph) append(sequence []byte, current uint64, weight int) {
|
||||||
|
|
||||||
for i := 0; i < len(sequence); i++ {
|
for i := 0; i < len(sequence); i++ {
|
||||||
current <<= 2
|
current <<= 2
|
||||||
@ -323,14 +323,14 @@ func (graph *DeBruijnGraph) append(sequence []byte, current uint64) {
|
|||||||
b := iupac[sequence[i]]
|
b := iupac[sequence[i]]
|
||||||
if len(b) == 1 {
|
if len(b) == 1 {
|
||||||
current |= b[0]
|
current |= b[0]
|
||||||
graph.graph[current] = uint(graph.Weight(current) + 1)
|
graph.graph[current] = uint(graph.Weight(current) + weight)
|
||||||
} else {
|
} else {
|
||||||
for j := 0; j < len(b); j++ {
|
for j := 0; j < len(b); j++ {
|
||||||
current &= ^uint64(3)
|
current &= ^uint64(3)
|
||||||
current |= b[j]
|
current |= b[j]
|
||||||
|
|
||||||
graph.graph[current] = uint(graph.Weight(current) + 1)
|
graph.graph[current] = uint(graph.Weight(current) + weight)
|
||||||
graph.append(sequence[(i+1):], current)
|
graph.append(sequence[(i+1):], current, weight)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -341,6 +341,7 @@ func (graph *DeBruijnGraph) append(sequence []byte, current uint64) {
|
|||||||
func (graph *DeBruijnGraph) Push(sequence *obiseq.BioSequence) {
|
func (graph *DeBruijnGraph) Push(sequence *obiseq.BioSequence) {
|
||||||
key := uint64(0)
|
key := uint64(0)
|
||||||
s := sequence.Sequence()
|
s := sequence.Sequence()
|
||||||
|
w := sequence.Count()
|
||||||
init := make([]uint64, 0, 16)
|
init := make([]uint64, 0, 16)
|
||||||
var f func(start int, key uint64)
|
var f func(start int, key uint64)
|
||||||
f = func(start int, key uint64) {
|
f = func(start int, key uint64) {
|
||||||
@ -365,7 +366,7 @@ func (graph *DeBruijnGraph) Push(sequence *obiseq.BioSequence) {
|
|||||||
f(0, key)
|
f(0, key)
|
||||||
|
|
||||||
for _, idx := range init {
|
for _, idx := range init {
|
||||||
graph.append(s[graph.kmersize:], idx)
|
graph.append(s[graph.kmersize:], idx, w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,9 +99,19 @@ func BuildConsensus(seqs obiseq.BioSequenceSlice,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
seq, err := graph.LongestConsensus(seqs[0].Source())
|
id := seqs[0].Source()
|
||||||
|
if id == "" {
|
||||||
|
id = seqs[0].Id()
|
||||||
|
}
|
||||||
|
seq, err := graph.LongestConsensus(id)
|
||||||
|
|
||||||
seq.SetCount(len(seqs))
|
sumCount := 0
|
||||||
|
|
||||||
|
for _, s := range seqs {
|
||||||
|
sumCount += s.Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
seq.SetCount(sumCount)
|
||||||
seq.SetAttribute("seq_length", seq.Len())
|
seq.SetAttribute("seq_length", seq.Len())
|
||||||
seq.SetAttribute("kmer_size", kmer_size)
|
seq.SetAttribute("kmer_size", kmer_size)
|
||||||
seq.SetAttribute("kmer_min_occur", threshold)
|
seq.SetAttribute("kmer_min_occur", threshold)
|
||||||
|
Reference in New Issue
Block a user