Skip to content

Commit

Permalink
fix bugs while processing genomic locations
Browse files Browse the repository at this point in the history
  • Loading branch information
ygidtu committed Jul 20, 2020
1 parent efefc75 commit 85153e0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
7 changes: 4 additions & 3 deletions const.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"fmt"
"regexp"
"strconv"
Expand All @@ -20,7 +21,7 @@ var conf config
var region *Region

const (
VERSION = "0.0.4-beta"
VERSION = "0.0.5-beta"
DefaultBaseQuality = 30
)

Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
15 changes: 3 additions & 12 deletions fast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions slow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 85153e0

Please sign in to comment.