BioPerl & CPAN - Problems in installation & error "Can't locate Bio/EnsEMBL/Registry.pm in #INC" - cpan

I'm posting this message out of pure desperation, because I really don't know what else to try. I'm a beginner in bioperl and I'm working on a script to parse out some results I got from MolQuest fgenesh. Results are out in .txt format and I want to parse them to GFF and fasta file for mRNA and protein sequences to facilitate comparison with other results we have. So I found the Bio::Tools::Fgenesh module and I'm working on a script with it. Problem is, BioPerl doesn't seem to work on my ubuntu pc
I followed the instructions here http://www.bioperl.org/wiki/Installing_Bioperl_for_Unix . I managed to install CPAN in root mode (otherwise it wouldn't work) and BioPerl via CPAN. All tests were ok, but when I ran this script to test the installation
use strict;
use warnings;
use Getopt::Long;
use Bio::EnsEMBL::Registry;
my $reg = "Bio::EnsEMBL::Registry";
$reg->load_registry_from_db(
-host => "ensembldb.ensembl.org",
-user => "anonymous"
);
my $db_list=$reg->get_all_adaptors();
my #line;
foreach my $db (#$db_list){
#line = split ('=',$db);
print $line[0]."\n";
}
I got the error: "Can't locate Bio/EnsEMBL/Registry.pm in #INC"
I tried to install BioPerl again via Build.PL, running as root, but still came to the same outcome.
Thanks for your help
Merche

You seem to be attempting to use the Ensembl API. This is not part of the BioPerl distribution. Please see http://www.ensembl.org/info/docs/api/api_installation.html for more information about how to install it. We do not recommend you install this in any of the default Perl library location as the API is heavily tied into the data made in the same release. Ensembl provides 4-5 releases per year so maintaining this can be difficult.
Should you have anymore issues then you can contact the developers. We have an active developers mailing list & a helpdesk. See http://www.ensembl.org/info/about/contact/index.html for more information.

I had ecountered the same error as you, working on a windows 64x. Seems Bio::EnsEMBL::Registry is not recognized on my windows computer.
Following all the ENSEMBL-API instructions, I finally came across a debugging page (http://www.ensembl.org/info/docs/api/debug_installation_guide.html). After running C:\src\ensembl/misc-scripts/ping_ensembl.pl, I got again the same error message as listed above.
According to the PERL API help for windows, I need to run "set PERL5LIB=C:\src\bioperl-1.2.3;C:\src\ensembl\modules;C:\src\ensembl-compara\modules;C:\src\ensembl-variation\modules;C:\src\ensembl-funcgen\modules" from the cmd box. Did that, but error remained the same.
Now I included these paths (C:\src\bioperl-1.2.3;C:\src\ensembl\modules;C:\src\ensembl-compara\modules;C:\src\ensembl-variation\modules;C:\src\ensembl-funcgen\modules) directly in my perl script, and this seems to work. Probably this is not the way to do it, but as long as it works, I'm happy.
See an example script (based on excercises provided by Bert Overduin) below:
#!/usr/bin/perl -w
use lib "C:/src/ensembl/modules";
use lib "C:/src/ensembl/modules/Bio/EnsEMBL";
use lib "C:/src/ensembl-compara/modules/Bio/EnsEMBL/Compara";
use lib "C:/src/ensembl-functgenomics/modules/Bio/EnsEMBL/Funcgen";
use lib "C:/src/ensembl-variation/modules/Bio/EnsEMBL/Variation";
use strict;
use Bio::EnsEMBL::Registry;
my $registry = 'Bio::EnsEMBL::Registry';
$registry->load_registry_from_db(
-host => 'ensembldb.ensembl.org',
-user => 'anonymous',
-verbose => '1'
);
my $slice_adaptor =
Bio::EnsEMBL::Registry->get_adaptor( "human", "core", "slice" );
get a slice on the entire chromosome X
my $chr_slice = $slice_adaptor->fetch_by_region( 'chromosome', '13', 32_889_000, >32_891_000 );
print "#######################################################\n";
print $chr_slice->seq;
Or alternatively:
#!/usr/bin/perl -w
BEGIN{ push #INC,'C:/src/bioperl-live','C:/src/ensembl/modules','C:/src/ensembl-compara/modules','C:/src/ensembl-variation/modules','C:/src/ensembl-functgenomics/modules';};
use strict;
use Bio::EnsEMBL::Registry;
my $registry = 'Bio::EnsEMBL::Registry';
$registry->load_registry_from_db(
-host => 'ensembldb.ensembl.org',
-user => 'anonymous',
-verbose => '1'
);
my $slice_adaptor =
Bio::EnsEMBL::Registry->get_adaptor( "human", "core", "slice" );
get a slice on the entire chromosome X
my $chr_slice = $slice_adaptor->fetch_by_region( 'chromosome', '13', 32_889_000, >32_891_000 );
print "#######################################################\n";
print $chr_slice->seq;

Related

Can't run Perl script on other computer

When I try to run script on my second computer I get this message:
malformed JSON string, neither array, object, number, string or atom, at character offset 0
(before "LWP will support htt...") at iptest.pl line 21, line 2.
On my first computer, the script works fine.
Line 21:
my $data = decode_json($resp->content);
Does anyone know what the problem can be?
Thanks in advance
I'm a bit surprised that the JSON error is the only error you get. But it does contain a tiny little hint: "LWP will support htt...". I bet that LWP is missing a module it needs to be able to make https connections. You now have two options:
print $response->content to see the full error message.
On the command line, do something like lwp-request https://google.com/. You should see the full error message.
Then install the missing module.
And of course: please, please, please:
use strict and use warnings
Clean that script up and throw away every use-line you don't need: IO::Socket, LWP::Simple, YAML::Tiny.
Read the documentation of the modules that you actually are using. What are you trying to achieve with LWP::UserAgent->new(keep_alive)? Hint: It won't help to quote keep_alive.
Some issues:
Always use use strict; use warnings;.
Never use $response->content. What it returns is useless. Instead, use $response->decoded_content( charset => 'none').
You need to chomp the values you get from STDIN.
You should never use our unless forced to (e.g. our #ISA = ok). my should be used instead.
my $format = '$format'; "$format" is a silly way of writing "\$format".
I applied most of the changes ikegami suggested. Then perl gave me good error messages to fix the remaining issues. It looks like it works now. Don't ask why it didn't work before. Your code is weird that it's hard to say what exactly went wrong. With strict and warnings you're forced to write better code. Maybe add some nicely named subroutines to add more clarity.
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket;
use LWP::UserAgent;
use open qw(:std :utf8);
use LWP::Simple;
use YAML::Tiny;
use JSON;
use URI;
use List::MoreUtils qw(uniq);
print "Enter Qve:";
my ( $qve, $loc, $key, $href );
chomp( $qve = <STDIN> );
print "Enter Location:";
chomp( $loc = <STDIN> );
$key = '';
my $format = '$format';
$href =
"https://api.datamarket.azure.com/Bing/Search/v1/Web?Query='$qve [loc:$loc]'&Latitude=43&Longitude=19&$format=JSON";
my $ua = LWP::UserAgent->new('keep_alive');
$ua->credentials( "api.datamarket.azure.com" . ':443', '', '', $key );
my $resp = $ua->get($href);
my $data = decode_json( $resp->decoded_content( charset => 'none' ) );
my #urls = map { $_->{'Url'} } #{ $data->{d}->{results} };
my #za;
for my $i ( 0 .. $#urls ) {
my $trz = "www.";
my $host = URI->new( $urls[$i] )->host;
$host =~ s/$trz//g;
push( #za, $host );
}
For the record, this fixed the issue for me (CentOS):
# yum install perl-Crypt-SSLeay
I got in the same situation. After I used 'yum' to install perl, I still got the error when run the perl script.
$ sudo yum install perl
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management
...
Eventually I did these, and it works.
$ lwp-request https://google.com/
It returned an error message .. (LWP::Protocol::https not installed)
$ sudo rpm -ivh ~/perl-LWP-Protocol-https-6.07-4.el8.noarch.rpm
$ lwp-request https://google.com/
it returned a HTML page.
and my perl script can run without error.
(my system is:
$ cat /etc/os-release
PRETTY_NAME=Red Hat Enterprise Linux 8.0 )

Problems using the HTML::Template module

I'm unable to execute the HTML::Template function in the CGI.
I'm following a simple tutorial that I found here: http://metacpan.org/pod/HTML::Template
I created a new file on my server in the home path as test.tmpl.
I created a new file named frt.cgi ... (is that the issue here? should it be a different file extention??)
#!/usr/local/bin/perl -w
use HTML::Template;
# open the html template
my $template = HTML::Template->new(filename => '/test.html');
# fill in some parameters
$template->param(HOME => $ENV{HOME});
$template->param(PATH => $ENV{PATH});
# send the obligatory Content-Type and print the template output
print "Content-Type: text/html\n\n", $template->output;
I've modified the 1st line to reflect my host provided program path for perl. I don't know what the -w does I just know I've tried this with and without it. Also I've tried changing the code a bit like this:
use warnings;
use strict;
use CGI qw(:standard);
use HTML::Template;
I've searched...
https://stackoverflow.com/search?q=HTML%3A%3ATEMPLATE+&submit=search
https://stackoverflow.com/search?q=HTML%3A%3ATEMPLATE
https://stackoverflow.com/search?q=HTML%3A%3ATEMPLATE+PERL&submit=search
Yet I still do not see the answer.
I even searched google for .TMPL Encoding because I thought there may be some special type needed. Please help.
If you look in your server logs, you'll probably see an error message along the lines of:
HTML::Template->new() : Cannot open included file /test.html : file not found.
You need to provide the path on the file system, not a URI relative to the generated document.
First, you likely specified the wrong path - change /test.html to test.html.
Also, it is possible that there is no $ENV{HOME} variable in your system so set up flag die_on_bad_params to 0:
my $template = HTML::Template->new(
filename => 'test.html',
die_on_bad_params => 0,
);
Also, don't forget to mark your Perl file as executable by chmod 755.
Option -w makes Perl to enable warnings, so there is no point to write use warnings; afterwards.
You can check what Perl command line options do by using module B::Deparse, like this ($^W variable disables/enables warnings):
perl -w -MO=Deparse -e "print;"
This would print:
BEGIN { $^W = 1; }
print $_;

Check the list of module installed in machine

I have made a script to intimate the admin the list of module need to be installed on machine .
I am trying to check wheather the module installed by underbelow code. The odd thing is that it is showing even installed module in the machine as not installed
#!/usr/bin/perl -w
my #module_list =('Smart::Comments','HTML::Parse');
foreach (#module_list) {
eval { require "$_" };
if (!($#)) {
print "Module Not installed : $_\n";
}
}
You need to use the string form of eval because require needs a bareword argument to match against the double-colon-separated form of the module name (e.g. Scalar::Util). (If it's not a bareword, then it needs to be a relative path, e.g. 'Scalar/Util.pm')
#!/usr/bin/perl
use strict;
use warnings;
my #module_list = ('Scalar::Util', 'flibble');
foreach (#module_list) {
if (!eval "require $_") {
print "Module not installed: $_\n";
}
}
There's my App::Module::Lister, which I designed as a modulino that can run as a module, a command-line utility, or a CGI script. It's a simple thing I needed for a friend who only had FTP access to a web server.
It gives you the list of everything in Perl's module search path, which I usually find easier than checking for specific modules each time. Once I have the whole list, I just look at the list.
You could check that you can load the module, but I tend to not like that because I don't want to potentially run the module's code to see if it's installed. It's usually not a problem, though.

Perl script cant find Net/SSH/Perl.pm

Im trying to run a perl script which involves ssh to a remote server and while executing this code, it throws an error like
Can't locate Net/SSH/Perl.pm in INC <#INC contains:C:/Perl/site/lib c:\perl\lib at line5.
I open ppm graphical UI and installed NET-SSH, area= site
but still not able to execute this script
Here is the script
use strict;
use warnings;
use Net::SSH::Perl;
my $ip=12.14.142.22;
my $user = "qwerty";
my $pass = "termide";
my $ssh = Net::SSH::Perl->new($ip, use_pty => 1);
$ssh->login($user, $pass);
While Foo::Bar often includes a Foo::Bar::Baz module, that isn't the case here.
Net::SSH and Net::SSH::Perl are different distributions. You need to install Net::SSH::Perl.
You should install Net::SSH::Perl, not Net::SSH. The error message is clean about that :)
Net::SSH2 is another SSH client that works on Windows and far easier to install. A PPM is available from here.

How can I tell if a Perl module is core or part of the standard install?

How can I check if a Perl module is part of the core - i.e. it is part of the standard installation?
I'm looking for:
a command-line command:
a Perl subroutine/function to check within code
Perhaps the question should be: How can I tell what modules were originally provided with the specific Perl installation on a machine? (Actually, it is now asked as How can I tell what modules were originally provided with the specific Perl installation on a machine?.)
Given that there now appears to not to be an overall Perl standard installation, at least the answer to this new question will tell me what I originally had in the installation when it was first installed.
With that knowledge and if I keep the original installer image/package OR know how to get the exact thing again online, then I have a repeatable Perl installation for several machines with the knowledge of what modules will be present and what modules will not.
To clarify further: I am looking at what came with the installation originally, what modules were provided as part of that installation, and what was built-in. NOT what has been installed since then.
And I want to be able to do this on the machine that has the installation. So for this I would be relying upon the installation to have a record in some form as to what it has originally.
I asked spin-off question:
How can I tell what modules were originally provided with the specific Perl installation on a machine? (How can I tell what modules were originally provided with the specific Perl installation on a machine?)
The corelist command from the Module::CoreList module will determine if a module is Core or not.
> corelist Carp
Carp was first release with perl 5
> corelist XML::Twig
XML::Twig was not in CORE (or so I think)
Here is one way to use it in a script. The Module::CoreList POD is too terse -- you have to go hunting through the source code to find what methods to call:
use strict;
use warnings;
use Module::CoreList;
my $mod = 'Carp';
#my $mod = 'XML::Twig';
my #ms = Module::CoreList->find_modules(qr/^$mod$/);
if (#ms) {
print "$mod in core\n";
}
else {
print "$mod not in core\n";
}
__END__
Carp in core
You could check perlmodlib in a sub:
my %_stdmod;
sub is_standard_module {
my($module) = #_;
unless (keys %_stdmod) {
chomp(my $perlmodlib = `perldoc -l perlmodlib`);
die "cannot locate perlmodlib\n" unless $perlmodlib;
open my $fh, "<", $perlmodlib
or die "$0: open $perlmodlib: $!\n";
while (<$fh>) {
next unless /^=head\d\s+Pragmatic\s+Modules/ ..
/^=head\d\s+CPAN/;
if (/^=item\s+(\w+(::\w+)*)/) {
++$_stdmod{ lc $1 };
}
}
}
exists $_stdmod{ lc $module } ? $module : ();
}
Example usage:
die "Usage: $0 module..\n" unless #ARGV;
foreach my $mod (#ARGV) {
my $stdmod = is_standard_module $mod;
print "$0: $mod is ", ($stdmod ? "" : "not "), "standard\n";
}
Output:
$ ./isstdmod threads::shared AnyDBM_File CGI LWP::Simple
./isstdmod: threads::shared is standard
./isstdmod: AnyDBM_File is standard
./isstdmod: CGI is standard
./isstdmod: LWP::Simple is not standard
perldoc is most definitely part of the Perl's true core and standard installation. The source distribution for perl-5.10.1, for example, contains
perldoc.PL, generates perldoc as part of the standard installation
perlmodlib.PL, generates perlmodlib.pod as part of the standard installation
This is not a new addition. Perl-5.6.0, about ten years old, had perlmodlib as part of its true-core, standard installation.
Installations that do not contain these items are non-standard. Yes, I appreciate that it may seem academic from your perspective, but your vendor's packaging permitted a non-standard installation that breaks otherwise working programs.
With Debian's package manager, you can get the standard Perl installation with
$ apt-get --install-recommends install perl
There really is no such thing as "core" any more. There used to be a standard Perl distribution, but a lot of people don't have a standard Perl distribution. Operating system distributions modify it by either adding or removing modules, changing modules, and so on. You can't rely on the standard distribution being actually standard. Some Linux distributions don't even include the Perl documentation as part of the base Perl installation.
You mention that you can't use Module::CoreList because it isn't core, but if you can create files, you can install the module. You can even pretend that you wrote it yourself.
For the really lazy, there's the Core Modules list on the perldoc.perl.org website.
You can use (for example, search for Net::FTP):
perl -MNet::FTP -e 1
If it doesn't have output, then it's installed.
Other resources
perldoc perlmodlib
perldoc perllocal
A node from perlmonks
In a response to a comment of Gbacon's, you say that you want the answer to be platform neutral. I don't know of such a solution, but I wonder if it's even the right way to go.
If your goal is to find out on specific machines, I would use the tools that come with the platform. On Debian, that would include dpkg (pre-installed on any Debian system) or apt-file (not pre-installed necessarily) or other APT tools.
As an example, take a look at the output of this:
dpkg-query -L perl | less
You would obviously need to parse the output, but it strikes me as a start precisely because it is specific to the machine in question.
From the command-line:
Let's say that you want to know
whether module Tie::Hash is
installed.
To find out, execute
the following from the command line:
perl -MTie::Hash -e 1
If you don't get any output from the above command then the module is installed; if you get an error, it's not installed.
For making this check from within the script you can make use of Module::Load::Conditional.