In python,write a program with giving: 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 13:50:23 浏览: 50
Sure, here's a Python program to fulfill your requirements:
```python
# Open the DNA.txt file and read the DNA sequences
with open('DNA.txt', 'r') as file:
dna_sequences = file.readlines()
# Define a function to get the complementary sequence
def get_complementary_sequence(sequence):
complement = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}
complementary_sequence = ''.join([complement[base] for base in sequence])
return complementary_sequence
# Define a function to calculate the GC content
def get_gc_content(sequence):
gc_count = sequence.count('G') + sequence.count('C')
gc_content = (gc_count / len(sequence)) * 100
return gc_content
# Open the DNA.txt file in append mode to store the output
with open('DNA.txt', 'a') as file:
file.write('\nComplementary Strand and GC Content:\n')
for i, sequence in enumerate(dna_sequences):
sequence = sequence.strip()
complementary_sequence = get_complementary_sequence(sequence)
gc_content = get_gc_content(sequence)
file.write(f'\nSequence {i+1}:\nComplementary Strand: {complementary_sequence}\nGC Content: {gc_content:.2f}%\n')
```
This program reads the DNA sequences from the 'DNA.txt' file, calculates the complementary strand and GC content for each sequence, and writes the output to the same file using append mode. Hope this helps!
阅读全文