#!perl
use warnings;
#use strict;
use threads;
use Thread::Semaphore;
use File::Basename qw(basename);
die "perl $0 <bam> <threads>\n" if @ARGV != 2;
my $semaphore = Thread::Semaphore->new($ARGV[1]);
my $id = basename($ARGV[0], ".bam");
if(-s "$ARGV[0].bai")
{
}else{
`samtools index $ARGV[0]`;
}
my $outdir = "${id}_split";
mkdir $outdir;
my (%hash, $hd, $rg, $pg);
open HEAD, "samtools view -H $ARGV[0] |" or die $!;
while(<HEAD>)
{
if(/^\@SQ/)
{
my ($chr) = $_ =~ /SN:(\S+)/;
$hash{$chr} = $_;
next;
}
if(/^\@HD/)
{
$hd .= "$_";
next;
}
if(/^\@RG/)
{
$rg .= "$_";
next;
}
if(/^\@PG/)
{
$pg .= "$_";
next;
}
}
foreach(keys %hash)
{
$semaphore->down();
my $thread = threads->create(\&splitchr, $_);
$thread->detach();
}
&waitDone;
sub waitDone{
多线程拆分bam文件
最新推荐文章于 2024-09-22 07:09:05 发布
本文介绍如何在内存充足的集群环境中,通过多线程技术有效地拆分大型BAM文件,提高生物信息分析的效率。
摘要由CSDN通过智能技术生成