my $multi_cpu_num = 13; my @ciona_pwm_array = getCionaPWM(); my $output_temp = 'temp.ciona.temp'; my $output_temp_handle = FileHandle->new(">output_temp"); my $output_handle = FileHandle->new(">ciona.matrix.result"); my $result_buffer = undef; foreach my $id (1..100) { my $seq_1 = 'gatctatcgtagcagcta'; my $seq_2 = 'agtctacatgctacgatg'; my $pm = Parallel::ForkManager->new( $multi_cpu_num ); PWM: for my $pwm (@ciona_pwm_array) { $pm->start and next PWM; my $count = count_pwm_num($pwm,$seq_1,$seq_2); if($count != 0) { $output_temp_handle->print($id); $output_temp_handle->print("\t$pwm\t1\n"); } else { $output_temp_handle->print($id); $output_temp_handle->print("\t$pwm\t0\n"); } $pm->finish; } $pm->wait_all_children; } $output_temp_handle->close; # catch the Parallel::ForkManager output # the temporary output looks like that # a A 1 # b B 0 # c C 1 # a B 1 # in real code , I used 1, 2,3, instead of a, b, c ,d. my $reopen_handle = FileHandle->new($output_temp); while(my $line = $reopen_handle->getline) { chomp $line; my @buffer = split/\t/,$line; $result_buffer->{$buffer[0]}->{$buffer[1]} = $buffer[2]; } $reopen_handle->close; unlink 'temp.ciona.temp'; # print output_header_information :row 1 in program result table; $output_handle->print("id"); foreach my $pwm (@ciona_pwm_array) { $output_handle->print("\t$pwm"); } $output_handle->print("\n"); # print the content of program result table foreach my $id (1..100}) { $output_handle->print("$id"); foreach my $pwm (@ciona_pwm_array) { my $count = $result_buffer->{$id}->{$pwm}; $output_handle->print("\t$count"); } $output_handle->print("\n"); } $output_handle->close; sub ciona_pwm_num {} sub getCionaPWM {] exit(0);