Bio-EUtilities

 view release on metacpan or  search on metacpan

t/release-EUtilities.t  view on Meta::CPAN

        isa_ok($history, 'Bio::Tools::EUtilities::HistoryI');

        # check the actual data
        my ($webenv, $key) = $history->history;
        like($webenv, qr{^\S{15}}, 'WebEnv');
        like($key, qr{^\d+}, 'query key');

        # can we fetch the sequences?
        $eutil->set_parameters(
            -eutil      => 'efetch',
            -history    => $history,
            -rettype    => 'fasta',
            -retmax     => 5
        );
        # look for fasta headers
        my ($r, $t);
        eval{ $r = $eutil->get_Response->content;};
        skip("EPost HTTP error", 1) if $@;
        $t = grep m{^>.*$}, split("\n", $r);
        is($t, 5, 'EPost to EFetch');
    }
}

# EInfo

sub einfo {
    SKIP: {
        $eutil = Bio::DB::EUtilities->new(
                                        -eutil      => 'einfo',
                                        -db         => 'protein',
                                        -email      => $email
                                          );
        isa_ok($eutil, 'Bio::DB::GenericWebAgent');
        eval {$response = $eutil->get_Response; };
        skip("EInfo HTTP error:$@", 10) if $@;
        isa_ok($response, 'HTTP::Response');
        like($response->content, qr(<eInfoResult>), 'EInfo response');
        is(($eutil->get_database)[0], 'protein', '$einfo->get_database()');
        like($eutil->get_last_update, qr(\d{4}\/\d{2}\/\d{2}\s\d{2}:\d{2}),
             '$einfo->get_last_update()');
        cmp_ok($eutil->get_record_count, '>', 9200000, '$einfo->get_record_count()');
        is($eutil->get_description, 'Protein sequence record', '$einfo->get_description()');
        my @links = $eutil->get_LinkInfo;
        my @fields = $eutil->get_FieldInfo;
        cmp_ok(scalar(@links), '>',30, '$einfo->get_LinkInfo()');
        cmp_ok(scalar(@fields), '>',24, '$einfo->get_FieldInfo()');

        # all databases (list)
        $eutil = Bio::DB::EUtilities->new(
                                        -eutil      => 'einfo',
                                        -api_key    => $api_key,
                                        -email      => $email
                                          );

        eval {$response = $eutil->get_Response; };
        skip("EInfo HTTP error:$@", 1) if $@;

        my @db = sort qw(pubmed  protein  nucleotide  nuccore  nucgss  nucest  structure
        genome  books  cancerchromosomes  cdd  domains  gene  genomeprj  gensat
        geo  gds  homologene  journals  mesh  ncbisearch  nlmcatalog  omia  omim
        pmc  popset  probe  pcassay  pccompound  pcsubstance  snp  taxonomy toolkit
        unigene  unists);

        my @einfo_dbs = sort $eutil->get_databases;
        cmp_ok(scalar(@einfo_dbs), '>=', scalar(@db), 'All EInfo databases');
    }
}


# ELink - normal (single ID array) - single db - ElinkData tests

sub elink1 {
    SKIP: {
        $eutil = Bio::DB::EUtilities->new(
                                        -eutil      => 'elink',
                                        -db         => 'taxonomy',
                                        -dbfrom     => 'protein',
                                        -id         => \@ids,
                                        -api_key    => $api_key,
                                        -email      => $email
                                          );

        isa_ok($eutil, 'Bio::DB::GenericWebAgent');
        eval {$response = $eutil->get_Response; };
        skip("ELink HTTP error:$@", 7) if $@;
        isa_ok($response, 'HTTP::Response');
        like($response->content, qr(<eLinkResult>), 'ELink response');
        # Data is too volatile to test; commenting for now...
        #my @ids2 = qw(350054 306537 273068 83332 1394);
        cmp_ok($eutil->get_ids, '>=', 1);
        #is_deeply([sort $eutil->get_ids], [sort @ids2],'$elink->get_ids()');

        # Linkset tests
        is($eutil->get_LinkSets, 1, '$elink->get_LinkSets()');
        my $linkobj = $eutil->next_LinkSet;
        isa_ok($linkobj, 'Bio::Tools::EUtilities::Link::LinkSet');
        is($linkobj->get_dbfrom, 'protein', '$linkdata->get_dbfrom()');
        #is_deeply([sort $linkobj->elink_queryids],
        #          [sort @ids], '$linkdata->elink_queryids()');
        my $db = $linkobj->get_dbto;
        is($db, 'taxonomy', '$linkdata->get_dbto()');
        #is_deeply([sort $linkobj->get_LinkIds_by_db($db)],
        #          [sort @ids2], '$linkdata->get_LinkIds_by_db($db)');
    }
}

sub elink2 {
    my @genome_ids = qw(30807 33011 12997 16707 45843 31129 31141 31131 31133 32203 31135);
    SKIP: {
        $eutil = Bio::DB::EUtilities->new(
                                        -eutil      => 'elink',
                                        -db         => 'nuccore',
                                        -dbfrom     => 'genomeprj',
                                        -id         => @genome_ids,
                                        -api_key    => $api_key,
                                        -email      => $email
                                          );

        eval {$response = $eutil->get_Response; };
        skip("ELink HTTP error:$@", 7) if $@;
        isa_ok($response, 'HTTP::Response');



( run in 0.767 second using v1.01-cache-2.11-cpan-71847e10f99 )