similarity_service
Similarity analysis service that orchestrates the similarity workflow.
Module Contents
- exception similarity_service.SimilarityCacheOnlyMiss
A strict synchronous run could not use its preflight snapshot.
- similarity_service.analyze_sequence_similarity(csv_file, session_id: str = 'default') Dict[str, Any]
Analyze sequence similarity against target databases.
- Parameters:
csv_file – Uploaded CSV file containing protein sequences
session_id – Session ID for logging
- Returns:
Dictionary containing similarity analysis results
- Raises:
ValueError – If CSV is invalid or contains no sequences
Exception – If analysis fails
- similarity_service.analyze_similarity_for_method(query_db: str, target_db: str, query_file_path: str, method_name: str, original_sequences: List[str], seq_to_unique_id: Dict[str, str], session_id: str) Dict[str, Any]
Analyze similarity for a specific method/database.
- Parameters:
query_db – Path to query database
target_db – Path to target database
query_file_path – Path to original FASTA file
method_name – Name of the method
original_sequences – Original sequence list
seq_to_unique_id – Sequence to unique ID mapping
session_id – Session ID for logging
- Returns:
Dictionary containing method-specific results
- similarity_service.similarity_cache_label_for_method(method_key: str) str
Return the persistent-cache dataset label used by output enrichment.
- similarity_service.append_kcat_similarity_columns_to_output_csv(output_csv_path: str, kcat_method_key: str, recon_xkg: bool = False, cached_similarity_snapshot: dict[str, tuple[float | None, float | None]] | None = None, cache_only: bool = False, selected_sequences_by_row: list[str] | None = None) None
Best-effort enrichment for completed kcat jobs.
- Adds two per-row columns to output.csv:
mean similarity to {method} training data
max similarity to {method} training data
When
recon_xkgis set, per-sequence similarity is served from the persistent SimilarityStore and MMseqs2 runs only for sequences not yet cached. A cachedNULL/NULLpair is a negative cache hit and renders as blank cells, so repeated deterministic failures do not retry MMseqs2. On any error, both columns are still created with blank values.
- similarity_service.kcat_similarity_sequences_for_output_rows(df: pandas.DataFrame, selected_sequences_by_row: list[str] | None = None) list[str]
Return the unique sequence keys kcat output enrichment will require.