This repository has been archived by the owner on Mar 21, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Break off common file and fasta operations
- Loading branch information
Showing
2 changed files
with
21 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains 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