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

Annotation of /FigMetagenomeTools/rename_fa_qual.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 :     # rename the sequences in a fasta file and a quality file begining with 1.
4 :    
5 :     use strict;
6 :     use Rob;
7 :    
8 :     my $usage=<<EOF;
9 :     $0 <options>
10 :     -f fasta file
11 :     -q quality file (can be ommitted if it is -f.qual)
12 :     -s start at (default=1)
13 :     -d destination fasta file (default = -f.renamed). Quality file is named from this
14 :    
15 :     EOF
16 :    
17 :     my ($faf, $qaf, $daf, $start)=('','','',1);
18 :     while (@ARGV) {
19 :     my $t=shift;
20 :     if ($t eq "-f") {$faf=shift}
21 :     elsif ($t eq "-q") {$qaf = shift}
22 :     elsif ($t eq "-s") {$start = shift}
23 :     elsif ($t eq "-d") {$daf=shift}
24 :     }
25 :    
26 :     die $usage unless ($faf);
27 :     $qaf = $faf.".qual" unless ($qaf);
28 :     $daf = $faf.".renamed" unless ($daf);
29 :    
30 :     die "Fasta file $faf not found" unless (-e $faf);
31 :     die "Quality file $qaf not found" unless (-e $qaf);
32 :    
33 :    
34 :     my $seqs=Rob->read_fasta($faf);
35 :     my $qual=Rob->read_fasta($qaf, 1);
36 :    
37 :     open(FA, ">$daf") || die "Can't open $daf for writing";
38 :     open(QU, ">$daf.qual") || die "Can't open $daf.qual for writing";
39 :    
40 :    
41 :     foreach my $id (keys %$seqs) {
42 :     if ($qual->{$id}) {
43 :     $seqs->{$id}=~s/\s+//g;
44 :     print FA ">$start\n", $seqs->{$id}, "\n";
45 :     print QU ">$start\n", $qual->{$id}, "\n";
46 :     $start++;
47 :     }
48 :     else {
49 :     print STDERR "No qualitites for $id. Skipped\n";
50 :     }
51 :     }
52 :    
53 :     foreach my $id (keys %$qual) {
54 :     print STDERR "No fasta for quality $id\n" unless ($seqs->{$id});
55 :     }
56 :    
57 :     print STDERR "$start sequences were renamed\n";
58 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3