comp_seq_sim
- class comp_seq_sim(seq1=None, seq2=None, df_seq=None)[source]
Bases:
Compute pairwise similarity between two or more sequences ([pro], requires
aaanalysis[pro]).The sequence similarity score between two sequences is the alignment score expressed as a percentage of the length of the longest sequence (range
[0, 100]). The alignment score is obtained using theBio.Align.PairwiseAlignerfrom BioPython with default settings.Added in version 1.0.0.
- Parameters:
- Returns:
seq_sim (float) – Sequence similarity score as a percentage in
[0, 100], returned whenseq1andseq2are provided (pairwise comparison of two strings).df_pw_sim (pd.DataFrame, shape (n_samples, n_samples)) – Pairwise similarity matrix with
entryvalues as both index and columns, returned whendf_seqis provided.
See also
Bio.Align.PairwiseAlignerfor details on the similarity computation.
Warning
This function requires biopython, which is automatically installed via pip install aaanalysis[pro].
Examples
You can compute the pairwise sequence similarity between two sequences using the features
comput_seq_sim()function:import aaanalysis as aa aa.options["verbose"] = False seq1 = "GTGGHWWW" seq2 = "GTGGHFALSE" # Compute similarity between two sequences seq_sim = aa.comp_seq_sim(seq1=seq1, seq2=seq2) print(seq_sim)
30.0To compute the similarity between all pairs of sequences from a DataFrame, you can use the
df_seqparameter:import pandas as pd # Pairwise similarity across all sequences in a df_seq (needs 'entry' + 'sequence' columns) df_seq = pd.DataFrame({ "entry": ["P1", "P2", "P3"], "sequence": ["GTGGHWWW", "GTGGHFALSE", "GTGGHWWA"], }) df_pw_sim = aa.comp_seq_sim(df_seq=df_seq) aa.display_df(df=df_pw_sim, show_shape=True)
DataFrame shape: (3, 3)
P1 P2 P3 P1 100.000000 30.000000 87.500000 P2 30.000000 100.000000 30.000000 P3 87.500000 30.000000 100.000000