Bio-WGS2NCBI

 view release on metacpan or  search on metacpan

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

			}
		}
		if ( / \Q$auth\E($prefix\d+)/ ) {
			my $id = $1;
			INFO "Going to prune annotations identified by $id";
			$objects{$id}++;
		}
	}
	
	# start reading feature tables
	opendir my $dh, $datadir or die $!;
	while( my $entry = readdir $dh ) {
		if ( $entry =~ /\.tbl$/ ) {
		
			# make pruned copy
			INFO "Going to start writing to $datadir/$entry.pruned";
			open my $fh, '>', "$datadir/$entry.pruned" or die $!;
		
			# instantiate reader and start scanning
			INFO "Going to start reading $datadir/$entry";
			my $read = Bio::WGS2NCBI::TableReader->new(  
				'-file' => "$datadir/$entry",
				'-cb'   => sub { print $fh ">Features @_\n" }
			);
			
			# iterate over features, write out with sequence separators
			my $seq = '';
			FEAT: while( my $feat = $read->next_feature ) {
				
				# scan all the ranges
				$seq = $read->seq;
				if ( $locations{$seq} ) {
					for my $loc ( @{ $locations{$seq} } ) {
						if ( $feat->lies_within(@$loc) ) {
							WARN "Pruning from location $seq:".$loc->[0].'-'.$loc->[1];
							next FEAT;
						}
					}				
				}
				
				# check object ids
				if ( $feat->can('locus_tag') and $objects{$feat->locus_tag} ) {
					WARN "Pruning $feat ".$feat->locus_tag;
					next FEAT;
				}
				if ( $feat->can('protein_id') and $objects{$auth . $feat->protein_id} ) {
					WARN "Pruning $feat ".$feat->protein_id;
					next FEAT;
				}
				
				# still here? then print the feature
				print $fh $feat->to_string;
			}
		}	
	}	
}

=head1 compress

The C<compress> action bundles the ASN.1 files produced by C<Bio::WGS2NCBI/convert> into
a .tar.gz archive that can be uploaded to NCBI. This requires the following configuration 
settings:

=over

=item C<outdir>

The location where the ASN.1 files were written.

=item C<archive>

The name and location of the archive to produce.

=back

=cut

sub compress {
	my $config  = Bio::WGS2NCBI::Config->new;
	my $tar     = Archive::Tar->new;
	my $sqndir  = $config->outdir;
	my $archive = $config->archive;
	
	# open directory handle
	INFO "going to add *.sqn files from $sqndir to $archive";
	opendir my $dh, $sqndir or die $!;
	
	# iterate over files
	my $counter;
	while( my $entry = readdir $dh ) {
		if ( $entry =~ /\.sqn$/ ) {
			$counter++;
			$tar->add_files( "${sqndir}/${entry}" );
		}	
	}
	INFO "added $counter file(s)";
	
	# compress results
	INFO "going to compress $archive";
	$tar->write( $archive, COMPRESS_GZIP );
}

=head1 help

Displays module documentation (which you are reading now).

=cut

sub help {
	pod2usage({
		'-verbose'   => 2,
		'-exitval'   => 0,
		'-noperldoc' => 1,
	});
}

1;



( run in 5.226 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )