Python代写:CS177-Python-Programming-Lab-Prep7

继续代写Python基础练习题,练习Python的基础使用方法,属于比较基础的Python作业。
Python

Lab Prep 7

Due Date:

This assignment is due Week 1 1 (Oct 27 th - Nov 1 st) by 11:59 pm on the night before your lab.

This assignment requires you to write a program utilizing functions that read data from two separate large text files manipulate it, create a List of Lists , then display a report and create a new file named analysis.txt containing number of occurrences. Lab Prep 7 does not use the Graphics library.

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 (ChainLeft.txt) and right half (ChainRight.txt). 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: cG, mG, tG, sG, cV, mV, tV or sV.

A partial sample of a chain: ( Example: not from the actual data )
ChainLeft.txt file: tsscmcsts
ChainRight.txt file: VGVVGGVVG

DNA sequence after completing a left/right pairing :
tV, sG, sV, cV, mG, cG, sV, tV, sG

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 , print an output report and create an output file named
    analysis.txt containing the results of your analysis

TO DO #1: Setup the labprep7.py program

  • Define a header with comments including your name, the program’s name and a description of the program’s function
  • Define a main() function
  • In the main() function, display a message describing the purpose of the program

TO DO #2: The match() function

The match() function accepts two filenames as arguments and return a List of combined protein pairs
in the DNA chain.

  • Define a function named match() that accepts two (2) String arguments
  • Display the status message: ‘Reading and Processing Protein Pairs…’
  • Open and read the contents of the two files specified by the String arguments
  • Combine the matching values into a List of protein pairs
    NOTE : The List of combined protein pairs will have 1 million entries similar to:
    ['mG', 'mV', 'cV', 'cG', 'tV', 'mG', 'cV', 'mG',...]
    
  • Close the two files
  • Return the List of combined protein pairs

TO DO #3: The occur() function

The occur() function accepts one List as an argument and creates a new List containing the number of
occurrences of each pair combination from the List argument

  • Define a function named occur() that accepts one argument, the protein pair List
  • Display the status message: ‘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.
    NOTE : The List will have 8 entries where pair is the 2 - character protein pair and #occurs is
    number of times that pair occurs
    [ [ pair , # occurs ], [ pair , # occurs ], … [ pair , # occurs ] ]
  • Return the List of occurrences

TO DO #4: Modify the main() function

To finish the program you need to add the commands to process the data files and create the output file.

  • Modify main() to prompt the user for the two (2) file names containing the genetic data
  • Call the match() function providing the two filenames as arguments - don’t forget to assign the
    List returned by match() to a variable
  • Call the occur() function providing the List of protein pairs as an argument – don’t forget to assign the List returned by occur() to a variable
  • Display the values in the List returned by occur() matching the following format:
  • Display the message: ‘Creating the Output File: analysis.txt’
  • The analysis.txt file should include same text as the report: ‘Alien Protein Analysis’
  • Close the analysis.txt file
  • Display the message: ‘Processing Complete.’

Submit your completed labprep7.py program

Your Python program should be saved to a file named labprep7.py

  • Attach your labprep7.py file to the Lap Prep 7 assignment by 11:59 pm on the due date.
  • Click the blue “SUBMIT” button to complete the assignment

Lab Prep 7 Grading Rubric Points

1
2
3
4
5
6
7
8
9
10
TODO #1: Program has proper header including name/description and is named labprep7.py 1
TODO #1: main() function defined, greeting message & user prompted for files 2
TODO #2: match() function defined, opens and reads data files specified by 2 arguments 2
TODO #2: match() function combines matching value pairs into List correctly, returns List 2
TODO # 3 : occur() function defined, accepts protein pair List as argument 1
TODO #2: occur() function creates List of Lists containing the # of each pair occurrences 2
TODO #4: main()modified to call match(), occur() and display status messages 2
TODO #4: main()displays report and text file based on List returned by occur() as specified 2
Style / Format: Program is formatted well and easy to understand 1
Total Points 15
1
Figure 1 : This is an example report – your results will be different