File: split_seqs_2.pl

package info (click to toggle)
wtdbg2 2.5-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 119,728 kB
  • sloc: ansic: 27,655; perl: 1,212; makefile: 125; sh: 83
file content (40 lines) | stat: -rwxr-xr-x 650 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/perl -w
#
#
use strict;

my $cnt = shift or die("Usage: $0 <n_files> <fasta_file> [gzip:0]\n");
my $inf = shift or die("Usage: $0 <n_files> <fasta_file> [gzip:0]\n");
my $zip = shift || 0;
$zip = 0 unless($zip eq '1' or $zip eq 'y');
my $ouf = $inf;
if($ouf eq '-'){
	$ouf = 'unnamed';
} else {
	unshift @ARGV, $inf;
}

my @fhs = ();

for(my $i=1;$i<=$cnt;$i++){
	my $fh;
	if($zip){
		open($fh, "| gzip -c >$ouf.shuffle$i.gz") or die;
	} else {
		open($fh, ">", "$ouf.shuffle$i") or die;
	}
	push(@fhs, $fh);
}

my $n = -1;
while(<>){
	$n ++ if(/^>/);
	my $fh = $fhs[$n % $cnt];
	print $fh $_;
}

foreach my $fh (@fhs) {
	close $fh;
}

1;