src/proteingnn/example/util.py
def visual_esm_corr(methods: Optional[Union[str, Tuple]] = None, rootdir: Optional[AnyPath] = None, pdb_name: str = '1gnx',
                    exp_data: Optional[Union[Dict, OrderedDict]] = None, esm_dir: Optional[AnyPath] = None,
                    **kwargs) -> Union[CorrType, Dict[str, CorrType]]:
    """(Legacy) plot esm to log2enrichment experiment data and evaluate correlations.

    Args:
        exp_data: Dictionary of mutant name and experiment data, i.e. {mut_name: y}
        pssm: Path to pssm file from psiblast.
        rootdir: Destination directory for exp-pssm.png.
        kwargs: Keyword arguments for seaborn.jointplot.
    """
    esm_dir = Path('data/embeddings/esm') if esm_dir is None else Path(esm_dir)
    if not esm_dir.exists():
        raise FileNotFoundError(f'{esm_dir} not found.')

    if methods is None:
        methods = ('ave', 'max', 'min')
    elif type(methods) == str:
        methods = [methods]
    else:
        methods = list(methods)

    if exp_data is None:
        exp_data = read_log2en(return_type='OrderedDict')
    esm_values = {method: OrderedDict() for method in methods}

    for mut_name, log2en_value in exp_data.items():
        pt = esm_dir / f'{pdb_name}_{mut_name}.pt'
        esm = torch.load(pt)

        for method in methods:
            if method == 'ave':
                esm_value = esm.mean().item()
            elif method == 'max':
                esm_value = esm.max().item()
            elif method == 'min':
                esm_value = esm.min().item()
            else:
                raise ValueError(f'{method} method not supported.')
            esm_values[method][mut_name] = esm_value

    method_corr = {}
    for method in methods:
        plot_corr(exp_data, esm_values[method], x_name='exp', y_name=f'esm-{method}', rootdir=rootdir, **kwargs)
        method_corr[method] = get_corr(exp_data, esm_values[method])

    if len(methods) == 1:
        return method_corr[methods[0]]
    else:
        return method_corr
(Legacy) plot esm to log2enrichment experiment data and evaluate correlations.

    Args:
        exp_data: Dictionary of mutant name and experiment data, i.e. {mut_name: y}
        pssm: Path to pssm file from psiblast.
        rootdir: Destination directory for exp-pssm.png.
        kwargs: Keyword arguments for seaborn.jointplot.
    
(Legacy) plot esm to log2enrichment experiment data and evaluate correlations.
( Legacy ) plot esm to log2enrichment experiment data and evaluate correlations .
def visual_esm_corr(methods: Optional[Union[str, Tuple]] = None, rootdir: Optional[AnyPath] = None, pdb_name: str = '1gnx',
                    exp_data: Optional[Union[Dict, OrderedDict]] = None, esm_dir: Optional[AnyPath] = None,
                    **kwargs) -> Union[CorrType, Dict[str, CorrType]]:
    esm_dir = Path('data/embeddings/esm') if esm_dir is None else Path(esm_dir)
    if not esm_dir.exists():
        raise FileNotFoundError(f'{esm_dir} not found.')
    if methods is None:
        methods = ('ave', 'max', 'min')
    elif type(methods) == str:
        methods = [methods]
    else:
        methods = list(methods)
    if exp_data is None:
        exp_data = read_log2en(return_type='OrderedDict')
    esm_values = {method: OrderedDict() for method in methods}
    for mut_name, log2en_value in exp_data.items():
        pt = esm_dir / f'{pdb_name}_{mut_name}.pt'
        esm = torch.load(pt)
        for method in methods:
            if method == 'ave':
                esm_value = esm.mean().item()
            elif method == 'max':
                esm_value = esm.max().item()
            elif method == 'min':
                esm_value = esm.min().item()
            else:
                raise ValueError(f'{method} method not supported.')
            esm_values[method][mut_name] = esm_value
    method_corr = {}
    for method in methods:
        plot_corr(exp_data, esm_values[method], x_name='exp', y_name=f'esm-{method}', rootdir=rootdir, **kwargs)
        method_corr[method] = get_corr(exp_data, esm_values[method])
    if len(methods) == 1:
        return method_corr[methods[0]]
    else:
        return method_corr
def visual_esm_corr ( methods : Optional [ Union [ str , Tuple ] ] = None , rootdir : Optional [ AnyPath ] = None , pdb_name : str = '1gnx' , exp_data : Optional [ Union [ Dict , OrderedDict ] ] = None , esm_dir : Optional [ AnyPath ] = None , ** kwargs ) -> Union [ CorrType , Dict [ str , CorrType ] ] : esm_dir = Path ( 'data/embeddings/esm' ) if esm_dir is None else Path ( esm_dir ) if not esm_dir . exists ( ) : raise FileNotFoundError ( f'{esm_dir} not found.' ) if methods is None : methods = ( 'ave' , 'max' , 'min' ) elif type ( methods ) == str : methods = [ methods ] else : methods = list ( methods ) if exp_data is None : exp_data = read_log2en ( return_type = 'OrderedDict' ) esm_values = { method : OrderedDict ( ) for method in methods } for mut_name , log2en_value in exp_data . items ( ) : pt = esm_dir / f'{pdb_name}_{mut_name}.pt' esm = torch . load ( pt ) for method in methods : if method == 'ave' : esm_value = esm . mean ( ) . item ( ) elif method == 'max' : esm_value = esm . max ( ) . item ( ) elif method == 'min' : esm_value = esm . min ( ) . item ( ) else : raise ValueError ( f'{method} method not supported.' ) esm_values [ method ] [ mut_name ] = esm_value method_corr = { } for method in methods : plot_corr ( exp_data , esm_values [ method ] , x_name = 'exp' , y_name = f'esm-{method}' , rootdir = rootdir , ** kwargs ) method_corr [ method ] = get_corr ( exp_data , esm_values [ method ] ) if len ( methods ) == 1 : return method_corr [ methods [ 0 ] ] else : return method_corr
(Legacy) plot esm to log2enrichment experiment data and evaluate correlations.
( Legacy ) plot esm to log2enrichment experiment data and evaluate correlations .
"""(Legacy) plot esm to log2enrichment experiment data and evaluate correlations.

    Args:
        exp_data: Dictionary of mutant name and experiment data, i.e. {mut_name: y}
        pssm: Path to pssm file from psiblast.
        rootdir: Destination directory for exp-pssm.png.
        kwargs: Keyword arguments for seaborn.jointplot.
    """
methods
Optional[Union[str, Tuple]]
rootdir
Optional[AnyPath]
Destination directory for exp-pssm.png.
Destination directory for exp - pssm . png .
pdb_name
str
exp_data
Optional[Union[Dict, OrderedDict]]
Dictionary of mutant name and experiment data, i.e. {mut_name: y}
Dictionary of mutant name and experiment data i . e . { mut_name : y }
esm_dir
Optional[AnyPath]
pssm
Path to pssm file from psiblast.
Path to pssm file from psiblast .
kwargs
Keyword arguments for seaborn.jointplot.
Keyword arguments for seaborn . jointplot .