-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcs58FileUtil.py
78 lines (59 loc) · 1.84 KB
/
cs58FileUtil.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# s50FileUtil
#
# Jeff Parker Feb 2009
#
# File Handling utilities
# Other programs can use these utilities
import string
import sys
# Remove white space, change to upper case
def prepare(text):
text = string.replace(text, " ", "")
text = string.replace(text, "\n", "")
text = string.replace(text, "\t", "")
text = text.upper()
return text
def readFastaFile(fileName):
f = open(fileName, 'r')
# First line in Fasta format is header
line = f.readline()
# print "Saw", line
text = f.read()
f.close()
# Remove end of lines
text = prepare(text)
return text
def readMultiFastaFile(fileName):
#
# seqArray = ["GATTACA", "TAGACCA", "ATACA"]
seqArray = []
f = open(fileName, 'r')
currentString = ''
for line in f:
# if it's a new one, save the current value into array and start fresh
# check that currentSring has something to prevent saving an empty value in the first step
if ((line.find('Rosalind') > 0 ) & (currentString != '')):
#if (line.find('Rosalind') > 0 ) :
#print "this line is a new one"
seqArray.append(currentString)
currentString = ''
# otherwise (it's one in progress) save it into currentString unless it's that very first rosalind heading
else:
if (line.find('Rosalind') < 0 ):
currentString += line
#print "currentString is: ", currentString
# add the last value
seqArray.append(currentString)
#line = f.readline()
#while (line != '\n'):
#
# currentString += f.readline()
#print "currentString is: ", currentString
#
#line = f.readline()
#print "Saw", line
# text = f.read()
# f.close()
# Remove end of lines
#text = prepare(text)
return seqArray