mspire-mascot-dat 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ require 'mspire/mascot/dat'
4
+
5
+ describe 'dat file can be open for reading with block' do
6
+ let(:file) { TESTFILES + '/F004129.dat' }
7
+
8
+ specify '#open(file)' do
9
+ Mspire::Mascot::Dat.open(file) do |dat|
10
+ dat.should be_a(Mspire::Mascot::Dat)
11
+ end
12
+ end
13
+ end
14
+
15
+ describe 'reading a dat file' do
16
+ before(:each) do
17
+ @file = TESTFILES + '/F004129.dat'
18
+ @io = File.open(@file)
19
+ @dat = Mspire::Mascot::Dat.new(@io)
20
+ end
21
+
22
+ after(:each) do
23
+ @io.close
24
+ end
25
+
26
+ it 'knows all the sections, with queries grouped' do
27
+ @dat.sections.should == [:parameters, :masses, :unimod, :enzyme, :header, :summary, :decoy_summary, :peptides, :decoy_peptides, :proteins, :index, :queries]
28
+ end
29
+
30
+ it 'can retrieve queries at random' do
31
+ @dat.query(1).title.should == '1.2746.2746.2'
32
+ @dat.query(2).title.should == '1.2745.2745.4'
33
+ end
34
+
35
+ it 'can retrieve every peptide' do
36
+ start = [ [1,1,'VMLSDADPSLEQYYVNVR'],
37
+ [2,1,'MDSSSGSQGNGSFMDQNSLGILNMDNLK'],
38
+ [2,2,'STGAESSEEXLREAYIMASVEHVNLLK'],
39
+ [2,3,'LSSPPSTSHTYEGKLLTKPTHTNTDLR'],
40
+ [2,4,'MDSSSGSQGNGSFMDQNSLGILNMDNLK']]
41
+
42
+ last = [2,10,'NGSSVAGTSVLSPSIPLTLVVLPALMIAQK']
43
+
44
+ last_pep = nil
45
+ @dat.each_peptide do |peptide|
46
+ last_pep = peptide
47
+ (qnum, pnum, aa) = start.shift
48
+ if qnum
49
+ peptide.query_num.should == qnum
50
+ peptide.peptide_num.should == pnum
51
+ peptide.seq.should == aa
52
+ end
53
+ end
54
+ (qnum, pnum, aa) = last
55
+ peptide = last_pep
56
+ peptide.query_num.should == qnum
57
+ peptide.peptide_num.should == pnum
58
+ peptide.seq.should == aa
59
+
60
+ # this proves that each_peptide can also return an enumerator if asked
61
+ cnts = @dat.each_peptide.with_index.map do |peptide,i|
62
+ peptide.should(be_a(Mspire::Mascot::Dat::Peptide)) && i
63
+ end
64
+ cnts.should == (0..10).to_a
65
+ end
66
+
67
+ it 'can retrieve decoy peptides' do
68
+ ions_score_target = @dat.each_peptide(true, 1).map do |peptide|
69
+ peptide.should(be_a(Mspire::Mascot::Dat::Peptide))
70
+ peptide.peptide_num.should == 1
71
+ peptide.ions_score
72
+ end
73
+ ions_score_target.should == [0.22, 4.11]
74
+
75
+ ions_score_decoy = @dat.each_peptide(false, 1).map do |peptide|
76
+ peptide.should(be_a(Mspire::Mascot::Dat::Peptide))
77
+ peptide.peptide_num.should == 1
78
+ peptide.ions_score
79
+ end
80
+ ions_score_decoy.should == [3.52, 4.58]
81
+ end
82
+
83
+ it 'can retrieve just the n peptides' do
84
+ n = 1
85
+ cnt = 0
86
+ @dat.each_peptide(true, n) do |peptide|
87
+ cnt += 1
88
+ peptide.should(be_a(Mspire::Mascot::Dat::Peptide))
89
+ peptide.query_num.should == cnt
90
+ peptide.peptide_num.should == 1
91
+ end
92
+ end
93
+
94
+ end