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

Annotation of /FigMetagenomeTools/randomize_fasta.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3