Skip to content

Commit

Permalink
[extract] Fix crashes when link size exceeds MaxLinkDist
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed Nov 15, 2018
1 parent a301323 commit bf822fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions base.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ var Backend = logging.NewLogBackend(os.Stderr, "", 0)
// BackendFormatter contains the fancy debug formatter
var BackendFormatter = logging.NewBackendFormatter(Backend, format)

// ErrorAbort logs an error message and then exit with retcode of 1
func ErrorAbort(err error) {
if err != nil {
log.Errorf("%s", err)
os.Exit(1)
}
}

// RemoveExt returns the substring minus the extension
func RemoveExt(filename string) string {
return strings.TrimSuffix(filename, path.Ext(filename))
Expand Down
3 changes: 2 additions & 1 deletion extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ func (r *Extracter) makeModel(outfile string) {

// writeRE write a RE file and report statistics
func writeRE(outfile string, contigs []*ContigInfo) {
f, _ := os.Create(outfile)
f, err := os.Create(outfile)
ErrorAbort(err)
w := bufio.NewWriter(f)
defer f.Close()
totalCounts := 0
Expand Down
5 changes: 4 additions & 1 deletion model.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,15 @@ func (r *LinkDensityModel) countBinDensities(contigs []*ContigInfo) {
// Find the length of assayable intra-contig sequence in each bin
intraContigLinkRange := math.Log2(float64(maxLinkDist) / float64(MinLinkDist))
nIntraContigBins := int(math.Ceil(intraContigLinkRange * 16))
if nIntraContigBins > len(r.nLinks) {
nIntraContigBins = len(r.nLinks)
}

// Step 3: loop through all links and tabulate the counts
for _, contig := range contigs {
for _, link := range contig.links {
bin := r.linkBin(link)
if bin == -1 {
if bin == -1 || bin >= len(r.nLinks) {
continue
}
r.nLinks[bin]++
Expand Down

0 comments on commit bf822fb

Please sign in to comment.