In Pycharm,write a program withgiving: Three DNA strings in DNA.txt fileReturn: for each sequence1) the complementary strand .2) GC content.And store the output in the same file using attach model.
时间: 2024-03-09 17:50:12 浏览: 78
Sure! Here's the Python program for your requirement:
```python
# Open DNA.txt file
with open('DNA.txt', 'r') as file:
dna_strings = file.readlines()
# Function to get complementary strand of DNA sequence
def get_complementary_strand(dna_seq):
complement_dict = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}
complement = ''.join([complement_dict[base] for base in dna_seq])
return complement
# Function to calculate GC content of DNA sequence
def get_gc_content(dna_seq):
gc_count = dna_seq.count('G') + dna_seq.count('C')
gc_content = gc_count / len(dna_seq) * 100
return gc_content
# Open DNA.txt file in append mode to write outputs
with open('DNA.txt', 'a') as file:
file.write('\nComplementary Strand and GC Content:\n')
for i in range(3):
dna_seq = dna_strings[i].strip()
complement = get_complementary_strand(dna_seq)
gc_content = get_gc_content(dna_seq)
file.write(f'\nSequence {i+1}:\nComplementary Strand: {complement}\nGC Content: {gc_content:.2f}%\n')
```
This program reads three DNA sequences from the 'DNA.txt' file, calculates their complementary strands and GC contents, and writes the output to the same file using append mode. Hope this helps!
阅读全文