Skip to content
This repository has been archived by the owner on Mar 21, 2020. It is now read-only.

Commit

Permalink
Break off common file and fasta operations
Browse files Browse the repository at this point in the history
  • Loading branch information
bebarino committed May 18, 2009
1 parent b7785aa commit 7b590cc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
19 changes: 19 additions & 0 deletions common.py
@@ -0,0 +1,19 @@
from optparse import OptionParser, OptionValueError

def parse_seq(f):
"""Parse a FASTA sequence from the file 'f', returning its full string"""
if not f.readline().startswith(">"):
raise Exception("Not a FASTA sequence")
lines = []
for line in f:
if line.startswith(">"):
break
lines += [line.strip()]
return ''.join(lines)

def parser_open_file(option, opt_str, value, parser, mode):
try:
f = open(value, mode)
except IOError, e:
raise OptionValueError(str(e))
setattr(parser.values, option.dest, f)
21 changes: 2 additions & 19 deletions readGen.py
Expand Up @@ -2,7 +2,8 @@

import random
import sys
from optparse import OptionParser, OptionValueError
from optparse import OptionParser
from common import *

def gen_reads(seq, l, coverage=1):
num_reads = int((len(seq)/l) * coverage)
Expand All @@ -21,24 +22,6 @@ def write_reads(rs, f):
f.write('\t'.join(str(x) for x in read))
f.write('\n')

def parse_seq(f):
"""Parse a FASTA sequence from the file 'f', returning its full string"""
if not f.readline().startswith(">"):
raise Exception("Not a FASTA sequence")
lines = []
for line in f:
if line.startswith(">"):
break
lines += [line.strip()]
return ''.join(lines)

def parser_open_file(option, opt_str, value, parser, mode):
try:
f = open(value, mode)
except IOError, e:
raise OptionValueError(str(e))
setattr(parser.values, option.dest, f)

if __name__ == "__main__":
parser = OptionParser(usage="%prog length [options]")

Expand Down

0 comments on commit 7b590cc

Please sign in to comment.