File size: 1,268 Bytes
14f4c95
942bf87
51a3749
 
 
 
 
 
 
 
 
942bf87
51a3749
 
 
942bf87
51a3749
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14f4c95
51a3749
 
 
 
 
 
 
 
942bf87
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
import gradio as gr
import joblib
from fastapi import FastAPI
import joblib
import numpy as np
from pydantic import BaseModel
import propy
from sklearn.preprocessing import MinMaxScaler

# Load trained SVM model
model = joblib.load("SVM.joblib")

# Define request model
class SequenceInput(BaseModel):
    sequence: str

def extract_features(sequence):
    """Calculate AAC, Dipeptide Composition and normalize features."""
    # Calculate Amino Acid Composition (AAC)
    aac = propy.AAComposition.CalculateAAC(sequence)
    
    # Calculate Dipeptide Composition
    dipeptide_comp = propy.AAComposition.CalculateAADipeptideComposition(sequence)
    
    # Combine both features (AAC and Dipeptide Composition)
    features = np.concatenate((aac, dipeptide_comp))
    
    # Min-Max Normalization
    scaler = MinMaxScaler()
    normalized_features = scaler.fit_transform(features.reshape(-1, 1)).flatten()
    
    return normalized_features

@app.post("/predict/")
def predict(sequence_input: SequenceInput):
    """Predict AMP vs Non-AMP"""
    sequence = sequence_input.sequence
    features = extract_features(sequence)
    prediction = model.predict([features])[0]
    
    return {"sequence": sequence, "prediction": "AMP" if prediction == 1 else "Non-AMP"}