Member-only story
Key Points
- Python basics
- Demonstration of converting previous assignments from C to Python
- Files
- Features that C does not have
Assignment: DNA
I broke down this programme into a few small functions, dealing with the DNA database, the input DNA sequences, and the computation of DNA results respectively.
Main
At the beginning of this programme, it checks the number of command-line arguments first. If the user does not pass 3 arguments on the command line, this programme exits.
If 3 command-line arguments are passed, this programme reads the database by calling function read_db()
. The second command-line argument, supposed to be the file name of a database, is passed to this function. read_db()
reads the database and save all data to a global variable db_dict
.
Then, it gets a list of DNA result by calling function find_dna()
. The third command-line argument, supposed to be the file name of a DNA sequence, is passed to the function along with a list of STRs.
With the DNA result, it identifies if any value from DNA database matches the DNA result.