Skip to content

Commit

Permalink
[partition] Update matrix entries in contact matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed Nov 26, 2017
1 parent 0c9cbea commit de6fe8a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
1 change: 0 additions & 1 deletion allhic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ proc optimize_main() =

proc partition_main() =
var c = initPartitioner("tests/prunning.sub.bam")
echo c.bamfile
c.count_links()


Expand Down
8 changes: 8 additions & 0 deletions hic/base.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import future
import logging
import strutils
import "matrix"


var logger = newConsoleLogger()
logger.addHandler()
9 changes: 2 additions & 7 deletions hic/clm.nim
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import future
import math
import os
import parseutils
import sets
import strutils
import tables
import logging
import "matrix"

var logger = newConsoleLogger()
logger.addHandler()
include "base"


##
Expand Down Expand Up @@ -104,7 +99,7 @@ proc M*(this: CLMFile): Matrix[int] =
N = this.N
tig_to_idx = this.tig_to_idx

result = newMatrix[int](N, N)
result = zeros[int](N, N)
for abt, links in this.contacts.pairs():
let (at, bt) = abt
if at notin tig_to_idx:
Expand Down
26 changes: 14 additions & 12 deletions hic/partition.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@

import algorithm
import hts
import logging
import strutils
import tables
import "matrix"
include "base"


var logger = newConsoleLogger()
logger.addHandler()

type
Partitioner* = ref object
bamfile*: string
Expand All @@ -41,16 +36,23 @@ proc count_links*(this: Partitioner) =
for t in b.hdr.targets:
targets[t.name] = t

let N = targets.len
var M = newMatrix[int](N, N)
let N = max(lc[ x.tid | (x <- b.hdr.targets), int]) + 1
var M = zeros[int](N, N)
debug("Initiating matrix of size $# x $#".format(N, N))

for record in b:
let qi = targets[record.chrom].tid
let mi = targets[record.mate_chrom].tid
echo qi, " & ", mi
var
qi = targets[record.chrom].tid
mi = targets[record.mate_chrom].tid

if qi > mi:
swap(qi, mi)

M[qi, mi] = M[qi, mi] + 1
mappings.add((record.qname, record.chrom))

mappings.sort do (x, y: ReadMapping) -> int:
result = cmp(x.name, y.name)

for mapping in mappings[0..<100]:
echo mapping
echo mapping
5 changes: 3 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

echo $(pwd)

sudo apt-get -qy install bwa make build-essential cmake libncurses-dev ncurses-dev libbz2-dev lzma-dev liblzma-dev \
curl libssl-dev libtool autoconf automake libcurl4-openssl-dev
#sudo apt-get -qy install bwa make build-essential cmake libncurses-dev ncurses-dev libbz2-dev lzma-dev liblzma-dev \
# curl libssl-dev libtool autoconf automake libcurl4-openssl-dev

BRANCH=latest
export base=$(pwd)
if [ ! -x nim-$BRANCH/bin/nim ]; then
git clone -b $BRANCH --depth 1 git://github.com/nim-lang/nim nim-$BRANCH/
Expand Down

0 comments on commit de6fe8a

Please sign in to comment.