Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with writing the code and calling other files into python. Loading a FASTA file: the loadSeq(fileName) function FASTA files are actually just

I need help with writing the code and calling other files into python.

Loading a FASTA file: the loadSeq(fileName) function

FASTA files are actually just text files, and we can use the above syntax to load them.

Begin a new homework file called load.py. We will now create a function called loadSeq(fileName) in this file. Note that load.py should not contain anything else besides this function (i.e. the practice stuff from the section above should not be included there.)

loadSeq will take one variable as input: a string with the name of the FASTA file that we'll be loading. This way we can use loadSeq to load any FASTA file we want, not just the one that we downloaded a moment ago. This function should return a single string (not a list!) which is all of the DNA in the lines of the input file.

Keep in mind that the input file is a FASTA format file. So, its first line contains information that is not part of the DNA. The subsequent lines are the actual DNA broken up over multiple lines. Your loadSeq function can start by using the same three lines below to read in the file and get the list of all of the lines in the file. Except, of course, now we're not necessarily reading goodStuff.txt, but rather the file whose name is specified in the string fileName.

f = open(fileName) # open the file linesList = f.readlines() # read in the file as a list of its lines f.close() # close the file 

But now what you want to return is a single string! So, you'll need a for loop and you'll need to slice. The idea is very similar to the for loop that we wrote above, but that one constructed a list and it included the first line. Now, we want to return a single string and we don't want the first line.

You can test your function on the following two FASTA files: test1.fa and test2.fa. (Remember, on a Mac, you should hold the "Control" button down when you click on these links so that you can easily save these to files. Remember to save them in the working folder for this problem!)

test1.fa looks like this:

> Test fasta file 1 AGGTCTGTCAACCGTTTCAGTACA ACCTAGCCTACCCTGCTAACTAGA 

Here's our loadSeq function at work:

>>> loadSeq("test1.fa") "AGGTCTGTCAACCGTTTCAGTACAACCTAGCCTACCCTGCTAACTAGA" >>> loadSeq("test2.fa") "CCGTCCATTCGACGGATA" 

You have now created a module, which other python programs can use. load.py contains just one function. When it is imported by another program using import load this function will be brought into that program's memory space. (A python module can contain more than one function, but in this case we have only the one.)

Because load.py will be used as a module, it is important not to have other extraneous things included in it (e.g. no lines loading goodStuff.txt etc.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle9i Database Administrator Implementation And Administration

Authors: Carol McCullough-Dieter

1st Edition

0619159006, 978-0619159009

More Books

Students also viewed these Databases questions