@@ -729,69 +729,3 @@ def merge_xmfas(
729
729
xmfa_out_handle .write (tx .read ())
730
730
731
731
732
- if __name__ == "__main__" :
733
- args = parse_args ()
734
- os .makedirs (args .output_dir , exist_ok = True )
735
-
736
- query_files = list ()
737
- for arg_path in args .sequences :
738
- if arg_path .endswith (".txt" ):
739
- with open (arg_path ) as input_list_handle :
740
- for line in input_list_handle :
741
- query_files .append (line .strip ())
742
- elif any (arg_path .endswith (suff ) for suff in FASTA_SUFFIX_LIST ):
743
- query_files .append (arg_path )
744
- elif os .path .isdir (arg_path ):
745
- for f in os .listdir (arg_path ):
746
- if any (f .endswith (suff ) for suff in FASTA_SUFFIX_LIST ):
747
- query_files .append (f"{ arg_path } /{ f } " )
748
-
749
- full_query_list_path = f"{ args .output_dir } /input-list.txt"
750
- with open (full_query_list_path , 'w' ) as input_list_handle :
751
- for qf in query_files :
752
- input_list_handle .write (qf + "\n " )
753
-
754
- partition_output_dir = f"{ args .output_dir } /partition"
755
- partition_list_dir = f"{ partition_output_dir } /input-lists"
756
- os .makedirs (partition_list_dir , exist_ok = True )
757
- run_command (f"split -l { args .partition_size } -a 5 --additional-suffix '.txt' { full_query_list_path } { partition_list_dir } /{ CHUNK_PREFIX } -" )
758
-
759
- chunk_label_parser = re .compile (f'{ CHUNK_PREFIX } -(.*).txt' )
760
- chunk_labels = []
761
- for partition_list_file in os .listdir (partition_list_dir ):
762
- chunk_labels .append (chunk_label_parser .search (partition_list_file ).groups ()[0 ])
763
-
764
- parsnp_commands = []
765
- for cl in chunk_labels :
766
- chunk_output_dir = f"{ partition_output_dir } /{ CHUNK_PREFIX } -{ cl } -out"
767
- os .makedirs (chunk_output_dir , exist_ok = True )
768
- chunk_command = f"./parsnp -d { partition_list_dir } /{ CHUNK_PREFIX } -{ cl } .txt -r { args .reference } -o { chunk_output_dir } "
769
- chunk_command += args .parsnp_flags
770
- chunk_command += f" > { chunk_output_dir } /parsnp.stdout 2> { chunk_output_dir } /parsnp.stderr"
771
- parsnp_commands .append (chunk_command )
772
-
773
- good_chunks = set (chunk_labels )
774
- run_command_nocheck = partial (run_command , check = False )
775
- with Pool (args .threads ) as pool :
776
- return_codes = tqdm (pool .imap (run_command_nocheck , parsnp_commands , chunksize = 1 ), total = len (parsnp_commands ))
777
- for cl , rc in zip (chunk_labels , return_codes ):
778
- if rc != 0 :
779
- logger .error ("Partition {cl} failed..." )
780
- good_chunks .remove (cl )
781
-
782
- chunk_labels = list (good_chunks )
783
-
784
- logger .info ("Computing intersection of all partition LCBs..." )
785
- chunk_to_intvervaldict = get_chunked_intervals (partition_output_dir , chunk_labels )
786
- intersected_interval_dict = get_intersected_intervals (chunk_to_intvervaldict )
787
-
788
- logger .info ("Trimming partitioned XMFAs back to intersected intervals..." )
789
- num_clusters = trim_xmfas (partition_output_dir , chunk_labels , intersected_interval_dict , args .threads )
790
-
791
- os .makedirs (f"{ args .output_dir } /merged-out/" , exist_ok = True )
792
- xmfa_out_f = f"{ args .output_dir } /merged-out/parsnp.xmfa"
793
-
794
- logger .info (f"Merging trimmed XMFA files into a single XMFA at { xmfa_out_f } " )
795
- merge_xmfas (partition_output_dir , chunk_labels , xmfa_out_f , num_clusters , args .threads )
796
-
797
-
0 commit comments