o
    Uݢgop                     @  s  d Z ddlmZ ddlZddlZddlmZmZmZm	Z	m
Z
 ddlmZ ddlmZ ddlZddlmZmZ ddlmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZ dZddegZ eddG dd dZ!dZ"e"gZ#e#Z$dZ%G dd de&Z'G dd dZ(G dd dZ)dS )z<Types for loading, saving, and using feature reference data.    )annotationsN)
Collection	Generator	ItemsViewIterableKeysView)	dataclass)TextIO)ensure_binary
ensure_str)
MHC_ALLELETARGETING_ANTIGEN)ANTIGEN_LIBRARY_TYPE)EXCLUDED_PROBE_ID_PREFIXESfeature_typeidnameT)frozenc                   @  sD   e Zd ZU dZded< ded< ded< ded	< d
ed< dddZdS )
FeatureDefz@A more sophisticated object for FeatureDef that allows defaults.intindexbytesr   
str | Noner   strr   zdict[str, str]tagsheadersIterable[str]return	list[str]c                 C  sz   g }|D ]6}|t d kr|| jd q|t d kr#|| j q|t d kr0|| j q|| j|d q|S )z4Get list of attributes corresponding to the feature.r   zutf-8       )REQUIRED_DATASETSappendr   decoder   r   r   get)selfr   Zret_listheader r(   e/oak/stanford/groups/akundaje/marinovg/programs/cellranger-9.0.1/lib/python/cellranger/feature_ref.pyget_attr_list(   s   zFeatureDef.get_attr_listN)r   r   r   r   )__name__
__module____qualname____doc____annotations__r*   r(   r(   r(   r)   r      s   
 r   genomeZhashtagc                      s(   e Zd ZdZ fddZdd Z  ZS )FeatureDefExceptionzOException type for trying to create a `FeatureReference` with non-distinct IDs.c                   s   t  | || _d S N)super__init__msg)r&   r5   	__class__r(   r)   r4   C   s   
zFeatureDefException.__init__c                 C  s   | j S r2   )r5   r&   r(   r(   r)   __str__G   s   zFeatureDefException.__str__)r+   r,   r-   r.   r4   r9   __classcell__r(   r(   r6   r)   r1   @   s    r1   c                   @  s~   e Zd ZdZd(ddZdd	 Zd
d Zed)ddZd*ddZ	d*ddZ
d+ddZd,ddZd-ddZd.d!d"Zd/d%d&Zd'S )0TargetFeatureSetszA set of target features.

    Each target set should be a list of integers with a dictionary key representing the name.
    This name will also exist in the library_info.
    target_features3None | TargetFeatureSets | dict[str, Iterable[int]]r   Nonec                 C  sP   i | _ |d ur$| D ]\}}tdd |D sJ t|}|| j |< qd S d S )Nc                 s  s    | ]}t |tV  qd S r2   )
isinstancer   .0xr(   r(   r)   	<genexpr>X   s    z-TargetFeatureSets.__init__.<locals>.<genexpr>)target_feature_setsitemsallset)r&   r<   r   Z_setr(   r(   r)   r4   R   s   zTargetFeatureSets.__init__c                 C  s   t |tsdS | j|jkS )NF)r?   r;   rD   r&   otherr(   r(   r)   __eq__\   s   
zTargetFeatureSets.__eq__c                 C  
   t | jS r2   )hashrD   r8   r(   r(   r)   __hash__a      
zTargetFeatureSets.__hash__KeysView[str]c                 C  
   | j  S r2   )rD   keysr8   r(   r(   r)   namesd   s   
zTargetFeatureSets.namesItemsView[str, set[int]]c                 C  rP   r2   rD   rE   r8   r(   r(   r)   rE   h   rN   zTargetFeatureSets.itemsc                 C  rP   )zReturns a view of the items.

        .. deprecated::4.0
            Use `items` instead.  Python 3 doesn't do `iteritems`.
        rT   r8   r(   r(   r)   	iteritemsk   s   
zTargetFeatureSets.iteritemskeyr   set[int] | Nonec                 C  s   | j |S r2   )rD   r%   )r&   rV   r(   r(   r)   r%   s   s   zTargetFeatureSets.getrI   dict[str, set[int]]c                 C  s   | j | d S r2   )rD   updaterH   r(   r(   r)   rY   v   s   zTargetFeatureSets.updater   c                 C     t tj| j  S )zReturns the number of distinct feature indices.

        This is more efficient than len(get_target_feature_indices()
        because it doesn't bother to sort the indices.
        )lenrG   unionrD   valuesr8   r(   r(   r)   count_target_feature_indicesy   s   z.TargetFeatureSets.count_target_feature_indices	list[int]c                 C  rZ   r2   )sortedrG   r\   rD   r]   r8   r(   r(   r)   get_target_feature_indices   s   z,TargetFeatureSets.get_target_feature_indicesold_to_new_index_translationdict[int, int]c                   sH   t  tsJ i }| j D ]\}} fdd|D }|||< qt|S )a{  Recreates a list of target features by subsetting it.

        If the Feature Reference holding this object is ever subset, or the index values are changed,
        we need to update the target_feature_sets to hold these new values instead.  This function
        recreates a list of target features by subsetting it to only those present in a translation
        table that maps old index positions to new ones.

        Args:
            old_to_new_index_translation: a dictionary that tells what old index position is being converted
            to a new index position

        Returns:
            A new TargetFeatureSets
        c                   s   g | ]
}| v r | qS r(   r(   )rA   Z	old_indexrb   r(   r)   
<listcomp>   s
    z@TargetFeatureSets.subset_to_reduced_features.<locals>.<listcomp>)r?   dictrD   rE   r;   )r&   rb   new_target_featuresr   indicesZnew_valsr(   rd   r)   subset_to_reduced_features   s   

z,TargetFeatureSets.subset_to_reduced_featuresN)r<   r=   r   r>   )r   rO   )r   rS   )rV   r   r   rW   )rI   rX   r   r>   r   r   )r   r_   )rb   rc   r   r;   )r+   r,   r-   r.   r4   rJ   rM   propertyrR   rE   rU   r%   rY   r^   ra   ri   r(   r(   r(   r)   r;   K   s    







r;   c                   @  s  e Zd ZdZ	dudvd	d
ZdwddZdd Zdd Zdd ZdxddZ	dyddZ
dzddZd{d d!Zd|d#d$Zd}d(d)Zd~d*d+Zd~d,d-Z	dudd1d2Zdd6d7Z	8ddd<d=Zedd@dAZeddBdCZddDdEZddFdGZddIdJZduddKdLZdydMdNZdOdP ZddRdSZddUdVZddWdXZ ddZd[Z!dd\d]Z"dd^d_Z#dzd`daZ$ddcddZ%ddgdhZ&ddldmZ'ddpdqZ(eddsdtZ)dS )FeatureReferencez2Store a list of features (genes, antibodies, etc).Nfeature_defslist[FeatureDef]all_tag_keysr   r<   r=   c                 C  s   || _ || _|durt|| _nd| _i }| j D ]<}|j|v rOd|j d|j d|j }d||j j d||j j d||j j }td| d| d|||j< q|| _dS )a  Create a FeatureReference.

        Args:
            feature_defs (list of FeatureDef): All feature definitions.
            all_tag_keys (list of str): All optional tag keys.
            target_features (dictionary of list of int): Optional target set(s). Each target set
            should be a list of integers with a dictionary key representing the name. This name
            will also exist in the library_info.
        NzID: z; name: z; type: z1Found two feature definitions with the same ID: (z) and (z$). All feature IDs must be distinct.)	rm   ro   r;   r<   r   r   r   r1   id_map)r&   rm   ro   r<   rp   ZfdefZthis_fd_strZseen_fd_strr(   r(   r)   r4      s&   

.
zFeatureReference.__init__r   r   r   r   c                 C  s&   d}| j D ]}|j|kr|d7 }q|S )zeCount how many features in the matrix are of a given type.

        (e.g. "Gene Expression")
        r   r   )rm   r   )r&   r   totalfeaturer(   r(   r)   get_count_of_feature_type   s   

z*FeatureReference.get_count_of_feature_typec                 C  s8   | j |j ko| j|jko| jd u |jd u ko| j|jkS r2   rm   ro   r<   rH   r(   r(   r)   rJ      s   

zFeatureReference.__eq__c                 C  s.   | j d u rt| j| jfS t| j| j| j fS r2   )r<   rL   rm   ro   r8   r(   r(   r)   rM      s   
zFeatureReference.__hash__c                 C  s
   | |k S r2   r(   rH   r(   r(   r)   __ne__   rN   zFeatureReference.__ne__list[bytes]c                 C     dd | j D S )z;Return the list of feature IDs excluding deprecated probes.c                 S  s   g | ]}|j ts|j qS r(   r   
startswithr   rA   fr(   r(   r)   re          zPFeatureReference.get_feature_ids_excluding_deprecated_probes.<locals>.<listcomp>rm   r8   r(   r(   r)   +get_feature_ids_excluding_deprecated_probes   s   z<FeatureReference.get_feature_ids_excluding_deprecated_probesboolc                 C  s   t dd | jD S )z7Return true if there are deprecated probes in features.c                 s  s    | ]	}|j tV  qd S r2   rx   rz   r(   r(   r)   rC      s    z9FeatureReference.has_deprecated_probes.<locals>.<genexpr>)anyrm   r8   r(   r(   r)   has_deprecated_probes      z&FeatureReference.has_deprecated_probesc                 C  rw   )z=Return the list of feature types excluding deprecated probes.c                 S  s   g | ]}|j ts|jqS r(   )r   ry   r   r   rz   r(   r(   r)   re      s    
zRFeatureReference.get_feature_types_excluding_deprecated_probes.<locals>.<listcomp>r}   r8   r(   r(   r)   -get_feature_types_excluding_deprecated_probes   s   z>FeatureReference.get_feature_types_excluding_deprecated_probestuple | Nonec                 C  sP   d}t | jv r&dd | tjD }t|dksJ t|dkr$|d nd}|S )z7Extract antigen control feature from feature reference.Nc              	   S  s6   g | ]}|j t d kr|j|j|j|j tdfqS )FalseN)r   r   r   r   r   r%   r   rz   r(   r(   r)   re      s
    z8FeatureReference.get_antigen_control.<locals>.<listcomp>r   r   )r   ro   select_features_by_typer   rm   r[   )r&   Zcontrolr(   r(   r)   get_antigen_control   s   

z$FeatureReference.get_antigen_controlfrozenset[list[tuple]]c                 C  sL   g }|  tjD ]}||j|j|j|jt	d|jt
df qt|S )zExtract the antigen capture content from feature reference.

        The conent extracted in this function is what we expect to match between
        inputs to aggr.
        N)r   r   rm   r#   r   r   r   r   r%   r   r   	frozenset)r&   lstr{   r(   r(   r)   get_antigen_capture_content  s   
z,FeatureReference.get_antigen_capture_contentrI   is_pdtuple[bool, str | None]c           	      C  s  |   }|  }t||dkrtt|dd d}tt|dd d}t|t|ks/J t|D ]N\}}|| d || d ksEJ || d || d ksSJ || d || d ksaJ || d || d krp d	S || d
 || d
 kr|s dS q3dS )zChecks if two feature references have the same antigen capture features.

        returns appropriate error message in case of a mismatch
        r   c                 S     | d S Nr   r(   rB   r(   r(   r)   <lambda>      zAFeatureReference.equals_antigen_capture_content.<locals>.<lambda>)rV   c                 S  r   r   r(   r   r(   r(   r)   r      r   r   r       )FzThe datasets you are trying to aggregate have incompatible MHC alleles for the same control feature id. Please re-run the original multi pipelines with uniform [antigen-specificity] sections.   )FzThe datasets you are trying to aggregate have incompatible control feature ids. Please re-run the original multi pipelines with uniform [antigen-specificity] sections.)TN)r   r[   
differencer`   list	enumerate)	r&   rI   r   Zantigen_content_1Zantigen_content_2Zsorted_antigen_content_1Zsorted_antigen_content_2i_r(   r(   r)   equals_antigen_capture_content  s    z/FeatureReference.equals_antigen_capture_contentc                 C  st   |    p	|   }|p|  | k}dd | jD }dd |jD }|  | ko9|  | ko9||ko9|S )a-  Checks if two feature references are equal, ignoring missing targets.

        Only takes into account equality of the target set if it is present in
        both feature references. Useful for targeted feature reference
        compatibility checks in preflights. Excludes deprecated probes.
        c                 S     g | ]}|t kr|qS r(   HASHTAG_TAGrA   tagr(   r(   r)   re   G      z=FeatureReference.equals_ignore_target_set.<locals>.<listcomp>c                 S  r   r(   r   r   r(   r(   r)   re   H  r   )has_target_featuresra   ro   r   r~   )r&   rI   ignore_target_setcompatible_target_setsZself_all_tagsZother_all_tagsr(   r(   r)   equals_ignore_target_set;  s"   z)FeatureReference.equals_ignore_target_setc                 C  s,   |    p	|   }|p|  | k}|S )zChecks if two feature references have compatible target sets.

        Useful for targeted feature reference compatibility checks in preflights.

        Returns:
            True if either target set does not exist or if they are identical.
        r   ra   )r&   rI   r   r   r(   r(   r)   has_compatible_target_setS  s
   z*FeatureReference.has_compatible_target_setnew_tags
new_labels"Collection[Collection[str]] | Nonec                   s   t |dksJ |D ]}|| jv rtdq
|du r'|D ]}| |i  qdS t | jt |kr4td|D ]}t |t |ksBJ q6t|D ]\ } fdd|D }dd t| j|D }| || qGdS )	a  Add new tags and corresponding labels to self.

        If new labels are None, empty strings are supplied by default.

        Args:
            new_tags (list[str]):  a list of new tags
            new_labels (Optional[Collection[Collection[str]]], optional): per feature
                list of label values corresponding to the new tags. Defaults to None.

        Raises:
            ValueError: Tag already present
            ValueError: Number of labels is not equal to number of features in feature ref
        r   z(tag {} is already present in feature_refNzAnumber of labels does not match number of features in feature_refc                 3  s    | ]}|  V  qd S r2   r(   r@   indr(   r)   rC     s    z,FeatureReference.add_tags.<locals>.<genexpr>c                 S  s   i | ]\}}|j |qS r(   r   )rA   r{   labelr(   r(   r)   
<dictcomp>  s    z-FeatureReference.add_tags.<locals>.<dictcomp>)r[   ro   
ValueErroradd_tagrm   r   zip)r&   r   r   r   labelsZ
label_listfeature_id_to_label_dictr(   r   r)   add_tagsa  s,   

zFeatureReference.add_tagstag_to_updater   !dict[str, str] | dict[bytes, str]c                 C  sX   || j vrtdd| d d| j   | jD ]}|j|v r)||jd|j|< qdS )a<  Updates a tag in the feature reference.

        The features that need to
        be updated with their new tag values are passed in.

        Args:
            tag_to_update (str): a tag to update. Should be in feature_ref
            feature_id_to_label_dict (Union[dict[str, str], dict[bytes, str]]): a
                dict of {feature_id: new_value_of_tag} to update. The features that need to
                be updated mapped to their new tag values.

        Raises:
            ValueError: If tag passed in to be updated does not exist in the feature ref
        z"Tag to update not in Feature ref. Tag to update  . Tags in matrix r!   N)ro   r   rm   r   r%   r   )r&   r   r   f_defr(   r(   r)   
update_tag  s   




zFeatureReference.update_tagr!   
tag_to_adddefault_tag_valuer   c                 C  sZ   || j v rtdd| d d| j   | jD ]}||j||j|< q| j | dS )aP  Adds a tag to a Feature Reference.

        Args:
            tag_to_add (str): name of the tag to add
            feature_id_to_label_dict (Union[dict[str, str], dict[bytes, str]]):dict of
                {feature_id: new_value_of_tag} to update. The features that need to
                be updated mapped to their new tag values
            default_tag_value (Optional[str], optional): Value of the tag for features
            not in feature_id_to_label_dict. Defaults to "".

        Raises:
            ValueError: If tag passed in to be added already exists in the feature ref
        z(Tag to be added already in Feature ref. r   r   r   N)ro   r   rm   r%   r   r   r#   )r&   r   r   r   r   r(   r(   r)   r     s   



zFeatureReference.add_tagfeature_ref1feature_ref2c                 C  sf   | j |j ksJ | j}|j}| jdu r|j}n|jdu r | j}n	| j}||j t|| | j |dS )zKConcatenate two feature references, requires unique ids and identical tags.Nrt   )ro   rm   r<   rY   rl   )r   r   Zfeature_defs1Zfeature_defs2Zcombined_target_featuresr(   r(   r)   join  s   

zFeatureReference.joinc                 C  s   | g g d dS )Nrt   r(   )clsr(   r(   r)   empty  s   zFeatureReference.emptyc                 C  rK   r2   )r[   rm   r8   r(   r(   r)   get_num_features  rN   z!FeatureReference.get_num_featuresc                       fdd| j D S )zSReturn a list of feature ids of a particular feature type (e.g. "Gene Expression").c                      g | ]
}|j  kr|jqS r(   )r   r   rz   r   r(   r)   re     s    z<FeatureReference.get_feature_ids_by_type.<locals>.<listcomp>r}   r&   r   r(   r   r)   get_feature_ids_by_type  r   z(FeatureReference.get_feature_ids_by_typer_   c                   r   )Nc                   r   r(   )r   r   )rA   rr   r   r(   r)   re     s    z9FeatureReference.get_indices_for_type.<locals>.<listcomp>r}   r   r(   r   r)   get_indices_for_type  s   
z%FeatureReference.get_indices_for_typec                   s    fdd| j D }t|S )zGet sorted list of genomes.

        Empty string is for reverse compatibility.

        A specific feature type can optionally be specified.
        c                   s,   h | ]} d u s|j  kr|jtdqS )Nr!   )r   r   r%   GENOME_FEATURE_TAGrz   r   r(   r)   	<setcomp>  s
    z/FeatureReference.get_genomes.<locals>.<setcomp>)rm   r`   )r&   r   genomesr(   r   r)   get_genomes  s   
zFeatureReference.get_genomesc                 C  s
   | j d uS r2   )r<   r8   r(   r(   r)   r     rN   z$FeatureReference.has_target_featuresc                 C  s   | j dur
| j  S dS )zReturns the number of feature indices.

        If there are no target features, returns zero.

        This is more efficient than len(get_target_feature_indices()) because
        it doesn't bother sorting the indices.
        Nr   )r<   r^   r8   r(   r(   r)   r^     s
   

z-FeatureReference.count_target_feature_indiceslist[int] | Nonec                 C  s   |   sdS | j S )z}Gets the indices of on-target features within the FeatureReference.

        Returns None if there is no target set.
        N)r   r<   ra   r8   r(   r(   r)   ra   	  s   
z+FeatureReference.get_target_feature_indiceslist[bytes] | Nonec                   s"      sdS  fdd  D S )zeGets the feature ids of on-target features.

        Returns None if there is no target set.
        Nc                   s   g | ]} j | jqS r(   )rm   r   rA   r   r8   r(   r)   re     r   z;FeatureReference.get_target_feature_ids.<locals>.<listcomp>r   r8   r(   r8   r)   get_target_feature_ids  s   z'FeatureReference.get_target_feature_idsc                   s"    fddt | jD }| |S )z_Returns all features that match a given type.

        Args:
            feature_type:
        c                   s   g | ]\}}|j  kr|qS r(   r   rA   r   fdr   r(   r)   re   #  r|   z<FeatureReference.select_features_by_type.<locals>.<listcomp>)r   rm   select_features)r&   r   rh   r(   r   r)   r     s   
z(FeatureReference.select_features_by_typer0   c                   s    fddt | jD S )zReturns the indices of features within the FeatureReference with genome.

        Args:
            genome: Genome name
        c                   s&   g | ]\}}|j td  kr|qS r!   )r   r%   r   r   r0   r(   r)   re   ,  s
    zBFeatureReference.get_feature_indices_by_genome.<locals>.<listcomp>)r   rm   r&   r0   r(   r   r)   get_feature_indices_by_genome&  s   
z.FeatureReference.get_feature_indices_by_genomec                 C  s   |  | |S )zgReturns all features that match a given genome.

        Args:
            genome: Genome name
        )r   r   r   r(   r(   r)   select_features_by_genome2     z*FeatureReference.select_features_by_genomec                 C  s$   t | jD ]
}|j|kr dS qdS )zDetermines if a feature type is present in the FeatureRef.

        Args:
            feature_type:

        Returns:
            True | False
        TF)reversedrm   r   )r&   r   featr(   r(   r)   has_feature_type:  s
   	
z!FeatureReference.has_feature_typec                 C  rw   )zjGet a list of feature names.

        Returns:
            The names of all of the featture_defs.
        c                 S     g | ]}|j qS r(   )r   r@   r(   r(   r)   re   N      z6FeatureReference.get_feature_names.<locals>.<listcomp>r}   r8   r(   r(   r)   get_feature_namesH  r   z"FeatureReference.get_feature_nameslist[str] | list[bytes]c                 C  rw   )zeGet a list of feature IDs.

        Returns:
            The IDs of all of the feature_defs.
        c                 S  r   r(   r   r@   r(   r(   r)   re   V  r   z4FeatureReference.get_feature_ids.<locals>.<listcomp>r}   r8   r(   r(   r)   get_feature_idsP  r   z FeatureReference.get_feature_idsrh   Iterable[int]c              
     s    fdd|D }g }i }t |D ]\}}|||j< |t||j|j|j|jd q  r@ j	
|}t| dkr?d}nd}t| j|dS )zCreate a new FeatureReference that only contains features with the given indices.

        Any target sets present are updated, but the target_features attribute in the output
        is set to None if all target features were removed.
        c                   s   g | ]} j | qS r(   r}   r   r8   r(   r)   re   ^      z4FeatureReference.select_features.<locals>.<listcomp>)r   r   r   r   r   r   Nrt   )r   r   r#   r   r   r   r   r   r   r<   ri   r[   ra   rl   ro   )r&   rh   Zold_defsZnew_defsZtranslation_mapr   r   rg   r(   r8   r)   r   X  s2   

z FeatureReference.select_featuresgroup
h5py.Groupr>   c                   s   t D ]  fdd| jD }tj| |dd q| jD ]  fdd| jD }tj| |dd q| jdurV|tj}| j	 D ]\}}tj||dd t
|D dd qAt|d| j dS )	zWrite to an HDF5 group.c                   s   g | ]}t | qS r(   )getattrrz   colr(   r)   re   ~  r   z,FeatureReference.to_hdf5.<locals>.<listcomp>T)compressionc                   s   g | ]	}|j  d qS r   )r   r%   rz   r   r(   r)   re     s    Nc                 S     g | ]}t |qS r(   )r   r@   r(   r(   r)   re         _all_tag_keys)r"   rm   cr_h5Zcreate_hdf5_string_datasetro   r<   Zcreate_grouph5_constantsH5_TARGET_SET_ATTRrE   r`   )r&   r   dataZtarget_set_grouprV   valr(   r   r)   to_hdf5z  s   

zFeatureReference.to_hdf5handler	   c                 C  s>   t | j }t|}|| | jD ]
}||| qdS )zWrite to a csv file (only columns specified in CSV_HEADER).

        Args:
            handle: the file-like object the feature ref will be written to
        N)r"   ro   csvwriterwriterowrm   r*   )r&   r   Zcsv_headersr   rr   r(   r(   r)   to_csv  s   



zFeatureReference.to_csvh5py.Datasetc              
     s   ddddd
d 	dd  fddt |d }dd  D }t|dkr0d}g }ttd  }t|D ]&fdd|D }|ttd  d  t  |d q>| |||dS )!zLoad from an HDF5 group.

        Args:
            group (h5py.Dataset): Group to load from.

        Returns:
            feature_ref (FeatureReference): New object.
        noder   r   r   c                 S  s>   | j d u rg S | jjtjkr| jdv }t| |S | d d  S )N)z/features/feature_typez/features/genome)shapedtypecharr   ZSTR_DTYPE_CHARr   Zread_hdf5_string_dataset)r   memoizer(   r(   r)   	_load_str  s   

z-FeatureReference.from_hdf5.<locals>._load_strpathstr | bytesr   c                 S  s"   | dd } t | tr|  S | S )z>Strip off leading slash and convert to str (could be unicode).r   N)r?   r   r$   )r   r(   r(   r)   _format_path  s   z0FeatureReference.from_hdf5.<locals>._format_pathr!   r   h5py.Group | h5py.Datasetprefix,Generator[tuple[str, list[str]], None, None]c                 3  sb    | D ]+}| | }| d| }t |tjr  ||fV  qt |tjr.||E d H  qd S )N/)r?   h5pyZDatasetZGroup)r   r  rV   itemr   )r  _h5py_dataset_iteratorr   r(   r)   r	    s   z:FeatureReference.from_hdf5.<locals>._h5py_dataset_iteratorr   c                 S  s6   i | ]\}}t jt|v rtj|d d |D qS )c                 S  r   r(   )r   r@   r(   r(   r)   re     r   z9FeatureReference.from_hdf5.<locals>.<dictcomp>.<listcomp>)r   r   r
   osr   basename)rA   rV   r   r(   r(   r)   r     s
    z.FeatureReference.from_hdf5.<locals>.<dictcomp>r   Nc                   s.   i | ]} |  rt |t  |  qS r(   )r   )rA   k)r   r   r(   r)   r     s   . r   r   )r   r   r   r   r   )ro   r<   )r   r   r   r   )r   r  r   r   r   )r   r  r  r   r   r  )	rf   rE   r[   r"   ranger#   r   r
   FEATURE_TYPE)r   r   ro   r<   rm   Znum_featuresr   r(   )r  r	  r   r   r   r)   	from_hdf5  s2   

	


zFeatureReference.from_hdf5r2   )rm   rn   ro   r   r<   r=   )r   r   r   r   )r   rv   )r   r   )r   r   )r   r   )r   r   )rI   rl   r   r   r   r   )rI   rl   r   r   )r   r   r   r   )r   r   r   r   r   )r   r   r   r   r   r   )r   rl   r   rl   r   rl   )r   rl   rj   )r   r   r   rv   )r   r   r   r_   )r   r   r   r   )r   r   )r   r   )r   r   r   rl   )r0   r   r   r_   )r0   r   r   rl   )r   r   r   r   )r   r   )rh   r   r   rl   )r   r   r   r>   )r   r	   r   r>   )r   r   r   rl   )*r+   r,   r-   r.   r4   rs   rJ   rM   ru   r~   r   r   r   r   r   r   r   r   r   r   staticmethodr   classmethodr   r   r   r   r   r   r^   ra   r   r   r   r   r   r   r   r   r   r   r  r(   r(   r(   r)   rl      sX    
%






&

("









	





"
rl   )*r.   
__future__r   r   r
  collections.abcr   r   r   r   r   dataclassesr   typingr	   r  sixr
   r   cellranger.h5_constantsr   Zcellranger.hdf5Zhdf5r   Z&cellranger.feature.antigen.specificityr   r   cellranger.rna.libraryr   &cellranger.targeted.targeted_constantsr   r  r"   r   r   DEFAULT_FEATURE_TAGSRESERVED_TAGSr   	Exceptionr1   r;   rl   r(   r(   r(   r)   <module>   s2   
V