-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathoutsplit.pl
More file actions
52 lines (43 loc) · 1.05 KB
/
outsplit.pl
File metadata and controls
52 lines (43 loc) · 1.05 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
#! /usr/bin/perl -w
# Copyright (2005) Reed A. Cartwright. All rights reserved.
#
# outsplit.pl is used to extract sequences from Fasta and Phylip files
#
# usage: perl -w outsplit.pl <file> <id>
#
# if <id> is "all" it it creates a directory and
# creates a new file for each alignment
#
# Distributed under the same license as DAWG
#
use strict;
use File::Basename;
use File::Path;
use File::Spec::Functions;
my ($file, $id) = @ARGV;
local $/;
open( FILE, $file) or die("Error opening $file.");
my $text = <FILE>;
close(FILE);
my @blocks = split(/\[DataSet \d+\].*\n/, $text);
if($id ne 'all')
{
print $blocks[$id];
}
else
{
my ($name,$dir,$ext) = fileparse($file, qr{\..*});
my $outdir = catdir($dir, $name);
print "Creating directory $outdir\n";
mkpath($outdir) unless (-d $outdir);
chdir($outdir) or die("Unable to change directory.");
foreach my $i (1..$#blocks)
{
my $out = "${name}_$i$ext";
print "Creating file $out\n";
open(OUT, ">$out") or die("Unable to open file.");
print OUT $blocks[0];
print OUT $blocks[$i];
close(OUT);
}
}