Text: IN PYTHON!!!
3. Plot a BAR CHART capturing the frequency of occurrences for each MOTIF pattern given. Need to put a meaningful caption for the plot and identify each motif on x-axis and label the y-axis clearly.
Results are generated by <your first name> (<your matric number>)
import re
motifs = ['AA', 'GA', 'CG', 'TT', 'GT', 'TAC', 'GGA', 'CTG', 'CATG', 'TAGT', 'TGATC', 'TTAAC', 'GATACG', 'TTGCGC', 'AGGCCGAC']
Sequence: AGTGGCCATACAGGTCGATTAAGGCCA
Length of sequence = 27
Motif 0: AA: 1
Motif 1: GA: 1
Motif 2: CG: 1
Motif 3: TT: 1
Motif 4: GT: 2
Motif 5: TAC: 1
Motif 6: GGA: 0
Motif 7: CTG: 0
Motif 8: CATG: 0
Motif 9: TAGT: 0
Motif 10: TGATC: 0
Motif 11: TTAAC: 0
Motif 12: GATACG: 0
Motif 13: TTGCGC: 0
Motif 14: AGGCCGAC: 0
Sequence 1: TCTCCGACGAAGACGGTGCTTGTGGTGGACTTTCCGTACA
Length of sequence = 40
Motif 0: AA: 1
Motif 1: GA: 4
Motif 2: CG: 4
Motif 3: TT: 2
Motif 4: GT: 4
Motif 5: TAC: 1
Motif 6: GGA: 1
Motif 7: CTG: 0
Motif 8: CATG: 0
Motif 9: TAGT: 0
Motif 10: TGATC: 0
Motif 11: TTAAC: 0
Motif 12: GATACG: 0
Motif 13: TTGCGC: 0
with open('DNA_seqs.txt', 'r') as file:
index = 0
for sequence in file.readlines():
if sequence[-1] == '\n':
sequence = sequence[0:-1]
print(f"Sequence {index}: {sequence}")
print(f'Length of sequence = {len(sequence)}')
for i in range(len(motifs)):
print(f"Motif {i}: {motifs[i]}: {len(re.findall(motifs[i], sequence))}")
index += 1
Ln: 21 Col: 0
Maximum frequency of 398 for the motif(s) TAC CG
(d) Report the total number of sequences in the file and measure the running time starting from the start of part (a) to the end of part (c).
Print the results to your text file DNA_Seq_Analysis_results.txt at the end, after the maximum and minimum frequency.