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

Annotation of /FigMetagenomeTools/randomize_fasta.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (view) (download) (as text)

1 : olson 1.1 #!/usr/bin/perl -w
2 :    
3 :     # randomize a fasta file (and optionally a quality file)
4 :    
5 :     use strict;
6 :     use Rob;
7 :    
8 :     my $usage=<<EOF;
9 :     $0
10 :     -f fasta file
11 :     -q quality file (optional)
12 :     -o output file (default = fasta file.rand)
13 :     EOF
14 :    
15 :     my ($faf, $qaf, $oaf);
16 :     while (@ARGV) {
17 :     my $t=shift;
18 :     if ($t eq "-f") {$faf=shift}
19 :     if ($t eq "-q") {$qaf=shift}
20 :     if ($t eq "-o") {$oaf=shift}
21 :     }
22 :    
23 :     die $usage unless ($faf);
24 :     $oaf = $faf.".rand" unless ($oaf);
25 :    
26 :     my $fa=Rob->read_fasta($faf);
27 :     my $qual;
28 :     if ($qaf) {$qual=Rob->read_fasta($qaf, 1)} else {print STDERR "No quality file defined, just randomizing $faf\n"}
29 :    
30 :    
31 :     open(FA, ">$oaf") || die "Can't open $oaf for writing\n";
32 :     if ($qaf) {open(QU, ">$oaf.qual") || die "Can't open $oaf.qual for writing\n"}
33 :     my $allkeys=Rob->rand([keys %$fa]);
34 :     print STDERR "Writing ", scalar(@$allkeys), " sequences\n";
35 :     foreach my $key (@$allkeys)
36 :     {
37 :     $fa->{$key}=~ s/\s+//g;
38 :     print FA ">$key\n",$fa->{$key},"\n";
39 :     if ($qaf) {
40 :     if ($qual->{$key}) {
41 :     print QU ">$key\n", $qual->{$key}, "\n";
42 :     }
43 :     }
44 :     }
45 :    
46 :     print STDERR "DOne in ", $^T-time, " seconds\n";
47 :    
48 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3