File: BioFetch.t

package info (click to toggle)
bioperl 1.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 40,768 kB
  • ctags: 12,005
  • sloc: perl: 174,299; xml: 13,923; sh: 1,941; lisp: 1,803; asm: 109; makefile: 53
file content (134 lines) | stat: -rw-r--r-- 3,000 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# -*-Perl-*- Test Harness script for Bioperl
# $Id: BioFetch.t 16091 2009-09-15 22:11:15Z cjfields $

use strict;

BEGIN { 
    use lib '.';
    use Bio::Root::Test;
    
    test_begin(-tests => 36,
			   -requires_modules => [qw(IO::String LWP::UserAgent)],
			   -requires_networking => 1);
	
	use_ok('Bio::DB::BioFetch');
}

my $verbose = test_debug();

my $dbwarn = "Warning: Couldn't connect to EMBL with Bio::DB::BioFetch!\n";

my ($db,$db2,$seq,$seqio);

SKIP :{
	# get a single seq
	ok defined($db = Bio::DB::BioFetch->new(-verbose => $verbose));
	# get a RefSeq entry
	ok $db->db('refseq');
	eval {
		$seq = $db->get_Seq_by_acc('NM_006732'); # RefSeq VERSION
	};
	skip($dbwarn, 4) if $@;
	isa_ok($seq, 'Bio::SeqI');
	is($seq->accession_number,'NM_006732');
	is($seq->accession_number,'NM_006732');
	is( $seq->length, 3776);
}

SKIP: {
	# EMBL
	$db->db('embl');
	eval {
		$seq = $db->get_Seq_by_acc('J02231');    
	};
	skip($dbwarn, 3) if $@;
	isa_ok($seq, 'Bio::SeqI');
	is($seq->id, 'J02231');
	is($seq->length, 200);
}

SKIP: {
	eval {
		$seqio = $db->get_Stream_by_id(['BUM']);
	};
	skip($dbwarn, 3) if $@;
	undef $db; # testing to see if we can remove gb
	$seq = $seqio->next_seq();
	isa_ok($seqio, 'Bio::SeqIO');
	isa_ok($seq, 'Bio::SeqI');
	cmp_ok( $seq->length, '>=', 1);
}

SKIP: {
	#swissprot
	ok $db2 = Bio::DB::BioFetch->new(-db => 'swissprot');
	eval {
		$seq = $db2->get_Seq_by_id('YNB3_YEAST');
	};
	skip($dbwarn, 5) if $@;
	isa_ok($seq, 'Bio::SeqI');
	is($seq->length, 125);
	is($seq->division, 'YEAST');
	$db2->request_format('fasta');
	eval {
		$seq = $db2->get_Seq_by_acc('P43780');
	};
	skip($dbwarn, 2) if $@;
	isa_ok($seq, 'Bio::SeqI');
	is($seq->length,103);
}

$seq = $seqio = undef;

SKIP: {
	ok $db = Bio::DB::BioFetch->new(-retrievaltype => 'tempfile',
					 -format => 'fasta',
					 -verbose => $verbose
					);
	$db->db('embl');
	eval {
		$seqio = $db->get_Stream_by_id('J00522 AF303112 J02231');
	};
	skip($dbwarn, 7) if $@;
	my %seqs;
	# don't assume anything about the order of the sequences
	while ( my $s = $seqio->next_seq ) {
		isa_ok($s, 'Bio::SeqI');
		my ($type,$x,$name) = split(/\|/,$s->display_id);
		$seqs{$x} = $s->length;
	}
	isa_ok($seqio, 'Bio::SeqIO');
	is($seqs{'J00522'},408);
	is($seqs{'AF303112'},1611);
	is($seqs{'J02231'},200);
}

SKIP: {
	ok $db = Bio::DB::BioFetch->new(-db => 'embl', -verbose => $verbose ? $verbose : -1);
	
	# check contig warning (WebDBSeqI)
	eval {
		$seq = $db->get_Seq_by_acc('NT_006732');
	};
	like($@, qr{contigs are whole chromosome files}, 'contig warning');
	eval {
		$seq = $db->get_Seq_by_acc('NM_006732');
	};
	skip($dbwarn, 3) if $@;
	isa_ok($seq, 'Bio::SeqI');
	is($seq->length,3776);
}
    
# unisave
SKIP: {
	ok $db = Bio::DB::BioFetch->new(-db => 'unisave',
				   -verbose => $verbose);
	eval {
		$seq = $db->get_Seq_by_acc('LAM1_MOUSE');
	};
	skip($dbwarn, 3) if $@;
	isa_ok($seq, 'Bio::SeqI');
	is($seq->display_id, 'LAM1_MOUSE');
	is($seq->accession, 'P14733');   
	is($seq->length, 587);   
}