Skip to content

Commit 4602211

Browse files
author
Hernan Morales
committed
Add Haplotypes tests
Add Genepop wrapper + tests Rename BioParserTests -> BioParsers-Tests
1 parent bec639d commit 4602211

124 files changed

Lines changed: 4776 additions & 7259 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

repository/BaselineOfBioSmalltalk/BaselineOfBioSmalltalk.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ BaselineOfBioSmalltalk >> baselineCommonPackages: spec [
114114
includes: #('BioPharoCommon') ];
115115
package: 'BioToolsSamples' with: [ spec requires: #('BioTools' 'BioEntrez' 'BioParsers' ). ];
116116
package: 'BioTools-Tests' with: [ spec requires: #('BioTools' ). ];
117-
package: 'BioWrapperTests' with: [ spec requires: #('BioTools-Tests' ) ];
117+
package: 'BioWrappers-Tests' with: [ spec requires: #('BioTools-Tests' ) ];
118118
package: 'BioPhysics' with: [ spec requires: #('BioTools') ];
119119
package: 'BioPhysics-Tests' with: [ spec requires: #('BioPhysics') ];
120120
package: 'BioWrappers' with: [ spec requires: #('BioTools' ) ];
@@ -240,7 +240,7 @@ BaselineOfBioSmalltalk >> baselineTestsGroup: spec [
240240
241241
'BioTools-Tests'
242242
'BioBlastTests'
243-
'BioWrapperTests'
243+
'BioWrappers-Tests'
244244
'BioParsers-Tests'
245245
'BioEntrezTests'
246246
'BioNCBITests'
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Class {
2+
#name : 'BioHaplotypeIOTest',
3+
#superclass : 'TestCase',
4+
#category : 'BioHaplotypes-Tests-Core',
5+
#package : 'BioHaplotypes-Tests',
6+
#tag : 'Core'
7+
}
8+
9+
{ #category : 'tests' }
10+
BioHaplotypeIOTest >> testAsBioHaplotypesReturnsCollection [
11+
| reader haps |
12+
reader := BioHaplotypePlinkReader new.
13+
haps := reader asBioHaplotypes.
14+
self assert: haps class equals: BioHaplotypes.
15+
self assert: haps size equals: 0
16+
]
17+
18+
{ #category : 'tests' }
19+
BioHaplotypeIOTest >> testFromPedFileMapFileCreatesCollection [
20+
"Tests class-side factory exists and configuration works (no file I/O)."
21+
| reader |
22+
reader := BioHaplotypePlinkReader new.
23+
reader pedFile: 'test.ped'; mapFile: 'test.map'.
24+
self assert: reader pedFile equals: 'test.ped'.
25+
self assert: reader mapFile equals: 'test.map'
26+
]
27+
28+
{ #category : 'tests' }
29+
BioHaplotypeIOTest >> testParseMapLines [
30+
| reader lines variants |
31+
reader := BioHaplotypePlinkReader new.
32+
lines := #( '1 rs111 0 100' '1 rs222 0 200' '1 rs333 0 300' ).
33+
variants := reader parseMapLines: lines.
34+
self assert: variants size equals: 3.
35+
self assert: (variants at: 1) rsID equals: 'rs111'.
36+
self assert: (variants at: 1) position equals: 100.
37+
self assert: (variants at: 1) chromosome equals: '1'.
38+
self assert: (variants at: 2) rsID equals: 'rs222'.
39+
self assert: (variants at: 3) rsID equals: 'rs333'
40+
]
41+
42+
{ #category : 'tests' }
43+
BioHaplotypeIOTest >> testParsePedLines [
44+
| reader variants haps v1 v2 |
45+
v1 := BioVariant position: 100 referenceAllele: 'A' alternateAlleles: #('T') rsID: 'rs111' chromosome: '1'.
46+
v2 := BioVariant position: 200 referenceAllele: 'C' alternateAlleles: #('G') rsID: 'rs222' chromosome: '1'.
47+
variants := {v1 . v2}.
48+
reader := BioHaplotypePlinkReader new.
49+
haps := reader parsePedLines: #('FAM1 IND1 0 0 1 1 A T C G') variants: variants.
50+
self assert: haps size equals: 2.
51+
self assert: (haps at: 1) alleles equals: #('A' 'C').
52+
self assert: (haps at: 2) alleles equals: #('T' 'G').
53+
self assert: (haps at: 1) identifier equals: 'IND1_a'.
54+
self assert: (haps at: 2) identifier equals: 'IND1_b'
55+
]
56+
57+
{ #category : 'tests' }
58+
BioHaplotypeIOTest >> testPlinkWrapperConfiguration [
59+
"Verify plinkWrapper can be set and retrieved."
60+
| reader plink |
61+
reader := BioHaplotypePlinkReader new.
62+
plink := BioPLINK1Wrapper new.
63+
reader plinkWrapper: plink.
64+
self assert: reader plinkWrapper equals: plink
65+
]
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Class {
2+
#name : 'BioHaplotypeMatrixTest',
3+
#superclass : 'TestCase',
4+
#category : 'BioHaplotypes-Tests-Core',
5+
#package : 'BioHaplotypes-Tests',
6+
#tag : 'Core'
7+
}
8+
9+
{ #category : 'running' }
10+
BioHaplotypeMatrixTest >> exampleMatrix [
11+
12+
^ BioHaplotypes exampleSimple asHaplotypeMatrix
13+
]
14+
15+
{ #category : 'tests' }
16+
BioHaplotypeMatrixTest >> testAccessing [
17+
18+
| mat |
19+
mat := self exampleMatrix.
20+
self assert: (mat at: 1 at: 1) equals: 'A'.
21+
self assert: (mat at: 1 at: 2) equals: 'C'.
22+
self assert: (mat at: 2 at: 1) equals: 'T'.
23+
self assert: (mat at: 2 at: 2) equals: 'G'
24+
]
25+
26+
{ #category : 'tests' }
27+
BioHaplotypeMatrixTest >> testDimensions [
28+
29+
| mat |
30+
mat := self exampleMatrix.
31+
self assert: mat rows equals: 2.
32+
self assert: mat columns equals: 2
33+
]
34+
35+
{ #category : 'tests' }
36+
BioHaplotypeMatrixTest >> testHammingDistances [
37+
38+
| mat dist |
39+
mat := self exampleMatrix.
40+
dist := mat pairwiseHammingDistances.
41+
self assert: (dist at: 1 at: 1) equals: 0.
42+
self assert: (dist at: 1 at: 2) equals: 2
43+
]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Class {
2+
#name : 'BioHaplotypePanelTest',
3+
#superclass : 'TestCase',
4+
#category : 'BioHaplotypes-Tests-Core',
5+
#package : 'BioHaplotypes-Tests',
6+
#tag : 'Core'
7+
}
8+
9+
{ #category : 'tests' }
10+
BioHaplotypePanelTest >> testRegistry [
11+
12+
| panel v1 |
13+
BioHaplotypePanel resetRegistry.
14+
v1 := BioVariant
15+
position: 100
16+
referenceAllele: 'A'
17+
alternateAlleles: #( 'T' )
18+
rsID: 'rs1'.
19+
panel := BioHaplotypePanel new
20+
panelName: 'TestPanel';
21+
addVariant: v1;
22+
yourself.
23+
BioHaplotypePanel register: panel.
24+
self
25+
assert: (BioHaplotypePanel panelNamed: 'TestPanel')
26+
equals: panel.
27+
BioHaplotypePanel unregister: panel.
28+
self assert: (BioHaplotypePanel panelNamed: 'TestPanel') isNil
29+
]
30+
31+
{ #category : 'tests' }
32+
BioHaplotypePanelTest >> testVariantAtRsID [
33+
34+
| panel v1 v2 |
35+
panel := BioHaplotypePanel new panelName: 'RsTest'.
36+
v1 := BioVariant
37+
position: 100
38+
referenceAllele: 'A'
39+
alternateAlleles: #( 'T' )
40+
rsID: 'rs1'.
41+
v2 := BioVariant
42+
position: 200
43+
referenceAllele: 'C'
44+
alternateAlleles: #( 'G' )
45+
rsID: 'rs2'.
46+
panel
47+
addVariant: v1;
48+
addVariant: v2.
49+
self assert: (panel variantAtRsID: 'rs1') equals: v1.
50+
self assert: (panel variantAtRsID: 'rs2') equals: v2.
51+
self assert: (panel variantAtRsID: 'rs999') isNil
52+
]
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
Class {
2+
#name : 'BioHaplotypeTest',
3+
#superclass : 'TestCase',
4+
#category : 'BioHaplotypes-Tests-Core',
5+
#package : 'BioHaplotypes-Tests',
6+
#tag : 'Core'
7+
}
8+
9+
{ #category : 'running' }
10+
BioHaplotypeTest >> exampleHaplotype [
11+
12+
| v1 v2 |
13+
v1 := BioVariant
14+
position: 100
15+
referenceAllele: 'A'
16+
alternateAlleles: #( 'T' )
17+
rsID: 'rs1'
18+
chromosome: '1'.
19+
v2 := BioVariant
20+
position: 200
21+
referenceAllele: 'C'
22+
alternateAlleles: #( 'G' )
23+
rsID: 'rs2'
24+
chromosome: '1'.
25+
^ BioHaplotype
26+
withAlleles: #( 'A' 'C' )
27+
atVariants: {
28+
v1.
29+
v2 }
30+
identifier: 'hap1'
31+
]
32+
33+
{ #category : 'running' }
34+
BioHaplotypeTest >> exampleHaplotype2 [
35+
36+
| v1 v2 |
37+
v1 := BioVariant
38+
position: 100
39+
referenceAllele: 'A'
40+
alternateAlleles: #( 'T' )
41+
rsID: 'rs1'
42+
chromosome: '1'.
43+
v2 := BioVariant
44+
position: 200
45+
referenceAllele: 'C'
46+
alternateAlleles: #( 'G' )
47+
rsID: 'rs2'
48+
chromosome: '1'.
49+
^ BioHaplotype
50+
withAlleles: #( 'T' 'G' )
51+
atVariants: {
52+
v1.
53+
v2 }
54+
identifier: 'hap2'
55+
]
56+
57+
{ #category : 'tests' }
58+
BioHaplotypeTest >> testAlleleAtRsID [
59+
60+
| h |
61+
h := self exampleHaplotype.
62+
self assert: (h alleleAtRsID: 'rs1') equals: 'A'.
63+
self assert: (h alleleAtRsID: 'rs2') equals: 'C'
64+
]
65+
66+
{ #category : 'tests' }
67+
BioHaplotypeTest >> testAsAlleleString [
68+
69+
| h |
70+
h := self exampleHaplotype.
71+
self assert: h asAlleleString equals: 'A-C'
72+
]
73+
74+
{ #category : 'tests' }
75+
BioHaplotypeTest >> testAt [
76+
| h |
77+
h := self exampleHaplotype.
78+
self assert: (h at: 1) equals: 'A'.
79+
self assert: (h at: 2) equals: 'C'
80+
]
81+
82+
{ #category : 'tests' }
83+
BioHaplotypeTest >> testCreation [
84+
85+
| h |
86+
h := self exampleHaplotype.
87+
self assert: h alleles equals: #( 'A' 'C' ).
88+
self assert: h identifier equals: 'hap1'.
89+
self assert: h size equals: 2
90+
]
91+
92+
{ #category : 'tests' }
93+
BioHaplotypeTest >> testDynamicRsIDAccess [
94+
95+
| h |
96+
h := self exampleHaplotype.
97+
self assert: (h perform: #rs1) equals: 'A'.
98+
self assert: (h perform: #rs2) equals: 'C'
99+
]
100+
101+
{ #category : 'tests' }
102+
BioHaplotypeTest >> testHammingDistance [
103+
104+
| h1 h2 |
105+
h1 := self exampleHaplotype.
106+
h2 := self exampleHaplotype2.
107+
self assert: (h1 hammingDistanceTo: h2) equals: 2.
108+
self assert: (h1 hammingDistanceTo: h1) equals: 0
109+
]
110+
111+
{ #category : 'tests' }
112+
BioHaplotypeTest >> testImmutability [
113+
114+
| h |
115+
h := self exampleHaplotype.
116+
self assert: h isImmutable.
117+
self should: [ h at: 1 put: 'T' ] raise: Error
118+
]
119+
120+
{ #category : 'tests' }
121+
BioHaplotypeTest >> testMatchesAtLocus [
122+
123+
| h1 h2 |
124+
h1 := self exampleHaplotype.
125+
h2 := self exampleHaplotype2.
126+
self deny: (h1 matches: h2 atLocus: 1).
127+
self deny: (h1 matches: h2 atLocus: 2)
128+
]
129+
130+
{ #category : 'tests' }
131+
BioHaplotypeTest >> testPrintOn [
132+
133+
| h |
134+
h := self exampleHaplotype.
135+
self assert: h printString equals: 'BioHaplotype(hap1)[A|C]'
136+
]
137+
138+
{ #category : 'tests' }
139+
BioHaplotypeTest >> testVariantAt [
140+
141+
| h v1 |
142+
h := self exampleHaplotype.
143+
v1 := BioVariant
144+
position: 100
145+
referenceAllele: 'A'
146+
alternateAlleles: #( 'T' )
147+
rsID: 'rs1'
148+
chromosome: '1'.
149+
self assert: (h variantAt: 1) position equals: 100
150+
]
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Class {
2+
#name : 'BioHaplotypesTest',
3+
#superclass : 'TestCase',
4+
#category : 'BioHaplotypes-Tests-Core',
5+
#package : 'BioHaplotypes-Tests',
6+
#tag : 'Core'
7+
}
8+
9+
{ #category : 'running' }
10+
BioHaplotypesTest >> exampleHaplotypes [
11+
^ BioHaplotypes exampleSimple
12+
]
13+
14+
{ #category : 'tests' }
15+
BioHaplotypesTest >> testCountAllelesAtLocus [
16+
| hs |
17+
hs := self exampleHaplotypes.
18+
self assert: ((hs countAllelesAtLocus: 1) occurrencesOf: 'A') equals: 1.
19+
self assert: ((hs countAllelesAtLocus: 1) occurrencesOf: 'T') equals: 1
20+
]
21+
22+
{ #category : 'tests' }
23+
BioHaplotypesTest >> testHaplotypeDiversity [
24+
| hs |
25+
hs := self exampleHaplotypes.
26+
self assert: hs haplotypeDiversity closeTo: 1.0
27+
]
28+
29+
{ #category : 'tests' }
30+
BioHaplotypesTest >> testPairwiseDistances [
31+
| hs dist |
32+
hs := self exampleHaplotypes.
33+
dist := hs pairwiseDistances.
34+
self assert: (dist at: 1 at: 1) equals: 0.
35+
self assert: (dist at: 1 at: 2) equals: 2.
36+
self assert: (dist at: 2 at: 1) equals: 2.
37+
self assert: (dist at: 2 at: 2) equals: 0
38+
]
39+
40+
{ #category : 'tests' }
41+
BioHaplotypesTest >> testSelect [
42+
| hs selected |
43+
hs := self exampleHaplotypes.
44+
selected := hs select: [ :h | h identifier = 'h1' ].
45+
self assert: selected size equals: 1
46+
]
47+
48+
{ #category : 'tests' }
49+
BioHaplotypesTest >> testSize [
50+
| hs |
51+
hs := self exampleHaplotypes.
52+
self assert: hs size equals: 2
53+
]
54+
55+
{ #category : 'tests' }
56+
BioHaplotypesTest >> testUniqueHaplotypes [
57+
| hs |
58+
hs := self exampleHaplotypes.
59+
self assert: hs uniqueHaplotypes size equals: 2
60+
]

0 commit comments

Comments
 (0)