Skip to content

protein_blast() ​

Find the best hit of each gene in the query cluster's proteins.

Every protein is aligned globally with every protein of the query cluster (Needleman-Wunsch, as R's protein_blast() with pwalign::pairwiseAlignment(); see aligner for the scores). A gene keeps the query protein with the highest identity as its hit, when the identity is at least identity; equal best hits give a row each. The clusters are then ordered by a synteny score, the query first.

Needs Biopython: pip install "geneviewer-py[align]".

Usage ​

python
from geneviewer import protein_blast

protein_blast(
    data,
    query,
    id='protein_id',
    start='start',
    end='end',
    cluster='cluster',
    genes=None,
    identity=30,
)

Arguments ​

ArgumentTypeDescription
datapandas.DataFrame or pathGenes with their protein sequence (column translation or sequence), or a GenBank file or folder of them (one cluster per file).
querystrThe query cluster.
idstrColumn of unique protein ids.
start, endstrColumns of the start and end positions.
clusterstrColumn of cluster names.
geneslist of str, optionalOnly these genes of the query cluster (by id). Default: all.
identityfloatThe lowest identity (percent) of a hit. Default 30.

Value ​

pandas.DataFrame: data (rows without an id, sequence or cluster left out) with rowID, start, end, and identity, similarity, BlastP (the id of the hit, "No Hit" without one; a hit only one gene has is "No Hit" too) and score (the cluster's synteny score). Ordered by cluster, the query first, then by score.

Errors ​

ErrorWhen
ImportErrorWithout Biopython.
ValueErrorWhen a column or the query is not in the data.

Examples ​

python
>>> genes = pd.DataFrame({
...     "protein_id": ["A1", "A2", "B1", "B2"],
...     "cluster": ["A", "A", "B", "B"],
...     "start": [1, 200, 1, 200], "end": [150, 350, 150, 350],
...     "translation": ["MKTAYIAKQRQISFVKSHFSRQ", "MSDNELLKRLGEAVLAHPTTG",
...                     "MKTAYIAKQRQISFVKSHFSRQ", "MLPGGRTSWVQEHCDKAYNIF"]})
>>> protein_blast(genes, query="A")[["protein_id", "identity", "BlastP"]]
  protein_id  identity  BlastP
0         A1     100.0      A1
1         A2     100.0  No Hit
2         B1     100.0      A1
3         B2       NaN  No Hit