@@ -658,8 +658,12 @@ def bustools_whitelist(
658658
659659
660660def matrix_to_cellranger (
661- matrix_path : str , barcodes_path : str , genes_path : str , t2g_path : str ,
662- out_dir : str , gzip : bool = False
661+ matrix_path : str ,
662+ barcodes_path : str ,
663+ genes_path : str ,
664+ t2g_path : str ,
665+ out_dir : str ,
666+ gzip : bool = False
663667) -> Dict [str , str ]:
664668 """Convert bustools count matrix to cellranger-format matrix.
665669
@@ -1065,8 +1069,10 @@ def filter_with_bustools(
10651069 if cellranger :
10661070 if not tcc :
10671071 cr_result = matrix_to_cellranger (
1068- count_result ['mtx' ], count_result ['barcodes' ],
1069- count_result ['genes' ], t2g_path ,
1072+ count_result ['mtx' ],
1073+ count_result ['barcodes' ],
1074+ count_result ['genes' ],
1075+ t2g_path ,
10701076 os .path .join (counts_dir , CELLRANGER_DIR ),
10711077 gzip = gzip
10721078 )
@@ -1290,7 +1296,7 @@ def count(
12901296 by_name: Aggregate counts by name instead of ID.
12911297 cellranger: Whether to convert the final count matrix into a
12921298 cellranger-compatible matrix, defaults to `False`
1293- gzip: Whether to gzip compress cellranger output matrices,
1299+ gzip: Whether to gzip compress cellranger output matrices,
12941300 defaults to `False`
12951301 delete_bus: Whether to delete intermediate BUS files after successful count,
12961302 defaults to `False`
@@ -1649,8 +1655,10 @@ def update_results_with_suffix(current_results, new_results, suffix):
16491655 final_result = quant_result if quant else count_result
16501656 if cellranger :
16511657 cr_result = matrix_to_cellranger (
1652- count_result ['mtx' ], count_result ['barcodes' ],
1653- count_result ['genes' ], t2g_path ,
1658+ count_result ['mtx' ],
1659+ count_result ['barcodes' ],
1660+ count_result ['genes' ],
1661+ t2g_path ,
16541662 os .path .join (counts_dir , f'{ CELLRANGER_DIR } { suffix } ' ),
16551663 gzip = gzip
16561664 )
@@ -1760,24 +1768,26 @@ def update_results_with_suffix(current_results, new_results, suffix):
17601768 if delete_bus :
17611769 logger .info ('Deleting intermediate BUS files to save disk space' )
17621770 bus_files_to_delete = []
1763-
1771+
17641772 # Collect all .bus files from results
17651773 if 'bus' in unfiltered_results :
17661774 bus_files_to_delete .append (unfiltered_results ['bus' ])
17671775 if 'bus_scs' in unfiltered_results :
17681776 bus_files_to_delete .append (unfiltered_results ['bus_scs' ])
1769-
1777+
17701778 # For smartseq3, delete suffix versions too
17711779 for suffix in ['' , INTERNAL_SUFFIX , UMI_SUFFIX ]:
17721780 if f'bus{ suffix } ' in unfiltered_results :
17731781 bus_files_to_delete .append (unfiltered_results [f'bus{ suffix } ' ])
17741782 if f'bus_scs{ suffix } ' in unfiltered_results :
1775- bus_files_to_delete .append (unfiltered_results [f'bus_scs{ suffix } ' ])
1776-
1783+ bus_files_to_delete .append (
1784+ unfiltered_results [f'bus_scs{ suffix } ' ]
1785+ )
1786+
17771787 # Delete filtered bus if exists
17781788 if 'filtered' in results and 'bus_scs' in results ['filtered' ]:
17791789 bus_files_to_delete .append (results ['filtered' ]['bus_scs' ])
1780-
1790+
17811791 # Delete each BUS file
17821792 for bus_file in bus_files_to_delete :
17831793 if bus_file and os .path .exists (bus_file ):
@@ -1875,7 +1885,7 @@ def count_nac(
18751885 by_name: Aggregate counts by name instead of ID.
18761886 cellranger: Whether to convert the final count matrix into a
18771887 cellranger-compatible matrix, defaults to `False`
1878- gzip: Whether to gzip compress cellranger output matrices,
1888+ gzip: Whether to gzip compress cellranger output matrices,
18791889 defaults to `False`
18801890 cellranger_style: Whether to organize output in CellRanger-style directories
18811891 (spliced/ and unspliced/ subdirectories), defaults to `False`
@@ -2181,13 +2191,19 @@ def update_results_with_suffix(current_results, new_results, suffix):
21812191 elif i == 1 : # unprocessed/unspliced
21822192 cr_dir = os .path .join (counts_dir , 'unspliced' )
21832193 else : # ambiguous
2184- cr_dir = os .path .join (counts_dir , f'{ CELLRANGER_DIR } _{ prefix } { suffix } ' )
2194+ cr_dir = os .path .join (
2195+ counts_dir , f'{ CELLRANGER_DIR } _{ prefix } { suffix } '
2196+ )
21852197 else :
2186- cr_dir = os .path .join (counts_dir , f'{ CELLRANGER_DIR } _{ prefix } { suffix } ' )
2187-
2198+ cr_dir = os .path .join (
2199+ counts_dir , f'{ CELLRANGER_DIR } _{ prefix } { suffix } '
2200+ )
2201+
21882202 cr_result = matrix_to_cellranger (
2189- count_result [i ]['mtx' ], count_result [i ]['barcodes' ],
2190- count_result [i ]['genes' ], t2g_path ,
2203+ count_result [i ]['mtx' ],
2204+ count_result [i ]['barcodes' ],
2205+ count_result [i ]['genes' ],
2206+ t2g_path ,
21912207 cr_dir ,
21922208 gzip = gzip
21932209 )
@@ -2225,7 +2241,10 @@ def update_results_with_suffix(current_results, new_results, suffix):
22252241 update_results_with_suffix (prefix_results , res , suffix )
22262242 if cellranger :
22272243 cr_result = matrix_to_cellranger (
2228- res ['mtx' ], res ['barcodes' ], res ['genes' ], t2g_path ,
2244+ res ['mtx' ],
2245+ res ['barcodes' ],
2246+ res ['genes' ],
2247+ t2g_path ,
22292248 os .path .join (
22302249 counts_dir , f'{ CELLRANGER_DIR } _{ prefix } { suffix } '
22312250 ),
@@ -2352,17 +2371,28 @@ def update_results_with_suffix(current_results, new_results, suffix):
23522371 if cellranger_style :
23532372 # Create spliced/unspliced subdirectories for CellRanger style
23542373 if i == 0 : # processed/spliced
2355- cr_dir = os .path .join (filtered_counts_dir , 'spliced' )
2374+ cr_dir = os .path .join (
2375+ filtered_counts_dir , 'spliced'
2376+ )
23562377 elif i == 1 : # unprocessed/unspliced
2357- cr_dir = os .path .join (filtered_counts_dir , 'unspliced' )
2378+ cr_dir = os .path .join (
2379+ filtered_counts_dir , 'unspliced'
2380+ )
23582381 else : # ambiguous
2359- cr_dir = os .path .join (filtered_counts_dir , f'{ CELLRANGER_DIR } _{ prefix } ' )
2382+ cr_dir = os .path .join (
2383+ filtered_counts_dir ,
2384+ f'{ CELLRANGER_DIR } _{ prefix } '
2385+ )
23602386 else :
2361- cr_dir = os .path .join (filtered_counts_dir , f'{ CELLRANGER_DIR } _{ prefix } ' )
2362-
2387+ cr_dir = os .path .join (
2388+ filtered_counts_dir , f'{ CELLRANGER_DIR } _{ prefix } '
2389+ )
2390+
23632391 cr_result = matrix_to_cellranger (
2364- count_result [i ]['mtx' ], count_result [i ]['barcodes' ],
2365- count_result [i ]['genes' ], t2g_path ,
2392+ count_result [i ]['mtx' ],
2393+ count_result [i ]['barcodes' ],
2394+ count_result [i ]['genes' ],
2395+ t2g_path ,
23662396 cr_dir ,
23672397 gzip = gzip
23682398 )
@@ -2396,7 +2426,10 @@ def update_results_with_suffix(current_results, new_results, suffix):
23962426 filtered_results [prefix ] = {}
23972427 if cellranger :
23982428 cr_result = matrix_to_cellranger (
2399- res ['mtx' ], res ['barcodes' ], res ['genes' ], t2g_path ,
2429+ res ['mtx' ],
2430+ res ['barcodes' ],
2431+ res ['genes' ],
2432+ t2g_path ,
24002433 os .path .join (
24012434 filtered_counts_dir ,
24022435 f'{ CELLRANGER_DIR } _{ prefix } '
@@ -2488,19 +2521,21 @@ def update_results_with_suffix(current_results, new_results, suffix):
24882521 if delete_bus :
24892522 logger .info ('Deleting intermediate BUS files to save disk space' )
24902523 bus_files_to_delete = []
2491-
2524+
24922525 # Collect all .bus files from results
24932526 prefixes = ['processed' , 'unprocessed' , 'ambiguous' ]
24942527 for prefix in prefixes :
24952528 if prefix in unfiltered_results :
24962529 for suffix in ['' , INTERNAL_SUFFIX , UMI_SUFFIX ]:
24972530 if f'bus{ suffix } ' in unfiltered_results [prefix ]:
2498- bus_files_to_delete .append (unfiltered_results [prefix ][f'bus{ suffix } ' ])
2499-
2531+ bus_files_to_delete .append (
2532+ unfiltered_results [prefix ][f'bus{ suffix } ' ]
2533+ )
2534+
25002535 # Delete filtered bus files if they exist
25012536 if 'filtered' in results and 'bus_scs' in results ['filtered' ]:
25022537 bus_files_to_delete .append (results ['filtered' ]['bus_scs' ])
2503-
2538+
25042539 # Delete each BUS file
25052540 for bus_file in bus_files_to_delete :
25062541 if bus_file and os .path .exists (bus_file ):
0 commit comments