Spaces:
Sleeping
Sleeping
Update prediction.py
Browse files- prediction.py +18 -13
prediction.py
CHANGED
|
@@ -11,34 +11,35 @@ def predict_sequence_label(sequence):
|
|
| 11 |
Returns:
|
| 12 |
int: The predicted label (0 or 1).
|
| 13 |
"""
|
|
|
|
| 14 |
def compute_aac_features(sequence):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
amino_acids = 'ACDEFGHIKLMNPQRSTVWY'
|
| 26 |
|
| 27 |
-
|
| 28 |
aac_counts = {f"AAC_{aa}": 0 for aa in amino_acids}
|
| 29 |
|
| 30 |
-
|
| 31 |
seq_length = len(sequence)
|
| 32 |
|
| 33 |
-
|
| 34 |
for aa in sequence:
|
| 35 |
if f"AAC_{aa}" in aac_counts:
|
| 36 |
aac_counts[f"AAC_{aa}"] += 1
|
| 37 |
|
| 38 |
-
|
| 39 |
aac_features = {aa: count / seq_length for aa, count in aac_counts.items()}
|
| 40 |
|
| 41 |
-
|
| 42 |
aac_features_df = pd.DataFrame([aac_features])
|
| 43 |
|
| 44 |
return aac_features_df
|
|
@@ -53,3 +54,7 @@ def predict_sequence_label(sequence):
|
|
| 53 |
prediction = saved_model.predict(aac_features_df)
|
| 54 |
|
| 55 |
return prediction[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
Returns:
|
| 12 |
int: The predicted label (0 or 1).
|
| 13 |
"""
|
| 14 |
+
|
| 15 |
def compute_aac_features(sequence):
|
| 16 |
+
"""
|
| 17 |
+
Compute the Amino Acid Composition (AAC) features for a given sequence.
|
| 18 |
|
| 19 |
+
Parameters:
|
| 20 |
+
sequence (str): A string representing the amino acid sequence.
|
| 21 |
|
| 22 |
+
Returns:
|
| 23 |
+
pd.DataFrame: DataFrame containing the AAC features for the sequence.
|
| 24 |
+
"""
|
| 25 |
+
# Define the 20 standard amino acids
|
| 26 |
amino_acids = 'ACDEFGHIKLMNPQRSTVWY'
|
| 27 |
|
| 28 |
+
# Initialize a dictionary to hold the counts of each amino acid
|
| 29 |
aac_counts = {f"AAC_{aa}": 0 for aa in amino_acids}
|
| 30 |
|
| 31 |
+
# Calculate the length of the sequence
|
| 32 |
seq_length = len(sequence)
|
| 33 |
|
| 34 |
+
# Count the occurrences of each amino acid in the sequence
|
| 35 |
for aa in sequence:
|
| 36 |
if f"AAC_{aa}" in aac_counts:
|
| 37 |
aac_counts[f"AAC_{aa}"] += 1
|
| 38 |
|
| 39 |
+
# Convert counts to frequencies
|
| 40 |
aac_features = {aa: count / seq_length for aa, count in aac_counts.items()}
|
| 41 |
|
| 42 |
+
# Convert the AAC features to a DataFrame
|
| 43 |
aac_features_df = pd.DataFrame([aac_features])
|
| 44 |
|
| 45 |
return aac_features_df
|
|
|
|
| 54 |
prediction = saved_model.predict(aac_features_df)
|
| 55 |
|
| 56 |
return prediction[0]
|
| 57 |
+
|
| 58 |
+
# Example usage:
|
| 59 |
+
# sequence = "YOUR_AMINO_ACID_SEQUENCE_HERE"
|
| 60 |
+
# print(predict_sequence_label(sequence))
|