@@ -504,92 +504,90 @@ def execute(self) -> None:
504504 self .meteor .ref_dir ,
505505 )
506506 sys .exit (1 )
507- try :
508- census_json_files = list (
509- self .meteor .fastq_dir .glob ("*_census_stage_0.json" )
510- )
511- assert len (census_json_files ) > 0
512-
513- # mapping of each sample against reference
514- for library in census_json_files :
515- census_json = self .read_json (library )
516- sample_info = census_json ["sample_info" ]
517- stage1_dir = self .meteor .mapping_dir / sample_info ["sample_name" ]
518- stage1_dir .mkdir (exist_ok = True , parents = True )
519- stage1_json = (
520- self .meteor .mapping_dir
521- / sample_info ["sample_name" ]
522- / f"{ sample_info ['sample_name' ]} _census_stage_1.json"
523- )
524- self .json_data [library ] = {
525- "census" : census_json ,
526- "directory" : stage1_dir ,
527- "Stage1FileName" : stage1_json ,
528- "reference" : ref_json ,
529- }
530- if not stage1_json .exists ():
531- mapping_done = False
532- # mapping already done and no overwriting
533- if mapping_done :
534- logging .info (
535- "Mapping already done for sample: %s" ,
536- sample_info ["sample_name" ],
537- )
538- logging .info ("Skipped !" )
539- else :
540- logging .info ("Launch mapping" )
541- self .launch_mapping ()
542- # running counter
543- stage1_json_data = self .read_json (stage1_json )
544- raw_cram_file = (stage1_dir /
545- stage1_json_data ["mapping" ]["mapping_file" ]
546- )
547- cram_file = (
548- stage1_dir
549- / f"{ sample_info ['sample_name' ]} .cram"
550- )
551- count_file = (
552- stage1_dir
553- / f"{ sample_info ['sample_name' ]} .tsv.xz"
554- )
555- start = perf_counter ()
556- self .launch_counting (
557- raw_cram_file ,
558- cram_file ,
559- count_file ,
560- ref_json ,
561- stage1_json_data ,
562- stage1_json ,
563- )
564- # Add final mapping rate
565- stage1_json_data = self .read_json (stage1_json )
566- stage1_json_data ["counting" ]["final_mapping_rate" ] = (
567- round (
568- stage1_json_data ["counting" ]["counted_reads" ]
569- / stage1_json_data ["mapping" ]["total_read_count" ]
570- * 100 ,
571- 2
572- )
573- )
574- self .save_config (
575- stage1_json_data ,
576- stage1_json
577- )
578507
579- logging .info ("Completed counting in %f seconds" , perf_counter () - start )
580- if not self .keep_all_alignments :
581- logging .info (
582- "Raw cram file is not kept (--ka). "
583- "Re-counting operation will need to be performed from scratch."
584- )
585- raw_cram_file .unlink (missing_ok = True )
586- raw_cram_file .with_suffix (".cram.crai" ).unlink (missing_ok = True )
587- except AssertionError :
508+ census_json_files = list (
509+ self .meteor .fastq_dir .glob ("*_census_stage_0.json" )
510+ )
511+ if len (census_json_files ) == 0 :
588512 logging .error (
589513 "No *_census_stage_0.json file found in %s" ,
590514 self .meteor .fastq_dir ,
591515 )
592516 sys .exit (1 )
517+
518+ # mapping of each sample against reference
519+ for library in census_json_files :
520+ census_json = self .read_json (library )
521+ sample_name = census_json ["sample_info" ]["sample_name" ]
522+ stage1_dir = self .meteor .mapping_dir / sample_name
523+ stage1_dir .mkdir (exist_ok = True , parents = True )
524+ stage1_json = (
525+ self .meteor .mapping_dir
526+ / sample_name
527+ / f"{ sample_name } _census_stage_1.json"
528+ )
529+ self .json_data [library ] = {
530+ "census" : census_json ,
531+ "directory" : stage1_dir ,
532+ "Stage1FileName" : stage1_json ,
533+ "reference" : ref_json ,
534+ }
535+ if not stage1_json .exists ():
536+ mapping_done = False
537+ # mapping already done and no overwriting
538+ if mapping_done :
539+ logging .info (
540+ "Mapping already done for sample: %s" ,
541+ sample_name ,
542+ )
543+ logging .info ("Skipped !" )
593544 else :
594- # Not sure if it's a good idea to delete a temporary file
595- rmtree (self .meteor .tmp_dir , ignore_errors = True )
545+ logging .info ("Launch mapping" )
546+ self .launch_mapping ()
547+ # running counter
548+ stage1_json_data = self .read_json (stage1_json )
549+ raw_cram_file = (stage1_dir /
550+ stage1_json_data ["mapping" ]["mapping_file" ]
551+ )
552+ cram_file = (
553+ stage1_dir
554+ / f"{ sample_name } .cram"
555+ )
556+ count_file = (
557+ stage1_dir
558+ / f"{ sample_name } .tsv.xz"
559+ )
560+ start = perf_counter ()
561+ self .launch_counting (
562+ raw_cram_file ,
563+ cram_file ,
564+ count_file ,
565+ ref_json ,
566+ stage1_json_data ,
567+ stage1_json ,
568+ )
569+ # Add final mapping rate
570+ stage1_json_data = self .read_json (stage1_json )
571+ stage1_json_data ["counting" ]["final_mapping_rate" ] = (
572+ round (
573+ stage1_json_data ["counting" ]["counted_reads" ]
574+ / stage1_json_data ["mapping" ]["total_read_count" ]
575+ * 100 ,
576+ 2
577+ )
578+ )
579+ self .save_config (
580+ stage1_json_data ,
581+ stage1_json
582+ )
583+ logging .info ("Completed counting in %f seconds" , perf_counter () - start )
584+ if not self .keep_all_alignments :
585+ logging .info (
586+ "Raw cram file is not kept (--ka). "
587+ "Re-counting operation will need to be performed from scratch."
588+ )
589+ raw_cram_file .unlink (missing_ok = True )
590+ raw_cram_file .with_suffix (".cram.crai" ).unlink (missing_ok = True )
591+
592+ # Not sure if it's a good idea to delete a temporary file
593+ rmtree (self .meteor .tmp_dir , ignore_errors = True )
0 commit comments