# Python Ch3
###### tags: `python2021`
* 繳交格式:
* 以學號命名的zip (.7z or .rar)壓縮檔

* 程式作業 (1~4) 取名為:學號_ex3-1.py,不符合者視為缺交。
---
# Question 1 : Splitting genomic DNA
Look in the file on e3 called genomic_dna.txt – it contains the same piece of genomic DNA that we were using in the final exercise from chapter 2. Write a program that will split the genomic DNA into coding and non-coding parts, and **write coding sequence to "coding.txt", non-coding sequence to "non-coding.txt"**.
:::info
*Hint:*
Coding parts: dna[:63] & dna[90:]
:::
---
# Question 2 : Appending File
You know everytime you use:
```python
my_file_w=open("file_1","w");
my_file_w.write("something to write");
my_file_w.close()
```
You will overwrite everything in file_1, even the file that has already contained something.
So, use :
```python
my_file_a=open("file_1","a")
```
to keep writing.
Therefore, what you need to do is copy the code that you can not modify.
```python
file_1_header = "ABC123"
file_2_header = "DEF456"
file_3_header = "HIJ789"
# set the values of all the sequence variables
file_1_seq = "ATCGTACGATCGATCGATCGCTAGACGTATCG"
file_2_seq = "actgatcgacgatcgatcgatcacgact"
file_3_seq = "ACTGAC-ACTGT-ACTGTA----CATGTG"
file_1_w=open("ex3-2.fa","w")
file_1_w.write(">"+file_1_header+"\n"+file_1_seq+"\n");
file_1_w.close();
#you can not modify this code
#just copy and keep writing your own code
```
Then, output the file like the following picture


---
# Question 3 : Reading File
Just read the files that you created for last homework, and print them to the window.
(Read files "ex2-1.fa", "ex2-2.fa", "ex2-3.fa", and print them.)
:::warning
*warning:*
Of course, you must use function read like :
```python
my_file_a=open("file_1","r")
```
Other method like just :
```python
print (">"+file_1_header+"\n"+file_1_seq+"\n")
print (">"+file_2_header+"\n"+file_2_seq+"\n")
print (">"+file_3_header+"\n"+file_3_seq+"\n")
```
will be considered as a wrong answer.
:::
# Question 4: Merging File
This question is interesting.
In the last chapter, you wrote some easy python programs to handle string.
Now you should merge the homeworks which include hw1-1 to hw1-4 into the file which is called "hw1_code_merge.py".
Then try to run "hw1_code_merge.py", the output will be like the following picture:

:::info
*Hint:*
```python
#you can use complex file path to open your old code
file_1_r=open(r"..\0657226_hw1\0657226_hw1-1.py","r")
```
:::
:::warning
*warning:*
Of course, you must use function read and write function to complete this question.
:::