Here is the code:
def readFasta(filename): """ Reads a sequence in Fasta format """ fp = open(filename, 'rb') header = "" seq = "" while True: line = fp.readline() if (line == ""): break if (line.startswith('>')): header = line[1:].strip() else: seq = fp.read().replace('\n','') seq = seq.replace('\r','') # for windows break fp.close() return (header, seq) FASTAsequence = readFasta("MusChr01.fa") The error I'm getting is:
TypeError: startswith first arg must be bytes or a tuple of bytes, not str But the first argument to startswith is supposed to be a string according to the docs... so what is going on?
I'm assuming I'm using at least Python 3 since I'm using the latest version of LiClipse.
The startswith() method returns True if the string starts with the specified value, otherwise False.
STARTSWITH is a string manipulation function that manipulates all string data types (BIT, BLOB, and CHARACTER), and returns a Boolean value to indicate whether one string begins with another.
The startsWith() method determines whether a string begins with the characters of a specified string, returning true or false as appropriate.
startsWith method is case sensitive.
It's because you're opening the file in bytes mode, and so you're calling bytes.startswith() and not str.startswith().
You need to do line.startswith(b'>'), which will make '>' a bytes literal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With