use strict; use warnings; use Getopt::Long; use Bio::SeqIO; ### perl /home/xiangyang/Chen_genome/perl_bin/extract_rRNA_dir.pl /home/xiangyang/Chen_genome/chen_gbk my $path=$ARGV[0]; # my $filename=getcwd $path; opendir DIR, $path or die $!; my @dir = readdir DIR; closedir DIR; foreach my $file(@dir){ my $input="$path/$file"; mkdir "$path/rRNA/"; my $output="$path/rRNA/$file.fasta"; open(OUTPUT, ">$output"); ####################################################################################### my %options = ( cdsCount => 0, ); ####################################################################################### my $in = new Bio::SeqIO( -file => $input, -format => 'genbank' ); my $out = new Bio::SeqIO( -file => $output , -format => 'fasta' ); my @dna=(); my $label_3; my %hash_0; my $i=0; while ( my $seqObject = $in->next_seq() ) { my @features = $seqObject->get_SeqFeatures(); #--------------------------------------------------------------------------------------------display organism name for each CDS my $org = ""; foreach (@features) { my $feat = $_; my @ar; if ($feat->primary_tag() eq "source"){ @ar = $feat->get_tag_values('organism'); $org = $ar[0]; next; } #---------------------------------------------------------------------------------------------xiangyang li addition 2013-01-25 my $type = $feat->primary_tag; unless ( $type eq "rRNA") { next; } my @label = (); my @tag=(); if ( $feat->has_tag('locus_tag') ) { push( @label, join( ",", $feat->get_tag_values('locus_tag') ) ); } if ( $feat->has_tag('product') ) { push (@tag, join(",",$feat->get_tag_values('product'))); push (@label, join(",",$feat->get_tag_values('product'))); } push (@label, join(",","[".$file."]")); ###xiangyang li addition 2013-01-25 my $label = join( ";", @label ); my $label_2=join(";",@tag); $label =~ s/\s+/_/g; $label =~ s/\n//g; $label =~ s/\t+/ /g; if ($label_2 eq "16S ribosomal RNA") { $i++; print "$label\n"; my $dna = $feat->spliced_seq->seq; $dna=$i."_".$dna; $hash_0{$dna}=$label; print "$dna\n"; push @dna,$dna; $options{cdsCount}++; } } # corrsponding to Line 37 } # corrsponding to Line 33 my $max=length $dna[0]; foreach (@dna) {if ($max<=length $_){$max=length $_;}} $max=$max-2; my %hash; foreach (@dna) {$hash {length $_}=$_;} my @number = sort{$b <=> $a} (keys %hash); my $sequence = $hash {$number[0]}; $label_3=$max."---".$hash_0{$sequence}; $sequence=~s/(.+)_//g; print OUTPUT ">$label_3\n$sequence\n"; print "A total of $options{cdsCount} records were written to $file.\n"; } # corrsponding to Line 15