type tileSeq map[string][]tileLibRef
-func (tseq tileSeq) Variants() []tileVariantID {
+func (tseq tileSeq) Variants() ([]tileVariantID, int, int) {
maxtag := 0
for _, refs := range tseq {
for _, ref := range refs {
}
}
vars := make([]tileVariantID, maxtag+1)
+ var kept, dropped int
for _, refs := range tseq {
for _, ref := range refs {
+ if vars[int(ref.tag)] != 0 {
+ dropped++
+ } else {
+ kept++
+ }
vars[int(ref.tag)] = ref.variant
}
}
- return vars
+ return vars, kept, dropped
}
type tileLibrary struct {
var seqlabel string
for scanner.Scan() {
buf := scanner.Bytes()
- if len(buf) == 0 || buf[0] == '>' {
+ if len(buf) > 0 && buf[0] == '>' {
todo <- jobT{seqlabel, fasta}
seqlabel, fasta = string(buf[1:]), nil
log.Debugf("%s %s reading fasta", filelabel, seqlabel)
}
found := make([]foundtag, 2000000)
path := make([]tileLibRef, 2000000)
+ totalFoundTags := 0
totalPathLen := 0
skippedSequences := 0
for job := range todo {
tilelib.taglib.FindAll(job.fasta, func(tagid tagID, pos, taglen int) {
found = append(found, foundtag{pos: pos, tagid: tagid, taglen: taglen})
})
+ totalFoundTags += len(found)
+
+ skipped := 0
path = path[:0]
last := foundtag{tagid: -1}
+ if tilelib.skipOOO {
+ keep := longestIncreasingSubsequence(len(found), func(i int) int { return int(found[i].tagid) })
+ for i, x := range keep {
+ found[i] = found[x]
+ }
+ skipped = len(found) - len(keep)
+ found = found[:len(keep)]
+ }
for i, f := range found {
log.Tracef("%s %s found[%d] == %#v", filelabel, job.label, i, f)
- if tilelib.skipOOO {
- if f.tagid < last.tagid+1 {
- log.Debugf("%s %s skipped out-of-order tag %d (found at %d) because it appears after tag %d (found at %d)", filelabel, job.label, f.tagid, f.pos, last.tagid, last.pos)
- continue
- }
- if f.tagid > last.tagid+1 && // accepting this tag would mean skipping some tags
- i+1 < len(found) && // there is a "next" found tag after this one
- found[i+1].tagid > last.tagid && // next found tag is usable (we haven't already passed it in accepted sequence)
- found[i+1].tagid <= f.tagid { // next found tag is expected before this one (so we can't use both)
- log.Debugf("%s %s skipped out-of-order tag %d (found at %d) because it appears between tag %d (found at %d) and %d (found at %d)", filelabel, job.label, f.tagid, f.pos, last.tagid, last.pos, found[i+1].tagid, found[i+1].pos)
- continue
- }
- }
if last.taglen > 0 {
path = append(path, tilelib.getRef(last.tagid, job.fasta[last.pos:f.pos+f.taglen]))
}
pathcopy := make([]tileLibRef, len(path))
copy(pathcopy, path)
ret[job.label] = pathcopy
- log.Debugf("%s %s tiled with path len %d", filelabel, job.label, len(path))
+ log.Debugf("%s %s tiled with path len %d, skipped %d", filelabel, job.label, len(path), skipped)
totalPathLen += len(path)
}
- log.Printf("%s tiled with total path len %d in %d sequences (skipped %d sequences with '_' in name)", filelabel, totalPathLen, len(ret), skippedSequences)
+ log.Printf("%s tiled with total path len %d in %d sequences (skipped %d sequences with '_' in name, skipped %d out-of-order tags)", filelabel, totalPathLen, len(ret), skippedSequences, totalFoundTags-totalPathLen)
return ret, scanner.Err()
}