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

Annotation of /FigMetagenomeTools/renumber_based_on_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 :     # renumber some sequences based on what is in the fasta file. We have renumbered the 454 sequences, and then lost them all in a harddrive failure
4 :     # but I have the fa (just not the qual files)
5 :    
6 :     use Rob;
7 :    
8 :     my $rob=new Rob;
9 :    
10 :     my $usage=<<EOF;
11 :     $0
12 :     -f new fasta file
13 :     -o original fasta file
14 :     -q original quality file
15 :     -x fasta ouptut file
16 :     -y quality output file
17 :    
18 :     EOF
19 :    
20 :     my ($fa, $of, $qf, $qo, $fo);
21 :     while (@ARGV)
22 :     {
23 :     my $t=shift;
24 :     if ($t eq "-f") {$fa=shift}
25 :     elsif ($t eq "-o") {$of=shift}
26 :     elsif ($t eq "-q") {$qf=shift}
27 :     elsif ($t eq "-y") {$qo=shift}
28 :     elsif ($t eq "-x") {$fo=shift}
29 :     }
30 :     die $usage unless ($fa && $of && $qf && $qo && $fo);
31 :     my $fasta=$rob->read_fasta($fa);
32 :     my $seq;
33 :     map {$fasta->{$_}=~s/\s+//g; $fasta->{$_}=uc($fasta->{$_}); $seq->{$fasta->{$_}}=$_} keys %$fasta;
34 :    
35 :     my $orifa=$rob->read_fasta($of);
36 :     my $oriqf=$rob->read_fasta($qf, 1);
37 :    
38 :    
39 :     open(FA, ">$fo") || die "Can't open $fo for writing";
40 :     open(QU, ">$qo") || die "Can't open $qo for writing";
41 :    
42 :     my %seen; my $skip; my $kept;
43 :     map
44 :     {
45 :     if ($seen{$orifa->{$_}}) {$skip++}
46 :     else
47 :     {
48 :     $seen{$orifa->{$_}}=1;
49 :     $orifa->{$_}=~s/\s+//g;
50 :     $orifa->{$_}=uc($orifa->{$_});
51 :     $kept++;
52 :     if ($seq->{$orifa->{$_}})
53 :     {
54 :     print FA ">", $seq->{$orifa->{$_}}, "\n", $orifa->{$_}, "\n";
55 :     print QU ">", $seq->{$orifa->{$_}}, "\n", $oriqf->{$_}, "\n";
56 :     }
57 :     else
58 :     {
59 :     print STDERR "$_ not found!\n";
60 :     }
61 :     }
62 :     } keys %$orifa;
63 :    
64 :    
65 :    
66 :     print STDERR "$kept sequences were kept (seen was: ", scalar(keys %seen), " and $skip sequences were ignored\n";
67 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3