o
    Uݢg                     @  sP   d Z ddl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 ZdS )zcCode to provide preflights for AGGR and munging of data.

From multiple versions in the preflight.
    )annotationsNc              	   C  s  t  }g }| jD ]}| jtjk}|tj }tj|s#t	
d|  t|tjs2t	
d|  t|s?t	
d|  t|}|rT|tjkrTt	
d| d ||v rat	
d|  n|| d}t|\}}	|	dk r|rt	
d	| d
 n{|rtj|d}
|
 st	
d|d  W d   n1 sw   Y  nS|	dk rt	
d||	f  nE|	dkrt|}t|tj ddd }t|d }tdd | D }|dk s|st	
d	| d |d jd }tjj |dd}|!||	|d q|ddidS )a"  The split method for the `CHECK_MOLECULE_INFO_VERSION` stage.

    It verifies the versions of all the input files meet requirements, and if
    necessary, schedules the main stage to update all of them.

    Args:
        args: The args to the stage

    Returns:
        dict: chunks
    z$Input molecule file does not exist: zDInput molecule file is not readable, please check file permissions: z.Input molecule file is not a valid HDF5 file: zInput is a z& file, but a molecule file is requiredz@Same molecule file is specified in multiple sample definitions:       zThe molecule info HDF5 file (z#) was not produced by Space Ranger.rzVThe sample {} is not compatible with spaceranger aggr. Please use a matching pipeline.
library_idN   z|The molecule info HDF5 file (%s, version: %d) was produced by an older software version. Reading these files is unsupported..r   
gem_groupsc                 s  s    | ]}d |v V  qdS )Zconf_mapped_filtered_bc_readsN ).0groupr
   r
   l/oak/stanford/groups/akundaje/marinovg/programs/cellranger-9.0.1/lib/python/cellranger/aggr/preprocessing.py	<genexpr>U   s    
z4check_molecule_info_version_split.<locals>.<genexpr>zP) was produced by an older software version. Reading these files is unsupported.barcode   )scale)
sample_defmol_h5_version__mem_gbr   )chunksjoin)"setZsample_defsproduct_typecr_constantsSPATIAL_PRODUCT_TYPEAGG_H5_FIELDospathexistsmartianexitaccessR_OKcr_h5is_hdf5get_h5_filetypecr_mol_counterMOLECULE_H5_FILETYPEaddget_h5py_file_and_versionMoleculeCounteropenis_spatial_dataformatget_v2_metricsintCELLRANGER_VERSION_KEYsplitdictallvaluesshapeestimate_mem_gbappend)argsZ
files_seenr   r   
is_spatialmol_h5Zh5_filetypemem_gbmc_h5file_versionmol_infometricsZcr_major_versionZgem_metricsZmetric_in_allnrowsr
   r
   r   !check_molecule_info_version_split   s|   






rA   )__doc__
__future__r   r   r   cellranger.constants	constantsr   cellranger.hdf5hdf5r#   cellranger.molecule_countermolecule_counterr&   rA   r
   r
   r
   r   <module>   s   