0% found this document useful (0 votes)
5 views3 pages

Python

The document contains a Python script that processes biological sequences and performs various analyses, including reading sequence files, calculating docking scores, and identifying mutations. It also includes functionality for finding motifs in DNA sequences and counting k-mers. The script demonstrates practical applications of Python in bioinformatics.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Python

The document contains a Python script that processes biological sequences and performs various analyses, including reading sequence files, calculating docking scores, and identifying mutations. It also includes functionality for finding motifs in DNA sequences and counting k-mers. The script demonstrates practical applications of Python in bioinformatics.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Code

1 print("Q1")
2 with open(r"C:\Users\rohit\Downloads\AL645882.2 Streptomyces [Link]", "r") a
s f:
3 header = ''
4 seq = ''
5 for line in f:
6 line = [Link]()
7 if [Link]('>'):
8 header = line
9 else:
10 seq += line
11
12 print(header)
13 print(seq)
14
15 print("Q2")
16
17 with open(r"C:\Users\rohit\Downloads\@SEQ_ID_1.txt", "r") as f:
18 while True:
19 header = [Link]().strip()
20 if not header:
21 break
22 seq = [Link]().strip()
23 plus = [Link]().strip()
24 qual = [Link]().strip()
25 print(header)
26 print(seq)
27 print(qual)
28
29 print("Q3")
30
31 import re
32 with open(r"C:\Users\rohit\Downloads\[Link]", "r") as f:
33 for line in f:
34 line = [Link]()
35 if 'DEFINITION' in line:
36 definition = line[12:].strip()
37 print('definition', definition)
38 if 'ORIGIN' in line:
39 print('sequence data:')
40 for seq_line in f:
41 if '//' in seq_line:
42 break
43 seq = [Link](r'[^a-zA-Z]', '', seq_line)
44 print(seq)
45
46 print("Q4")
47
48 import numpy as np
49
50 protein_atoms = [Link]([[0,0,0],[1,0,0],[0,1,0]])
51 ligand_atoms = [Link]([[2,2,2],[3,2,2]])
52 docking_score = 0
53
54 for i in range(len(protein_atoms)):
55 for j in range(len(ligand_atoms)):
56 distance = [Link](protein_atoms[i] - ligand_atoms[j])
57 docking_score += 1 / (distance + 0.1)
58
59 print("Docking Score:", docking_score)
60
61 print("Q5")
62
63 protein_atoms = [Link]([[0,0,0],[1,1,1]])
64 ligand_atoms = [Link]([[2,2,2],[3,3,3]])
65 docking_score = 0
66
67 for i in range(len(protein_atoms)):
68 for j in range(len(ligand_atoms)):
69 distance = [Link](protein_atoms[i] - ligand_atoms[j])
70 docking_score += 1 / (distance + 0.1)
71
72 print("Docking Score:", docking_score)
73
74 print("Q6")
75
76 protein_sequence = 'AC'
77 amino_acid_mass = {'A': 71.03711, 'C': 103.00919}
78 total_mass = sum(amino_acid_mass[aa] for aa in protein_sequence)
79
80 print("TOTAL MASS:", total_mass)
81
82 print("Q7")
83
84 sequence1 = 'AGCTCTAG'
85 sequence2 = 'AGTTATCT'
86
87 if len(sequence1) != len(sequence2):
88 raise ValueError("Sequences must be of equal length")
89
90 mutation_count = 0
91 for i in range(len(sequence1)):
92 if sequence1[i] != sequence2[i]:
93 mutation_count += 1
94 print("position of mutation", i + 1)
95
96 print("Mutation Count:", mutation_count)
97 mutation_frequency = (mutation_count / len(sequence1)) * 100
98 print(mutation_count)
99 print(mutation_frequency)
100
101 print("Q8")
102
103 dna_sequence = 'GATATATGCATATACTT'
104 motif = 'ATAT'
105 positions = []
106 start = 0
107
108 while True:
109 idx = dna_sequence.find(motif, start)
110 if idx != -1:
111 [Link](idx)
112 start = idx + 1
113 else:
114 break
115
116 print(positions)
117
118 print("Q9")
119
120 dna_sequence = 'ACGTTGCATGTCGCATGATGCATGAGAGCTAT'
121 k = 4
122 from collections import defaultdict
123
124 kmer_counts = defaultdict(int)
125
126 for i in range(len(dna_sequence) - k + 1):
127 kmer = dna_sequence[i:i+k]
128 kmer_counts[kmer] += 1
129
130 max_count = max(kmer_counts.values())
131 most_frequent_kmers = [kmer for kmer, count in kmer_counts.items() if count == max_c
ount]
132
133 print(f"Most frequent {k}: {', '.join(most_frequent_kmers)} with count {max_count}")

You might also like