From 85153e038a64156f2c123ab689231367a75661e6 Mon Sep 17 00:00:00 2001 From: ygidtu Date: Sat, 18 Jul 2020 11:03:00 +0800 Subject: [PATCH] fix bugs while processing genomic locations --- const.go | 7 ++++--- fast.go | 15 +++------------ slow.go | 4 +--- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/const.go b/const.go index d9c9961..ff1a523 100644 --- a/const.go +++ b/const.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "fmt" "regexp" "strconv" @@ -20,7 +21,7 @@ var conf config var region *Region const ( - VERSION = "0.0.4-beta" + VERSION = "0.0.5-beta" DefaultBaseQuality = 30 ) @@ -298,7 +299,7 @@ type EditsInfo struct { func NewEditsInfo(lastChr string, ref byte, pos int) *EditsInfo { return &EditsInfo{ - LastChr: lastChr, Ref: ref, Edits: []byte{}, Pos: pos, + LastChr: lastChr, Ref: bytes.ToUpper([]byte{ref})[0], Edits: []byte{}, Pos: pos, Counter: map[byte]int{'A': 0, 'T': 0, 'C': 0, 'G': 0}, Variants: map[byte]int{'A': 0, 'T': 0, 'C': 0, 'G': 0}, Strand: "", Qualities: []byte{}, Total: 0, @@ -311,7 +312,7 @@ func (e *EditsInfo) AddReads(record *Record, at int) { if seq != 'N' { e.Counter[e.Ref]++ e.Qualities = append(e.Qualities, record.QualityAt(at)) // - e.Edits = append(e.Edits, seq) + e.Edits = append(e.Edits, bytes.ToUpper([]byte{seq})[0]) e.Strand += record.Strand() if e.Ref != seq { diff --git a/fast.go b/fast.go index b660c98..c72881b 100644 --- a/fast.go +++ b/fast.go @@ -19,15 +19,6 @@ func workerFast( break } - //chrRef, err := fetchFasta(ref.ToRegion()) - //if err != nil { - // sugar.Warnf("try to modify %s", ref) - // chrRef, err = fetchFasta(ref.SwitchRegion()) - //} - //if err != nil { - // sugar.Fatal(err) - //} - chrRef, ok := chrRefs[ref.Ref] if !ok { sugar.Errorf("failed to get %s from reference", ref.Ref) @@ -72,11 +63,11 @@ func workerFast( if _, ok := edits[genomic]; !ok { // GL000220.1 - if genomic - 1 >= len(chrRef) { + if genomic >= len(chrRef) { sugar.Error(record.Record) - sugar.Fatalf("%s: genomic - 1[%d] >= len(chrRef)[%d]", ref.Ref, genomic - 1, len(chrRef)) + sugar.Fatalf("%s: genomic - 1[%d] >= len(chrRef)[%d]", ref.Ref, genomic, len(chrRef)) } - edits[genomic] = NewEditsInfo(ref.Ref, chrRef[genomic-1], genomic) + edits[genomic] = NewEditsInfo(ref.Ref, chrRef[genomic], genomic + 1) } edits[genomic].AddReads(record, at) diff --git a/slow.go b/slow.go index b247b64..2172df8 100644 --- a/slow.go +++ b/slow.go @@ -61,12 +61,10 @@ func worker(wg *sync.WaitGroup, refs chan *Region, w chan string, omopolymericPo sugar.Fatal(record.SeqString()) } - // record.QueryPosition = append(record.QueryPosition, at) - genomic := start + record.Start if _, ok := edits[genomic]; !ok { - edits[genomic] = NewEditsInfo(ref.Chrom, chrRef[genomic-1], genomic) + edits[genomic] = NewEditsInfo(ref.Chrom, chrRef[genomic], genomic + 1) } edits[genomic].AddReads(record, at)