Last active
August 29, 2015 14:17
-
-
Save Aszarsha/32c68e654d384e363c59 to your computer and use it in GitHub Desktop.
Extract peptide counts from count matrix in new fasta files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Add those lines to lib/system.nim: | |
iterator pairs*[T](it: iterator(): T {.inline.}): tuple[key: int, val: T] {.inline.} = | |
## iterates over each item of it. Yields ``(index, item)`` pairs. | |
var i = 0 | |
for v in it: | |
yield (i, v) | |
inc(i) | |
iterator mpairs*[T](it: iterator(): T {.inline.}): tuple[key: int, val: var T] {.inline.} = | |
## iterates over each item of it. Yields ``(index, item)`` pairs. | |
## ``item`` can be modified. | |
var i = 0 | |
for v in it: | |
yield (i, v) | |
inc(i) | |
# $nim-vm rebuild repo | |
# CC: docutils_rstgen | |
# Error: execution of an external program failed; rerun with --parallelBuild:1 to see the error message | |
# FAILURE | |
# -- Ho well, lets try: | |
# $~/Nim/koch boot --parallelBuild:1 | |
# ... | |
# SUCCESS | |
# $~/Nim/bin/nim c extractFasta.nim | |
# extractLists.nim(14, 32) Error: undeclared identifier: 'lines' | |
#extractFasta.nim: | |
import os | |
import strutils | |
var files: seq[File] = @[] | |
let file = if paramCount() > 0: open( paramStr( 1 ) ) | |
else: stdin | |
for lineNum, line in pairs( file.lines() ): | |
var peptideName: string | |
let inTokens = split( line, '\t' ) | |
for tokenNum, token in inTokens: | |
if lineNum == 0: | |
if tokenNum > 0: | |
files.add( open( token&".fasta", FileMode.fmWrite ) ) | |
else: | |
if tokenNum == 1: | |
peptideName = token | |
elif tokenNum > 1 and parseInt( token ) > 0: | |
files[tokenNum-2].write( ">" & peptideName & "|" & token & "\n" ) | |
files[tokenNum-2].write( peptideName & "\n" ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import strutils | |
iterator pairs*[T](it: iterator(): T {.inline.}): tuple[key: int, val: T] {.inline.} = | |
## iterates over each item of it. Yields ``(index, item)`` pairs. | |
var i = 0 | |
for v in it: | |
yield (i, v) | |
inc(i) | |
iterator mpairs*[T](it: iterator(): T {.inline.}): tuple[key: int, val: var T] {.inline.} = | |
## iterates over each item of it. Yields ``(index, item)`` pairs. | |
## ``item`` can be modified. | |
var i = 0 | |
for v in it: | |
yield (i, v) | |
inc(i) | |
var files: seq[File] = @[] | |
let file = if paramCount() > 0: open( paramStr( 1 ) ) | |
else: stdin | |
for lineNum, line in pairs( file.lines() ): | |
var peptideName: string | |
for tokenNum, token in pairs( split( line, '\t' ) ): | |
if lineNum == 0: | |
if tokenNum > 0: | |
files.add( open( token & ".fasta", FileMode.fmWrite ) ) | |
else: | |
if tokenNum == 1: | |
peptideName = token | |
elif tokenNum > 1 and parseInt( token ) > 0: | |
files[tokenNum-2].write( ">" & peptideName & "|" & token & "\n" ) | |
files[tokenNum-2].write( peptideName & "\n" ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment