| Revision 174,
1.0 KB
checked in by admin, 6 years ago
(diff) |
|
|
-
Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 | #! /usr/bin/perl -w |
|---|
| 2 | # Copyright (2005) Reed A. Cartwright. All rights reserved. |
|---|
| 3 | # |
|---|
| 4 | # outsplit.pl is used to extract sequences from Fasta and Phylip files |
|---|
| 5 | # |
|---|
| 6 | # usage: perl -w outsplit.pl <file> <id> |
|---|
| 7 | # |
|---|
| 8 | # if <id> is "all" it it creates a directory and |
|---|
| 9 | # creates a new file for each alignment |
|---|
| 10 | # |
|---|
| 11 | # Distributed under the same license as DAWG |
|---|
| 12 | # |
|---|
| 13 | |
|---|
| 14 | use strict; |
|---|
| 15 | use File::Basename; |
|---|
| 16 | use File::Path; |
|---|
| 17 | use File::Spec::Functions; |
|---|
| 18 | |
|---|
| 19 | my ($file, $id) = @ARGV; |
|---|
| 20 | |
|---|
| 21 | local $/; |
|---|
| 22 | |
|---|
| 23 | open( FILE, $file) or die("Error opening $file."); |
|---|
| 24 | |
|---|
| 25 | my $text = <FILE>; |
|---|
| 26 | |
|---|
| 27 | close(FILE); |
|---|
| 28 | |
|---|
| 29 | my @blocks = split(/\[DataSet \d+\].*\n/, $text); |
|---|
| 30 | |
|---|
| 31 | if($id ne 'all') |
|---|
| 32 | { |
|---|
| 33 | print $blocks[$id]; |
|---|
| 34 | } |
|---|
| 35 | else |
|---|
| 36 | { |
|---|
| 37 | my ($name,$dir,$ext) = fileparse($file, qr{\..*}); |
|---|
| 38 | my $outdir = catdir($dir, $name); |
|---|
| 39 | print "Creating directory $outdir\n"; |
|---|
| 40 | mkpath($outdir) unless (-d $outdir); |
|---|
| 41 | chdir($outdir) or die("Unable to change directory."); |
|---|
| 42 | |
|---|
| 43 | foreach my $i (1..$#blocks) |
|---|
| 44 | { |
|---|
| 45 | my $out = "${name}_$i$ext"; |
|---|
| 46 | print "Creating file $out\n"; |
|---|
| 47 | open(OUT, ">$out") or die("Unable to open file."); |
|---|
| 48 | print OUT $blocks[0]; |
|---|
| 49 | print OUT $blocks[$i]; |
|---|
| 50 | close(OUT); |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.