o
    Uݢg	                     @  sT   d Z ddlmZ ddlZddlmZ ddlmZ G dd deZ	G dd	 d	e
ZdS )
zRA file to read and ingest cell_barcodes.json files produced by PARSE_MULTI_CONFIG.    )annotationsN)load_barcode_whitelist)-get_whitelist_name_from_chemistry_descriptionc                   @  s   e Zd ZdZdS )InvalidCellBarcodez&Barcode is not from a given whitelist.N)__name__
__module____qualname____doc__ r
   r
   g/oak/stanford/groups/akundaje/marinovg/programs/cellranger-9.0.1/lib/python/cellranger/cell_barcodes.pyr      s    r   c                      s*   e Zd ZdZ fddZdddZ  ZS )	CellBarcodeszKPython equivalent of file produced by Rust code, list of barcodes as bytes.c                   sV   t    t|}t|D ]	}| |  qW d   dS 1 s$w   Y  dS )a  Load a JSON file with a list of barcodes.

        e.g. like

        .. code-block:: python

            to_keep = [
                "AACAAAGAGCAACCAG-1",
                "AACGAAAGTGACCGAA-1",
                "AAGCGAGCAGTTGAAA-1",
                "AAGCGTTTCCCGTTCA-1",
                "AAGTGAACAAGATGGC-1",
                "AATCACGTCGTAACTG-1",
                "AATGGAAGTTAAGCAA-1",
                "AATGGAAGTTCCTTGC-1",
                "AATTCCTAGCCATTTG-1"
            ]

        Args:
            json_file_name: json path to load
        N)super__init__openjsonloadappendencode)selfZjson_file_namefbc	__class__r
   r   r      s   

"zCellBarcodes.__init__chemistry_description
str | Nonec                 C  sl   |dur0t |}|dur2t|d dd}| D ]}|dd }||vr/td|  d| qdS dS dS )	aq  Given a chemistry description (which corresponds to a "description" in the chemistry_defs.json.

        try to load the whitelist and verify that everything in this list is on that whitelist.

        Args:
            chemistry_description: string that corresponds to a "description" in the chemistry_defs.json

        Returns:
            None or Exception
        NnameT)Zas_set   -r   z	Barcode: z is invalid for the chemistry )r   r   splitr   decode)r   r   Zwhitelist_name	whitelistbarcodeZstripped_bcr
   r
   r   verify_bcs_match_whitelist0   s   z'CellBarcodes.verify_bcs_match_whitelist)r   r   )r   r   r   r	   r   r!   __classcell__r
   r
   r   r   r      s    r   )r	   
__future__r   r   Zcellranger.barcodes.utilsr   cellranger.chemistryr   	Exceptionr   listr   r
   r
   r
   r   <module>   s   