Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,27 +46,36 @@ selected_features = [
|
|
| 46 |
|
| 47 |
|
| 48 |
def extract_features(sequence):
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
all_features = list(all_features.values())
|
| 60 |
-
normalized_features = scaler.transform(all_features.T)
|
| 61 |
-
normalized_features = normalized_features.flatten()
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
return selected_feature_array
|
| 70 |
|
| 71 |
|
| 72 |
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
def extract_features(sequence):
|
| 49 |
+
try:
|
| 50 |
+
comp_features = AAComposition.CalculateAAComposition(sequence)
|
| 51 |
+
auto_features = Autocorrelation.CalculateAutoTotal(sequence)
|
| 52 |
+
ctd_features = CTD.CalculateCTD(sequence)
|
| 53 |
+
pseudo_features = PseudoAAC.GetAPseudoAAC(sequence)
|
| 54 |
+
|
| 55 |
+
# Combine all features into a dictionary
|
| 56 |
+
all_features = {**comp_features, **auto_features, **ctd_features, **pseudo_features}
|
| 57 |
+
|
| 58 |
+
# Convert to DataFrame
|
| 59 |
+
all_features_df = pd.DataFrame([all_features])
|
| 60 |
+
|
| 61 |
+
# Select only required features
|
| 62 |
+
all_features_df = all_features_df[selected_features]
|
| 63 |
+
|
| 64 |
+
# Ensure correct shape
|
| 65 |
+
if all_features_df.shape[0] == 0:
|
| 66 |
+
raise ValueError("No features extracted. Check the input sequence.")
|
| 67 |
|
| 68 |
+
# Normalize the features
|
| 69 |
+
normalized_features = scaler.transform(all_features_df)
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
+
return normalized_features
|
| 72 |
+
except ZeroDivisionError:
|
| 73 |
+
print("Error: Division by zero encountered in Moran autocorrelation calculation.")
|
| 74 |
+
return None
|
| 75 |
+
except Exception as e:
|
| 76 |
+
print(f"Feature extraction error: {e}")
|
| 77 |
+
return None
|
| 78 |
|
|
|
|
| 79 |
|
| 80 |
|
| 81 |
|