Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This assignment is due by 11: 59 pm on Monday, July 17^th. This assignment requi

ID: 3858056 • Letter: T

Question

This assignment is due by 11: 59 pm on Monday, July 17^th. This assignment requires you to write a function that utilizes the file input/output functionality of Python to read some data from two large text files, manipulate it and write the results to a new file named "sequence.txt". You are investigating a new life form found frozen in the ice of Antarctica. A genetic sample has been isolated and the data from this sample is stored in text files. The structure is similar to the DNA found in earth-based life forms, but there are some significant differences. Chemical analysis has determined that each compound chain is 1 million "pairs" long. You have two files containing the life form's data from the left ("ChainA-Left.txt") and right ("ChainA-Right.txt") halves of the genetic chain. Each file is 1 million characters long. The left half of the chain uses 8 different proteins (designated as 'c, 'm', 't', 's', 'C', 'M', 'T', and 'S') while the right half uses only 4 proteins (designated 'g', 'v', 'G' and 'V'). The compounds that make up each 'strand' (or full chain) of material are paired using one of 32 combinations. It is important to note that the upper-case and lower-case letters refer to the orientation of the protein on the strand and are significant, so it is critical that you maintain this formatting. A partial sample of a chain: (Example: from actual data) ChainA-Left file: tSSCmCstsSMM ChainA-Right file: vvVvvGvVVggG Output file after completing a left/right pairing: tv, Sv, sv, Cv, mv, CG, sv, tv, sV, Sg, Mg, MG Your assignment is to write a Python function that combines the two files containing the left and right halves of the chain. The resulting two-character protein combinations should be stored as elements in a List. Finally, your function should create a new output file (named "sequence.txt") containing the combined sequence values from your List. While the primary output of your function should be the new data file, it should also display status messages as it completes each step of the process. Your completed Python program should be named "labprep7.py" and should be submitted using the Lab Prep 7 assignment on Blackboard.

Explanation / Answer

def readFromFiles():
with open('Chain-Left.txt', 'r') as myfile:
leftData=myfile.read()# read chain-left file here
with open('Chain-Right.txt', 'r') as myfile:
rightData=myfile.read()# read chain-right file here
i = 0
outList = []
while i < len(leftData):
  
if leftData[i] != " ":
outList.append(leftData[i]+rightData[i])# add pair to list
print ("Adding pair to list: ", leftData[i]+rightData[i])
i += 1
f = open('sequence.txt', 'w')# create new output file here
i=0
for pair in outList:# iterate list
if i != 0:
f.write(", ") # format comma space
print("Writing pair: ", pair, " to out file")
f.write (pair)# write pair to file
readFromFiles() # call function from here