[Bio] / FigMetagenomeTools / randomize_fasta.pl Repository:
ViewVC logotype

View of /FigMetagenomeTools/randomize_fasta.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Mon Feb 19 17:15:26 2007 UTC (13 years, 1 month ago) by olson
Branch: MAIN
Branch point for: x
Initial revision

#!/usr/bin/perl -w

# randomize a fasta file (and optionally a quality file)

use strict;
use lib '/clusterfs//home/rob/perl';
use Rob;

my $usage=<<EOF;
$0 
-f fasta file
-q quality file (optional)
-o output file (default = fasta file.rand)
EOF

my ($faf, $qaf, $oaf);
while (@ARGV) {
 my $t=shift;
 if ($t eq "-f") {$faf=shift}
 if ($t eq "-q") {$qaf=shift}
 if ($t eq "-o") {$oaf=shift}
}

die $usage unless ($faf);
$oaf = $faf.".rand" unless ($oaf);

my $fa=Rob->read_fasta($faf);
my $qual;
if ($qaf) {$qual=Rob->read_fasta($qaf, 1)} else {print STDERR "No quality file defined, just randomizing $faf\n"}


open(FA, ">$oaf") || die "Can't open $oaf for writing\n";
if ($qaf) {open(QU, ">$oaf.qual") || die "Can't open $oaf.qual for writing\n"}
my $allkeys=Rob->rand([keys %$fa]);
print STDERR "Writing ", scalar(@$allkeys), " sequences\n";
foreach my $key (@$allkeys)
{
 $fa->{$key}=~ s/\s+//g;
 print FA ">$key\n",$fa->{$key},"\n";
 if ($qaf) {
  if ($qual->{$key}) {
   print QU ">$key\n", $qual->{$key}, "\n";
  }
 }
}

print STDERR "DOne in ", $^T-time, " seconds\n";
 
 

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3