Skip to content

Commit

Permalink
[allhic] Simplify data structures in clm
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed Jan 5, 2018
1 parent 498e830 commit 7787bfb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
33 changes: 11 additions & 22 deletions allhic/clm.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ type CLMFile struct {
Clmfile string
Idsfile string
Tigs []Tig
tigToIdx map[string]int // From name of the tig to the idx of the Tigs array
contacts []Contact // Array of contacts
orientations map[Pair]OrientedContact // (tigA, tigB) => strandedness x nlinks
orientedContacts map[OrientedPair]GArray // (tigA, tigB) => golden array i.e. exponential histogram
tigToIdx map[string]int // From name of the tig to the idx of the Tigs array
contacts map[Pair]Contact // (tigA, tigB) => {strandedness, nlinks, meanDist}
orientedContacts map[OrientedPair]GArray // (tigA, tigB, oriA, oriB) => golden array i.e. exponential histogram
}

// Pair contains two contigs in contact
Expand All @@ -55,14 +54,6 @@ type OrientedPair struct {

// Contact stores how many links between two contigs
type Contact struct {
a string
b string
nlinks int
dists []int
}

// OrientedContact stores only one configuration per pair of tigs
type OrientedContact struct {
strandedness int
nlinks int
meanDist int
Expand All @@ -89,7 +80,7 @@ func InitCLMFile(Clmfile string) *CLMFile {
p.Clmfile = Clmfile
p.Idsfile = RemoveExt(Clmfile) + ".ids"
p.tigToIdx = make(map[string]int)
p.orientations = make(map[Pair]OrientedContact)
p.contacts = make(map[Pair]Contact)
p.orientedContacts = make(map[OrientedPair]GArray)

p.ParseIds()
Expand Down Expand Up @@ -158,22 +149,20 @@ func (r *CLMFile) ParseClm() {
}

// Store all these info in contacts
contact := Contact{at, bt, nlinks, dists}
gdists := GoldenArray(dists)
meanDist := HmeanInt(dists, GRLB, GRUB)
strandedness := 1
if ao != bo {
strandedness = -1
}
r.contacts = append(r.contacts, contact)
pair := Pair{at, bt}
oc := OrientedContact{strandedness, nlinks, meanDist}
if p, ok := r.orientations[pair]; ok {
c := Contact{strandedness, nlinks, meanDist}
if p, ok := r.contacts[pair]; ok {
if p.meanDist > meanDist {
r.orientations[pair] = oc
r.contacts[pair] = c
}
} else {
r.orientations[pair] = oc
r.contacts[pair] = c
}
r.orientedContacts[OrientedPair{at, bt, ao, bo}] = gdists
r.orientedContacts[OrientedPair{bt, at, rr(bo), rr(ao)}] = gdists
Expand Down Expand Up @@ -223,12 +212,12 @@ func (r *CLMFile) M() [][]int {
P[i] = make([]int, N)
}

for _, contact := range r.contacts {
ai, aok := r.tigToIdx[contact.a]
for pair, contact := range r.contacts {
ai, aok := r.tigToIdx[pair.a]
if !aok {
continue
}
bi, bok := r.tigToIdx[contact.b]
bi, bok := r.tigToIdx[pair.b]
if !bok {
continue
}
Expand Down
6 changes: 3 additions & 3 deletions allhic/optimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Optimizer struct {
// Run kicks off the Optimizer
func (r *Optimizer) Run() {
clm := InitCLMFile(r.Clmfile)
clm.Activate()
// tour := clm.Activate()
// GARun(tour, 100, 2000, .2)
// clm.Activate()
tour := clm.Activate()
GARun(tour, 100, 2000, .2)
}

0 comments on commit 7787bfb

Please sign in to comment.