Skip to content

Commit

Permalink
[hic] Read tig sizes into a table
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed Nov 7, 2017
1 parent a078abc commit 4317cf8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
24 changes: 14 additions & 10 deletions hic/clm.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from parseutils import parseInt
from strutils import rsplit, split
import parseutils
import strutils
import tables


#[
Expand All @@ -19,14 +20,15 @@ type
name*: string
clmfile*: string
idsfile*: string
Tig* = tuple[tig: string, size: int]
tig_to_size*: OrderedTable[string, int]


proc newCLMFile*(name: string, clmfile: string): CLMFile =
proc initCLMFile*(name: string, clmfile: string): CLMFile =
new result
result.name = name
result.clmfile = clmfile
result.idsfile = clmfile.rsplit('.', maxsplit=1)[0] & ".ids"
result.tig_to_size = initOrderedTable[string, int]()


#[
Expand All @@ -36,15 +38,17 @@ keyword, if available in the third column, is less confident.
tig00035238 46779 recover
tig00030900 119291
#]#
proc parse_ids*(this: CLMFile, skiprecover: bool): seq[Tig] =
result = @[]
proc parse_ids*(this: CLMFile, skiprecover: bool) =
var
tig: string
size: int

for line in lines this.idsfile:
let atoms = line.split()
let tig = atoms[0]
var size = 0
tig = atoms[0]
size = 0
discard parseInt(atoms[1], size)
result.add((tig: tig, size: size))
return result
this.tig_to_size[tig] = size


proc parse*(this: CLMFile) =
Expand Down
17 changes: 13 additions & 4 deletions hic_opt.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
from hic/clm import newCLMFile, parse, parse_ids
import hic/clm
import strutils
import tables

var c = newCLMFile("test", "tests/test.clm")
echo c.parse_ids(true)
#c.parse()
proc main() {.discardable.} =
var c = initCLMFile("test", "tests/test.clm")
c.parse_ids(true)
for key, val in c.tig_to_size.pairs():
echo("$# $#".format(key, val))
#c.parse()


when isMainModule:
main()

0 comments on commit 4317cf8

Please sign in to comment.