-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotein-physicochemical-properties.py
More file actions
47 lines (38 loc) · 1.66 KB
/
Copy pathprotein-physicochemical-properties.py
File metadata and controls
47 lines (38 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from Bio import SeqIO
from Bio.SeqUtils.ProtParam import ProteinAnalysis
import csv
import sys
def compute_protein_properties(fasta_file, output_csv):
results = []
for record in SeqIO.parse(fasta_file, "fasta"):
sequence = str(record.seq)
analysis = ProteinAnalysis(sequence)
molecular_weight = analysis.molecular_weight()
theoretical_pI = analysis.isoelectric_point()
instability_index = analysis.instability_index()
gravy = analysis.gravy()
# Compute amino acid composition
aa_composition = analysis.count_amino_acids()
A = aa_composition.get('A', 0) # Alanine
V = aa_composition.get('V', 0) # Valine
I = aa_composition.get('I', 0) # Isoleucine
L = aa_composition.get('L', 0) # Leucine
total_residues = sum(aa_composition.values())
# Calculate aliphatic index
if total_residues > 0:
aliphatic_index = ((A + 2.9 * V + 3.9 * (I + L)) / total_residues) * 100
else:
aliphatic_index = 0
results.append([
record.id, molecular_weight, theoretical_pI,
instability_index, aliphatic_index, gravy
])
with open(output_csv, "w", newline="") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["Protein_ID", "Molecular_Weight", "Theoretical_pI", "Instability_Index", "Aliphatic_Index", "GRAVY"])
writer.writerows(results)
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python script.py input.fasta output.csv")
sys.exit(1)
compute_protein_properties(sys.argv[1], sys.argv[2])