[Bio] / Kmers2 / mk-partition.pl Repository:
ViewVC logotype

View of /Kmers2/mk-partition.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Wed Feb 13 20:42:16 2013 UTC (6 years, 8 months ago) by olson
Branch: MAIN
CVS Tags: HEAD
Kmer / partition creation code.

use strict;
use File::Copy;

=head1 NAME

mk-partition

=head1 SYNOPSIS

mk-partition [dna|protein] partition-dir definition-file [definition-file ...]

=head1 DESCRIPTION

Create a partition directory in C<partition-dir>. 

Creates a file tag.index that contains the tags from the first line of the 
list of C<definition-file>s. 

Create directories set.N where N corresponds to the tag indices.

Into set.N put the definition file.

=cut

@ARGV >= 3 or die "Usage: mk-partition [dna|protein] partition-dir def-file [def-file...]\h";

my $type = shift;
my $dir = shift;
my @defs = @ARGV;

-d $dir and die "Partition dir $dir already exists\n";

mkdir($dir) or die "Cannot mkdir $dir: $!";

open(F, ">", "$dir/type") or die "Cannot write $dir/type: $!";
print F "$type\n";
close(F);

open(I, ">", "$dir/tag.index") or die "Cannot write $dir/tag.index: $!";

my $id = 1;
for my $def (@ARGV)
{
    my $p = "$dir/set.$id";
    mkdir($p) or die "Cannot mkdir $p: $!";
    
    open(DOUT, ">", "$p/definition") or die "Cannot create $p/definition: $!";

    open(D, "<", $def) or die "Cannot open $def: $!";
    my $tag = <D>;
    chomp $tag;
    print I "$id\t$tag\n";
    
    print DOUT "$tag\n";

    while (<D>)
    {
	chomp;
	if (! -f $_)
	{
	    die "File $_ from $def does not exist\n";
	}
	print DOUT "$_\n";
    }
    close(D);
    close(DOUT);
    
    $id++;
}
close(I);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3