Question

In python Attached is a file called sequences.txt, it contains 3 sequences (one sequence per line)....

In python

Attached is a file called sequences.txt, it contains 3 sequences (one sequence per line). Also attached is a file called AccessionNumbers.txt. Write a program that reads in those files and produces 3 separate FATSA files. Each accession number in the AccessionNumbers.txt file corresponds to a sequence in the sequences.txt file. Remember a FASTA formatted sequence looks like this:

>ABCD1234

ATGCTTTACGTCTACTGTCGTATGCTTTACGTCTACTGACTGTCGTATGCTTACGTCTACTGTCG

The file name should match the accession numbers, so for 1st one it should be called ABCD1234.txt.

Note: Print out the sequences in upper case AND remove any special characters in the sequence!

sequences.txt contains the following sequence:

ATGCTTTACGTCTACTGTCGTATGCTTTACGTCTACTGACTGTCGTATGCTTACGTCTACTGTCG
atgctttacgtctactgtcgtatgctttacgtctactgactgtcgtatgcttacgtctactgtcg
atgctttacgt-tcgtatgctttacgtc---tatgcttacgt--cttacgt-----ctactgtcg

AccessionNumbers.txt contains the following:

ABCD1234
GFRT7890
HJIS5630

the output should produce 3 separate text files named "ABCD1234.txt" "GFRT7890.txt" and "HJIS5630.txt"

each text file output should look like this:

>ABCD1234

ATGCTTTACGTCTACTGTCGTATGCTTTACGTCTACTGACTGTCGTATGCTTACGTCTACTGTCG

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#function that takes sequence
#and returns the valid sequence in upper case.
def formatSeq(seq):
   #resultant seq
   res = ""
   #for each char in seq
   for i in seq:
       #if i_th char is one of the ATCG, then add it.
       if( i.upper() in "ATCG"):
           res += i.upper()
   #return the result
   return res

#open sequences.txt and AccessionNumbers.txt
seq = open("sequences.txt")
acNum = open("AccessionNumbers.txt")

#read one line from sequence and accession txt files
sequence = seq.readline()
accession = acNum.readline()
#till the end of the files
while(sequence and accession):
   #format the sequence by calling function
   sequence = formatSeq(sequence.strip())
   accession = accession.strip()
   #create file with accession number as txt file
   out = open(accession+".txt","w")
   #write accession number
   out.write(">"+accession+"\n")
   #and sequence
   out.write(sequence)
   out.close()
   #read next sequence and accession number.
   sequence = seq.readline()
   accession = acNum.readline()

seq.close()
acNum.close()

#sequence.txt

ATGCTTTACGTCTACTGTCGTATGCTTTACGTCTACTGACTGTCGTATGCTTACGTCTACTGTCG
atgctttacgtctactgtcgtatgctttacgtctactgactgtcgtatgcttacgtctactgtcg
atgctttacgt-tcgtatgctttacgtc---tatgcttacgt--cttacgt-----ctactgtcg
#accessionnumbers.txt

ABCD1234
GFRT7890
HJIS5630

ABCD1234.txt

>ABCD1234
ATGCTTTACGTCTACTGTCGTATGCTTTACGTCTACTGACTGTCGTATGCTTACGTCTACTGTCG

GFRT7890.txt

>GFRT7890
ATGCTTTACGTCTACTGTCGTATGCTTTACGTCTACTGACTGTCGTATGCTTACGTCTACTGTCG

HJIS5630.txt

>HJIS5630
ATGCTTTACGTTCGTATGCTTTACGTCTATGCTTACGTCTTACGTCTACTGTCG

fasta.py sequences.bxtAccessionNumbers.brtABCD1234.tt | GFRT7890.brt HUIS5630.bt #function that takes sequence #and returns tAccession Numbers.bxt xABCD1234.bt xGFRT7890.txt x HJIS5630.txt fasta.py sequences.brt rea- in sea or 1 in sea: #1r 1 th cha

Add a comment
Know the answer?
Add Answer to:
In python Attached is a file called sequences.txt, it contains 3 sequences (one sequence per line)....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python/idle 1. Write a program that counts the number of A’s in a DNA sequence. The...

    python/idle 1. Write a program that counts the number of A’s in a DNA sequence. The input is one sequence in FASTA format in a file called ‘dna.txt’. For example, if the file contains: >human ACCGT then the output of the program should be 1. Your program should work for any sequence and not just the one in the example.

  • In Python, do a basic encryption of a text file in the following manner. The program...

    In Python, do a basic encryption of a text file in the following manner. The program encrypt.py will read in the following text file and rearrange the lines in the file randomly and save the rearranged lines of txt to another file called encrypted.txt. It will also save another file called key.txt that will contain the index of the lines that were rearranged in the encrypted file, so for example if the 4th line from the original file is now...

  • There is a file lets call it the.faa. It contains all of the polypeptide coding sequences...

    There is a file lets call it the.faa. It contains all of the polypeptide coding sequences in the E. coli K12 genome in FASTA format. Your task for this exercise is to generate an amino acid usage report with counts only, and in no particular order. Your output should look like this: T: 69645 G: 95475 V: 91683 Y: 36836 H: 29255

  • Python Assignment Tasks 1. Place the two provided plaintext files (file_1.txt, file_2.txt) on your desktop. 2....

    Python Assignment Tasks 1. Place the two provided plaintext files (file_1.txt, file_2.txt) on your desktop. 2. Write a Python program named fun_with_files.py. Save this file to your desktop as well. 3. Have your program write the Current Working Directory to the screen.   4. Have your program open file_1.txt and file_2.txt, read their contents and write their contents into a third file that you will name final.txt . Note: Ponder the open‐read/write‐close file operation sequence carefully. 5. Ensure your final.txt contains...

  • Create a class called DuplicateRemover. Create an instance method called remove that takes a single parameter...

    Create a class called DuplicateRemover. Create an instance method called remove that takes a single parameter called dataFile (representing the path to a text file) and uses a Set of Strings to eliminate duplicate words from dataFile. The unique words should be stored in an instance variable called uniqueWords. Create an instance method called write that takes a single parameter called outputFile (representing the path to a text file) and writes the words contained in uniqueWords to the file pointed...

  • Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( );...

    Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( ); // constructor ~Salesperson( ); // destructor Salesperson(double q1, double q2, double q3, double q4); // constructor void getsales( ); // Function to get 4 sales figures from user void setsales( int quarter, double sales); // Function to set 1 of 4 quarterly sales // figure. This function will be called // from function getsales ( ) every time a // user enters a sales...

  • Using C# or Python, write a code that reads a Microsoft Excel CSV file named "LabAssignment"...

    Using C# or Python, write a code that reads a Microsoft Excel CSV file named "LabAssignment" then outputs all the collected and formated data as another Microsoft Excel CSV file named "labOutput" The CSV file contains 25 colums as well close to 200 rows of data. Write a code in C# or Python so that: It removes all unwanted columns along with its data...the columns that should be kept have the following header: "User" "Location" "Feature" "HoursUsed" Remove all files...

  • Create a python code named LetterCount with a text file named words.txt that contains at least...

    Create a python code named LetterCount with a text file named words.txt that contains at least 100 words in any format - some words on the same line, some alone (this program involves no writing so you should not be erasing this file). Then create a program in the main.py that prompts the user for a file name then iterates through all the letters in words.txt, counting the frequency of each letter, and then printing those numbers at the end...

  • python

    pythonComplete the below function that takes the name of two files, inFilename andoutFilename as arguments and reads the text from the inFilename. In this fileeach line contains the Turkish Republic Identity Number (TCNO), name, surnameand telephone number of a person. Your function should sort all personsaccording to their TCNO, write the sorted data into outFilename. If the fileinFilename does not exist, then the function must create an empty file namedoutFilename.For example, if the function is called such asreadText("in.txt", "out.txt")and in.txt...

  • C++ please Write a program that reads the following sentences from a file: I am Sam...

    C++ please Write a program that reads the following sentences from a file: I am Sam Sam I am That Sam I am That Sam I am I do not like that Sam I am Do you like green eggs and ham I do not like them But I do like spam! You will first have to create the text file containing the input, separate from your program. Your program should produce two output files: (i) (ii) one with the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT