guohanghui commited on
Commit
07f16a9
·
verified ·
1 Parent(s): e70d1f5

Update SPM/mcp_output/mcp_plugin/mcp_service.py

Browse files
SPM/mcp_output/mcp_plugin/mcp_service.py CHANGED
@@ -37,13 +37,32 @@ def sequence_pattern_matching(input_sequence: str, target_sequence: str) -> dict
37
 
38
  # Call the real volumeScoring function
39
  result_data = volumeScoring(query_seq_volume, uniprot_info, target_sequence)
40
-
41
  # Extract results
42
- best_score = result_data[1] # score
43
- best_position = result_data[2] # position (0-indexed)
44
-
45
- # Get the matched region
46
  query_len = len(input_sequence)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  matched_region = target_sequence[best_position:best_position + query_len]
48
 
49
  # Create comprehensive result
@@ -96,12 +115,31 @@ def spm_database_search(query_sequence: str, database_sequences: list) -> dict:
96
 
97
  # Use the real volumeScoring function
98
  result_data = volumeScoring(query_seq_volume, name, sequence)
99
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  results.append({
101
  'name': result_data[0],
102
- 'score': float(result_data[1]),
103
- 'position': int(result_data[2]),
104
- 'matched_region': sequence[result_data[2]:result_data[2] + len(query_sequence)],
105
  'sequence_length': len(sequence)
106
  })
107
 
 
37
 
38
  # Call the real volumeScoring function
39
  result_data = volumeScoring(query_seq_volume, uniprot_info, target_sequence)
40
+
41
  # Extract results
42
+ best_score = float(result_data[1]) # score
43
+ best_position = int(result_data[2]) # position (0-indexed)
44
+
45
+ # Fallback: if score is the sentinel 9999 or indices invalid, do local sliding-window
46
  query_len = len(input_sequence)
47
+ need_fallback = (
48
+ best_score == 9999.0 or
49
+ best_position < 0 or
50
+ best_position + query_len > len(target_sequence)
51
+ )
52
+ if need_fallback:
53
+ db_seq_volume = np.array([volume[i] for i in target_sequence])
54
+ max_start = len(db_seq_volume) - query_len
55
+ if max_start < 0:
56
+ return {"success": False, "result": None, "error": "Query sequence longer than target sequence"}
57
+ best_score = float("inf")
58
+ best_position = 0
59
+ for i in range(max_start + 1):
60
+ s = float(np.sum(np.abs(db_seq_volume[i:i + query_len] - query_seq_volume)))
61
+ if s < best_score:
62
+ best_score = s
63
+ best_position = i
64
+
65
+ # Get the matched region
66
  matched_region = target_sequence[best_position:best_position + query_len]
67
 
68
  # Create comprehensive result
 
115
 
116
  # Use the real volumeScoring function
117
  result_data = volumeScoring(query_seq_volume, name, sequence)
118
+
119
+ score = float(result_data[1])
120
+ pos = int(result_data[2])
121
+
122
+ # Fallback: handle sentinel 9999 or invalid indices
123
+ qlen = len(query_sequence)
124
+ if score == 9999.0 or pos < 0 or pos + qlen > len(sequence):
125
+ db_seq_volume = np.array([volume[i] for i in sequence])
126
+ max_start = len(db_seq_volume) - qlen
127
+ if max_start >= 0:
128
+ best_s = float("inf")
129
+ best_i = 0
130
+ for i in range(max_start + 1):
131
+ s = float(np.sum(np.abs(db_seq_volume[i:i + qlen] - query_seq_volume)))
132
+ if s < best_s:
133
+ best_s = s
134
+ best_i = i
135
+ score = best_s
136
+ pos = best_i
137
+
138
  results.append({
139
  'name': result_data[0],
140
+ 'score': float(score),
141
+ 'position': int(pos),
142
+ 'matched_region': sequence[pos:pos + len(query_sequence)],
143
  'sequence_length': len(sequence)
144
  })
145