Question

Write a Python program that converts an input file in FASTA format, called "fasta.txt", to an...

Write a Python program that converts an input file in FASTA format, called "fasta.txt", to an output file in PHYLIP format called "phylip.txt". For example, if the input file contains: >human ACCGTTATAC CGATCTCGCA >chimp ACGGTTATAC CGTACGATCG >monkey ACCTCTATAC CGATCGATCC >gorilla ATCTATATAC CGATCGATCG Then the output file should be human ACCGTTATACCGATCTCGCA chimp ACGGTTATACCGTACGATCG monkey ACCTCTATACCGATCGATCC gorilla ATCTATATACCGATCGATCG

FASTA format has a description (indicated with a '>') followed by 1 or more lines of a DNA sequence. PHYLIP format has a description followed by a single line of a DNA sequence and each sequence is the same length. For this homework, the input file will have an arbitrary number of sequences of arbitrary, but identical, length.

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

def Manage(str):

ls=list(str)

ls.remove('>')

position=0

for i in range(0,len(ls)):

if ls[i]==' ':

position=i

break

newlist=[]

for i in range(position,len(ls)):

if ls[i]!=' ':

newlist.append(ls[i])

str=""

for i in range(0,position):

str=str+ls[i]

str=str+" "

for i in newlist:

str=str+i

file = open('phylip.txt','a')

file.write(str)

file.close()




file=open("fasta.txt",'r')

for each in file:

Manage(each)# reading each line from file

file.close()


# we created simple list to remove space

# iterate to remove all spaces

#conver list into string

Add a comment
Know the answer?
Add Answer to:
Write a Python program that converts an input file in FASTA format, called "fasta.txt", to an...
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.

  • Write a Python function makeDict() that takes a filename as a parameter. The file contains DNA...

    Write a Python function makeDict() that takes a filename as a parameter. The file contains DNA sequences in Fasta format, for example: >human ATACA >mouse AAAAAACT The function returns a dictionary of key:value pairs, where the key is the taxon name and the valus is the total number of 'A' and 'T' occurrences. For example, for if the file contains the data from the example above the function should return: {'human':4,'mouse':7}

  • 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:...

  • 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:...

  • in Python Objective: Practice Displaying Output with print Function, Comments, Variable, Reading Input from the Keyboard,...

    in Python Objective: Practice Displaying Output with print Function, Comments, Variable, Reading Input from the Keyboard, format output, if statement, if-else statement, loop structure. import, functions, file handling. and string methods. Lab Description: You are given a file containing protein sequences with the task of finding motifs. Motifs are certain patterns of amino acids that appear many times in protein sequences that act as indictors or markers for special regions, genes, mutations, etc. An example of what this file will...

  • Write a Python program that reads from user the input file called data.txt that consists of...

    Write a Python program that reads from user the input file called data.txt that consists of a  keyword followed by a sequence of numbers separated by commas. If the keyword is UP, the  numbers are sorted in increasing order, if the key word is DOWN, the numbers are sorted in  decreasing order. The sorted sequence of numbers are saved in sorted.txt

  • Use PYTHON Write a program that will take an input file called input.txt which will contain a Jav...

    use PYTHON Write a program that will take an input file called input.txt which will contain a Java program and parse it and output an annotated version. Your program will track the nesting depth of the braces of the input file and will output an annotated version of the file. Your final program will 1. List the nesting depth of curly braces 2. Ignore braces inside quotes or comments Use Python Assume that all quoted strings begin and end on...

  • Python 3.6 Question 12 (20 points) Write a function named wordLengths. The function wordLengths takes two...

    Python 3.6 Question 12 (20 points) Write a function named wordLengths. The function wordLengths takes two parameters: 1. inFile, a string that is the name of an input file 2. outFile, a string that is the name of an output file The input file exists when wordLengths is called; wordLengths must create the file outFile. The input file contains only letters and white space For each line of the input file, wordLengths should identify the length of the longest word...

  • Write a PYTHON program that asks the user for the name of the file. The program...

    Write a PYTHON program that asks the user for the name of the file. The program should write the contents of this input file to an output file. In the output file, each line should be preceded with a line number followed by a colon. The output file will have the same name as the input filename, preceded by “ln” (for linenumbers). Be sure to use Try/except to catch all exceptions. For example, when prompted, if the user specifies “sampleprogram.py”...

  • Please develop a Java program to read in a piece of DNA sequence from a FASTA format sequence fil...

    Please develop a Java program to read in a piece of DNA sequence from a FASTA format sequence file (alternatively you can use the getRandomSeq(long) method of the RandomSeq class to generate a piece of DNA sequence), and then print out all the codons in three forward reading frames. Design a method called codon() that can be used to find all the codons from three reading frames. The method will take in an argument, the reading frame (1, 2, or...

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