I have an assignment where I have to write a python class to represent and manipulate biological sequences. I have almost finished the class, however I need to import sequences from FASTA files input the class, so that it can run them. In order to run the class in the command line, I was required to create a run_me.py file, which when executed in the command line, should ask for the FASTA file and then run the class.
This is the class constructor:
class Bioseq:
"""Biological sequence class"""
def __init__(self, seq):
self.seq = seq
And this is how far I've gotten with the run_me.py file:
def read_fasta():
with open(file_name, "r") as fh:
line = fh.readline()
header = ""
seq = ""
while line:
line = line.rstrip('\n')
if ">" in line:
header = line
else:
seq = seq + line
line = fh.readline()
return seq
print(seq)
from TPC2_MR2 import Bioseq
file_name = input("Please enter sequence file name:")
Bioseq = Bioseq(read_fasta())
Bioseq.main()
TPC2_MR2
is the name of the class module. Now the problem is that when I execute the run_me.py
file, I am asked to provide the name of the FASTA file but after that, the sequence is not imported into the class. What should I do?
Please note that I cannot use external Pyhton modules, such as Biopython.
I think there are a few issues, but the most glaring ones are that when you call
Bioseq(read_fasta())
, you arent providing an argument toread_fasta()
so there’s no data being input. Similarly, yourBioseq
contains no method calledmain()
, so your last line would throw an error. Also, it’s unwise to call the variable the same thing as the class, as you’re polluting the namespace. Since you’ve importedBioseq
, that name is taken.Do you want the class to do the parsing of the file, or do you want to parse the file separately and just pass the class the relevant parts? Are your input files multifastas?
Thank you for replying!
Actually, I had added the main() function to Bioseq, I just didn't include it in the question (my bad). Here it is:
The seq_type and the call_methods are two functions within the class that I wish to run.
Regarding the read_fasta(), I want to put the output from the read_fasta function into the class (later refered to as seq), and there is only one sequence in each fasta file