加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl 多线程及信号控制

发布时间:2020-12-15 23:47:51 所属栏目:大数据 来源:网络整理
导读:#!/usr/bin/perluse strict;use warnings;use threads;use Thread::Semaphore;my $max_thread = 5;my $semaphore = Thread::Semaphore-new($max_thread);sub TestFun{$semaphore-up();}for(my $index = 1; $index = 10; $index ++){$semaphore-down();my $th
#!/usr/bin/perl
use strict;
use warnings;
use threads;
use Thread::Semaphore;

my $max_thread = 5;
my $semaphore = Thread::Semaphore->new($max_thread);

sub TestFun
{
	$semaphore->up();
}

for(my $index = 1; $index <= 10; $index ++)
{
	$semaphore->down();
	my $thread = threads->create(&;TestFun);
	$thread->detach();
}

WaitQuit();

<pre name="code" class="plain">sub WaitQuit
{
	my $num = 0;
	while($num < $max_thread)
	{
		$semaphore->down();
		$num ++;
	}
}
 


#!perl
use warnings;
use strict;
use threads;
use Thread::Semaphore;

die "perl $0 <thread> <blastConfig> <pep || dna>
perl $0 3 blast.config dnan" if @ARGV != 3;

my $max_thread = $ARGV[0];
my $semaphore = Thread::Semaphore->new($max_thread);

mkdir "compliantFasta";
chdir "compliantFasta";

open FA,"../$ARGV[1]" or die $!;
while(<FA>)
{
	chomp;
	my @tmp = split;

	$semaphore->down();
	my $thread = threads->create(&;adjust,$tmp[0],$tmp[1]);
	$thread->detach();
}

&wait;

chdir "..";
my $len = 0;
my ($type,$p);
if($ARGV[2] =~ /dna/i)
{
	$len = 30;
	$type = "F";
	$p = "blastn";
}elsif($ARGV[2] =~ /pep/i){
	$len = 10;
	$type = "T";
	$p = "blastp";
}

`orthomclFilterFasta compliantFasta $len 20`;
`formatdb -i goodProteins.fasta -p $type`;
mkdir "splitBlast";
`perl split_fasta.pl goodProteins.fasta 8 splitBlast/blast`;
my @blast = `ls splitBlast/*`;
my $sp2 = Thread::Semaphore->new(8);
foreach my $i(@blast)
{
	chomp($i);
	$sp2->down();
	my $thread = threads->create(&;blast,$i,$p,$ARGV[0]);
	$thread->detach();
}

&wait2;

`cat splitBlast/*.out > all.blast`;
`orthomclBlastParser all.blast compliantFasta > similarSequences.txt`;
`rm all.blast -rf`;

sub blast
{
	my ($f,$t,$p) = @_;
	`blastall -p $t -i $f -d goodProteins.fasta -m 8 -F F -b 1000 -v 1000 -a $p -o $f.out`;
	$sp2->up();
}

sub wait2
{
	my $num = 0;
	while($num < 8)
	{
		$sp2->down();
		$num ++;
	}
}

sub adjust
{
	my ($label,$path) = @_;
	`orthomclAdjustFasta $label $path 1`;
	$semaphore->up();
}

sub wait
{
	my $num = 0;
	while($num < $max_thread)
	{
		$semaphore->down();
		$num ++;
	}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读