Skip to content

Instantly share code, notes, and snippets.

@telatin
Last active September 30, 2020 14:19
Show Gist options
  • Save telatin/ee3f112c284057566df04a477d2a8075 to your computer and use it in GitHub Desktop.
Save telatin/ee3f112c284057566df04a477d2a8075 to your computer and use it in GitHub Desktop.
import heapqueue
type
coverage = ref object
forward: int
reverse: int
# Class that stores info about the end position of alignments, used in the alignment queue
type
covEnd = ref object
stop: int
reverse: bool
proc newCov(f = 0, r = 0): coverage =
coverage(forward: f, reverse: r)
proc inc(c: coverage, reverse=false) =
if reverse == false:
c.forward += 1
else:
c.reverse += 1
proc dec(c: coverage, reverse=false) =
if reverse == false:
c.forward -= 1
else:
c.reverse -= 1
proc tot(c: coverage): int =
c.forward + c.reverse
proc `<`(a, b: covEnd): bool = a.stop < b.stop
proc `>`(a, b: covEnd): bool = a.stop > b.stop
var
chromosomes = newSeq[string]()
covQueue = initHeapQueue[covEnd]()
cov = newCov()
next_change : int
cov.inc(reverse=true)
cov.inc(reverse=true)
cov.inc(reverse=true)
cov.inc()
cov.inc()
echo "Total=",cov.tot()
echo "Rev =",cov.reverse
next_change = 1000
covQueue.push( covEnd(stop: next_change) )
covQueue.push( covEnd(stop: 20) )
covQueue.push( covEnd(stop: 1211) )
# this is a "Minimum heap" by default!
echo covQueue.pop().stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment