Bio-WGS2NCBI

 view release on metacpan or  search on metacpan

lib/Bio/WGS2NCBI.pm  view on Meta::CPAN

	my $INDIR  = $config->datadir;
	
	# iterate over files in folder, read FASTA files
	opendir my $dh, $INDIR or die $!;
	while( my $file = readdir $dh ) {
		
		# have a FASTA file
		if ( $file =~ /(.+)\.fsa$/ ) {
			my $stem = $1;
		
			# make backup of FASTA file
			rename "${INDIR}/${file}", "${INDIR}/${file}.bak";
			
			# read file, look op non-missing residue positions, write truncated
			open my $fh,  '<', "${INDIR}/${file}.bak" or die $!;
			open my $out, '>', "${INDIR}/${file}"     or die $!;
			my ( $pos, $seq, %coord );
			while( not eof($fh) ) {
				( $pos, $seq ) = Bio::WGS2NCBI::Seq->read_fasta( $fh, $pos );
				my $id = $seq->id;
				my $i1 = $seq->get_non_missing_index;
				my $i2 = $seq->get_non_missing_index(1);
				INFO "$id\t$i1 .. $i2";
				$coord{$id} = [ $i1, $i2  ];
				$seq->trunc( $i1 + 1, $i2 + 1 )->write_fasta($out);	
			}
			
			# make backup of TBL file, open handle for writing		
			rename "${INDIR}/${stem}.tbl", "${INDIR}/${stem}.tbl.bak";
			open my $outtbl, '>', "${INDIR}/${stem}.tbl" or die $!;
			
			# initialize variables
			my $tr = Bio::WGS2NCBI::TableReader->new( 
				'-file' => "${INDIR}/${stem}.tbl.bak",
				'-cb'   => sub {
					my $id = shift;
					print $outtbl '>Features ', $id, "\n";
				}



( run in 0.526 second using v1.01-cache-2.11-cpan-49f99fa48dc )