55from multiprocessing import Pool
66from rich .text import Text
77from rich_argparse import RichHelpFormatter
8- from ProtPeptigram .logger import CONSOLE
8+ from ProtPeptigram .logger import CONSOLE as console
99from ProtPeptigram import __author__ , __version__
1010from ProtPeptigram .runner import run_pipeline
1111
@@ -22,7 +22,7 @@ def _welcome():
2222 /_/ /____/
2323 """
2424
25- CONSOLE .print (tool_icon , style = "blue" )
25+ console .print (tool_icon , style = "blue" )
2626
2727
2828
@@ -69,7 +69,7 @@ def _print_credits(credits=False):
6969 text .append ("\n " )
7070 if credits :
7171 text .stylize ("#006cb5" )
72- CONSOLE .print (text )
72+ console .print (text )
7373
7474
7575def main ():
@@ -138,6 +138,14 @@ def main():
138138 help = "fasta file containing protein sequences"
139139 )
140140
141+ parser .add_argument (
142+ "-t" ,
143+ "--threads" ,
144+ type = int ,
145+ default = 1 ,
146+ help = "Number of threads to use for processing (default: 1)"
147+ )
148+
141149 parser .add_argument (
142150 "-v" ,
143151 "--version" ,
@@ -158,16 +166,39 @@ def main():
158166 sys .exit (0 )
159167
160168 if args .input and args .fasta :
161- run_pipeline (
162- csv_path = args .input ,
163- fasta_path = args .fasta ,
164- output_dir = args .output ,
165- top = args .top ,
166- protein_list = args .protein_list ,
167- regex_pattern = args .regex ,
168- intensity_threshold = args .threshold ,
169- min_samples = args .min_samples
170- )
169+ if args .threads > 1 :
170+ console .log (
171+ f"Using { args .threads } threads for processing." ,
172+ style = "bold green"
173+ )
174+ with Pool (processes = args .threads ) as pool :
175+ pool .apply_async (
176+ run_pipeline ,
177+ args = (
178+ args .input ,
179+ args .fasta ,
180+ args .output ,
181+ args .top ,
182+ args .protein_list ,
183+ args .regex ,
184+ args .threshold ,
185+ args .min_samples
186+ )
187+ )
188+ pool .close ()
189+ pool .join ()
190+ else :
191+ console .log ("Running in single-threaded mode." , style = "bold yellow" )
192+ run_pipeline (
193+ args .input ,
194+ args .fasta ,
195+ args .output ,
196+ args .top ,
197+ args .protein_list ,
198+ args .regex ,
199+ args .threshold ,
200+ args .min_samples
201+ )
171202 else :
172203 parser .error ("Both input CSV file (-i/--input) and FASTA file (-f/--fasta) are required." )
173204
0 commit comments