Bio-Grep
view release on metacpan or search on metacpan
lib/Bio/Grep/Backend/BackendI.pm view on Meta::CPAN
-class => 'Bio::Root::BadParameter',
-text => 'Sort mode not valid.',
-value => 'sort mode'
);
}
}
return 1;
}
### END OF SETTINGS TESTS
# copies the specified fasta file in the data directory and cerate a file
# <databasename>.nfo with the description, specified in the optional 2nd
# argument
# changes directory! so please save the oldpath before calling this method
sub _copy_fasta_file_and_create_nfo {
my ( $self, $args ) = @_;
# throw exception if filename looks wrong
$self->is_word( $args->{basefilename}, 'Fasta filename' );
my $newfile = $self->_cat_path_filename( $self->settings->datapath,
$args->{basefilename} );
$args->{filename} = $newfile;
my %dbs = $self->get_databases;
if ( defined $dbs{ $args->{basefilename} } ) {
$self->warn( "Database with that name already exists.\n"
. 'Skipping database generation.' );
$args->{skip} = 1;
return;
}
if ( defined $args->{copy} && $args->{copy} ) {
copy( $args->{file}, $newfile )
or $self->throw(
-class => 'Bio::Root::IOException',
-text => q{Can't copy } . $args->{file} . " to $newfile",
-value => $OS_ERROR,
);
}
else {
my $abs_path = $self->is_path( abs_path( $args->{file} ) );
symlink $abs_path, $newfile || $self->throw(
-class => 'Bio::Root::IOException',
-text => q{Can't symlink } . $abs_path . " to $newfile",
-value => $OS_ERROR,
);
}
if ( defined $args->{description} ) {
open my $NFOFILE, '>', $newfile . '.nfo';
print ${NFOFILE} $args->{description}
or $self->_cannot_print("$newfile.nfo");
close $NFOFILE;
}
return;
}
sub _guess_alphabet_of_file {
my ( $self, $filename ) = @_;
my $in = Bio::SeqIO->new( -file => $filename );
return $in->next_seq->alphabet;
}
sub _bioseq_query {
my ($self) = @_;
my $query_obj = $self->settings->query;
my $query;
if ( !defined $query_obj ) {
$self->throw(
-class => 'Bio::Root::BadParameter',
-text => 'Query not defined.',
);
}
my $db_alphabet
= $self->get_alphabet_of_database( $self->settings->database );
if ( eval { $query_obj->isa('Bio::Seq') } ) {
$query = $query_obj->seq;
}
else {
$query = $query_obj;
if ( $query =~ m{\A \w+ \z}xms ) {
if ( $db_alphabet eq 'dna' ) {
$query =~ tr/uU/tT/;
}
$query_obj = Bio::Seq->new(
-id => '1',
-desc => 'Query',
-seq => $query
);
}
else {
$query_obj = Bio::Seq->new( -id => '1', -desc => 'Query' );
}
}
return ( $query, $query_obj, $db_alphabet );
}
# prepares the query, for example calculating the reverse complement
# if necessary
# returns the prepared query. settings->query is unchanged!
sub _prepare_query {
my $self = shift;
my ( $query, $seq, $db_alphabet ) = $self->_bioseq_query();
if ( $seq->alphabet ne $db_alphabet ) {
$self->throw(
-class => 'Bio::Root::BadParameter',
-text => 'Alphabet of query and database not equal',
-value => 'Seq: ' . $seq->alphabet . ", DB: $db_alphabet"
);
}
if ( $self->settings->reverse_complement
|| $self->settings->direct_and_rev_com )
{
if ( $db_alphabet eq 'dna' ) {
if ( defined $self->features->{REVCOM_DEFAULT} ) {
( run in 0.840 second using v1.01-cache-2.11-cpan-39bf76dae61 )