U
    md+                  
   @   s   d dl mZmZ d dlZd dlZd dlmZ d dl	m
Z d dlmZ ddlmZ ddlmZ d	d
lmZ d	dlmZ eeddeeee eeeef  ee ee edddZdS )    )OptionalUnionN)AnnData)pyplot)Axes   )_utils)doc_show_save_ax   )normalize_total)_doc_params)Zshow_save_ax   F)adatan_topshowsaveaxgene_symbolslogc                 K   sb  ddl }ddlm}	 t| ddd}
|	|
d rt|
d jddj}t|ddd	 d| }|
d dd|f j}n@|
d jdd}t|ddd	 d| }|
d dd|f }|dkr| j	| n| j
| | }tj|| j|d
}|s|d d }tjd|fd\}}|jf |d|dd| |d |r@|d tjd||d |dkr^|S dS )u9      Fraction of counts assigned to each gene over all cells.

    Computes, for each gene, the fraction of counts assigned to that gene within
    a cell. The `n_top` genes with the highest mean fraction over all cells are
    plotted as boxplots.

    This plot is similar to the `scater` package function `plotHighestExprs(type
    = "highest-expression")`, see `here
    <https://bioconductor.org/packages/devel/bioc/vignettes/scater/inst/doc/vignette-qc.html>`__. Quoting
    from there:

        *We expect to see the “usual suspects”, i.e., mitochondrial genes, actin,
        ribosomal protein, MALAT1. A few spike-in transcripts may also be
        present here, though if all of the spike-ins are in the top 50, it
        suggests that too much spike-in RNA was added. A large number of
        pseudo-genes or predicted genes may indicate problems with alignment.*
        -- Davis McCarthy and Aaron Lun

    Parameters
    ----------
    adata
        Annotated data matrix.
    n_top
        Number of top
    {show_save_ax}
    gene_symbols
        Key for field in .var that stores gene symbols if you do not want to use .var_names.
    log
        Plot x-axis in log scale
    **kwds
        Are passed to :func:`~seaborn.boxplot`.

    Returns
    -------
    If `show==False` a :class:`~matplotlib.axes.Axes`.
    r   N)issparsed   F)Z
target_sumZinplaceX)Zaxis)indexcolumnsg?g      ?   )Zfigsizehr   )dataZorientr   Z	fliersizez% of total countsr   highest_expr_genes)r   r   )ZseabornZscipy.sparser   r   ZmeanA1npZargsortAZ	var_namesvarpdZ	DataFrameZ	obs_namespltZsubplotsZboxplotZ
set_xlabelZ
set_xscaler   Zsavefig_or_show)r   r   r   r   r   r   r   kwdsZsnsr   Z	norm_dictZmean_percentZtop_idxZcounts_top_genesr   heightZfig r'   L/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/scanpy/plotting/_qc.pyr      s:    0  


r   )r   NNNNF)typingr   r   numpyr    Zpandasr#   Zanndatar   Z
matplotlibr   r$   Zmatplotlib.axesr    r   Z_docsr	   Zpreprocessing._normalizationr   r   intboolstrr   r'   r'   r'   r(   <module>   s2         