Question
I'm trying to create a Python program. These are the specifications: The final output should look similar to this: My code so far is pasted
I'm trying to create a Python program. These are the specifications:
The final output should look similar to this:
My code so far is pasted below. Note that I have to keep all three functions: match, occur, and main
I commented what should happen in each line
# Define a match() function that accepts two filenames as arguments # and returns a list of combined protein pairs in the DNA chain def match(RightChainfile,LeftChainfile):
# Display the status message: 'Reading and Processing Protein Pairs...' print("Reading and Processing Protein Pairs...") # Open and read the contents of the two files f1=open(RightChainfile,"r") f2=open(LeftChainfile,"r") # Combine the matching values into a list of protein pairs pair=[] for line_right, line_left in zip(f1,f2): # removing whitespaces if present in line1 line1=line_right.strip()
# removing whitespaces if present in line2 line2=line_left.strip()
# concatenate line1 and line2 in mystr mystr=line1+line2
# appending the str to the list pair.append(mystr) # Close the two files f1.close() f2.close() # Return the list of combined protein pairs return pair
# Define an occur() function that accepts one List as an argument and # and creates a new List containing the number of occurrences of each # pair combination from the List argument #def occur(pair):
# Display the status message: 'Counting Occurrences...' #print("Counting Occurrences...") # Create a new List of Lists using the protein pair combinations and # the number of times each occurs in the protein pair List
# Return the List of occurences
# Define the main() function def main():
# Display a message describing the purpose of the program print("This program reads the contents of two files containing the left and right chains and creates a two-character pair combination") print("that is stored in a list. A List of Lists is created of each possible protein combination and the number of occurences is counted.") print("The values in the occurrences List are then displayed as a report and stored in in an output file named analysis.txt.") # Prompt the user for two filenames RightChainfile=input("Please enter the first file name: ") LeftChainfile=input("Please enter the second file name: ") # Call the match() function providing the two filenames as arguments pair=match(RightChainfile,LeftChainfile) # Assign the List returned by occur() to a variable
# Display the List returned by occur in a table format with two columns reading Pair and Occurences # and a title named Alien Protein Analysis count=0
# Iterating through each element in l1 # Printing each element with two spaces after the last character # Prints new line after count is greater than 9 # Count is reset to 0 and loops for element in pair: print(element, end=" ") count=count+1 if count>9: print() count=0 # Display the message: 'Creating the Output File: analysis.txt' # This file should include the same text as 'Alien Protein Analysis' print("Creating the Output File: analysis.txt") # Close the analysis.txt file #analysis.close() # Display the message: 'Processing Complete.' print("Processing Complete.") # Call the main() function main()
Any help appreciated! This is using python 3 and higher
Problem Description: You are investigating an alien life form found frozen in the ice of Antarctica. A genetic sample has been isolated and the data from this sample is stored in two (2) files. The structure is very different from the types of life found on earth. Chemical analysis has determined that each compound chain is 1 million DNA "pairs" long. You have two files containing 1 million characters representing the life form's genetic chain separated into the left half (Chain.Left) and right half (Chain.Right). The left half of the chain uses 4 different proteins (designated as c, m, t, or s) while the right half uses only 2 proteins (designated G or v). The compounds that make up each strand' or full chain of material are paired using one of 8 combinations: A partial sample of a chain: (Example: not from the actual data) Left file: Chain. Chain.Right file: VGVVGGVVG tsscmcsts DNA sequence after completing a left/right pairing: The Assignment Your assignment is to write a Python function that completes the following tasks: Read the contents of the two (2) files containing the left and right halves of the chain Pair the left/right protein values into a two-character pair combination, storing them in a List Create a new List of Lists containing each of the possible protein combinations and the count of the number of occurrences each value Using the values in the occurrences List, display a report and create an output file named analysis.txt containing the results of your analysisStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started