File: tests.py

package info (click to toggle)
sra-sdk 3.2.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 296,076 kB
  • sloc: ansic: 532,876; cpp: 243,000; perl: 9,649; python: 8,978; sh: 7,888; java: 6,253; makefile: 1,148; yacc: 703; xml: 310; lex: 236
file content (512 lines) | stat: -rw-r--r-- 22,080 bytes parent folder | download | duplicates (4)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
import unittest
from ngs import NGS
from ngs.ErrorMsg import ErrorMsg
from ngs.ReadCollection import ReadCollection
from ngs.ReferenceSequence import ReferenceSequence
from ngs.Alignment import Alignment
from ngs.Read import Read

PrimaryOnly           = "SRR1063272"
WithSecondary         = "SRR833251"
WithGroups            = "SRR822962"
WithCircularRef       = "SRR1769246"
SingleFragmentPerSpot = "SRR2096940";

def getRead(id):
    run = NGS.openReadCollection(PrimaryOnly)
    return run.getRead(id)

def getAlignment(id):
    run = NGS.openReadCollection(PrimaryOnly)
    return run.getAlignment(id)

def getSecondaryAlignment(id):
    run = NGS.openReadCollection(WithSecondary)
    return run.getAlignment(id)

def getReference():
    return NGS.openReadCollection(PrimaryOnly).getReference("supercont2.1")

def getReferenceSequence():
    return NGS.openReferenceSequence("NC_011752.1")

class Tests(unittest.TestCase):

    def fail(self):
        self.assertTrue(False)

    def test_open_success(self):
        run = NGS.openReadCollection(PrimaryOnly)

    def test_open_fail(self):
        try:
            run = NGS.openReadCollection("SRRsomejunk")
            self.fail()
        except ErrorMsg:
            pass

    def test_ReadCollection_getName(self):
        self.assertEqual(PrimaryOnly, NGS.openReadCollection(PrimaryOnly).getName())

    def test_ReadCollection_getReadGroup(self):
        gr = NGS.openReadCollection(PrimaryOnly).getReadGroup("C1ELY.6")

    def test_ReadCollection_getReadGroups(self):
        it = NGS.openReadCollection(PrimaryOnly).getReadGroups()

    def test_ReadCollection_getReferences(self):
        it = NGS.openReadCollection(PrimaryOnly).getReferences()

    def test_ReadCollection_getReference(self):
        ref = NGS.openReadCollection(PrimaryOnly).getReference("supercont2.1")

    def test_ReadCollection_hasReference(self):
        assert ( NGS.openReadCollection(PrimaryOnly).hasReference("supercont2.1") )
        assert ( not NGS.openReadCollection(PrimaryOnly).hasReference("non-existent acc") )

    def test_ReadCollection_getAlignment(self):
        al = NGS.openReadCollection(PrimaryOnly).getAlignment(PrimaryOnly + ".PA.1")

    def test_ReadCollection_getAlignments_Primary(self):
        alIt = NGS.openReadCollection(PrimaryOnly).getAlignments(Alignment.primaryAlignment)

    def test_ReadCollection_getAlignments_Secondary(self):
        alIt = NGS.openReadCollection(PrimaryOnly).getAlignments(Alignment.secondaryAlignment)

    def test_ReadCollection_getAlignments_all(self):
        alIt = NGS.openReadCollection(PrimaryOnly).getAlignments(Alignment.all)

    def test_ReadCollection_getAlignmentCount_PrimaryOnly(self):
        self.assertEqual(3987701, NGS.openReadCollection(PrimaryOnly).getAlignmentCount())

    def test_ReadCollection_getAlignmentCount_PrimaryOnly_Primary(self):
        self.assertEqual(3987701, NGS.openReadCollection(PrimaryOnly).getAlignmentCount(Alignment.primaryAlignment))

    def test_ReadCollection_getAlignmentCount_PrimaryOnly_Secondary(self):
        self.assertEqual(0, NGS.openReadCollection(PrimaryOnly).getAlignmentCount(Alignment.secondaryAlignment))

    def test_ReadCollection_getAlignmentCount_PrimaryOnly_All(self):
        self.assertEqual(3987701, NGS.openReadCollection(PrimaryOnly).getAlignmentCount(Alignment.all))

    def test_ReadCollection_getAlignmentCount_WithSecondary(self):
        self.assertEqual(178, NGS.openReadCollection(WithSecondary).getAlignmentCount())

    def test_ReadCollection_getAlignmentCount_WithSecondary_Primary(self):
        self.assertEqual(168, NGS.openReadCollection(WithSecondary).getAlignmentCount(Alignment.primaryAlignment))

    def test_ReadCollection_getAlignmentCount_WithSecondary_Secondary(self):
        self.assertEqual(10, NGS.openReadCollection(WithSecondary).getAlignmentCount(Alignment.secondaryAlignment))

    def test_ReadCollection_getAlignmentCount_WithSecondary_All(self):
        self.assertEqual(178, NGS.openReadCollection(WithSecondary).getAlignmentCount(Alignment.all))

    def test_ReadCollection_getAlignmentRange(self):
        # straddling primary and secondary alignments
        alIt = NGS.openReadCollection(WithSecondary).getAlignmentRange(166, 5)
        self.assertTrue(alIt.nextAlignment())
        self.assertEqual(WithSecondary + ".PA.166", alIt.getAlignmentId())

    def test_ReadCollection_getRead(self):
        read = NGS.openReadCollection(PrimaryOnly).getRead(PrimaryOnly + ".R.1")
        self.assertEqual(PrimaryOnly + ".R.1", read.getReadId())

    def test_ReadCollection_getReads(self):
        readIt = NGS.openReadCollection(PrimaryOnly).getReads(Read.all)
        self.assertTrue(readIt.nextRead())
        self.assertEqual(PrimaryOnly + ".R.1", readIt.getReadId())

    def test_ReadCollection_getReadCount(self):
        self.assertEqual(2280633, NGS.openReadCollection(PrimaryOnly).getReadCount())

    def test_ReadCollection_getReadRange(self):
        readIt = NGS.openReadCollection(PrimaryOnly).getReadRange(2, 3)
        self.assertTrue(readIt.nextRead())
        self.assertEqual(PrimaryOnly + ".R.2", readIt.getReadId())


# Read

    def test_Read_getReadCategory_full(self):
        self.assertEqual(Read.fullyAligned, getRead(PrimaryOnly + ".R.1").getReadCategory())

    def test_Read_getReadCategory_partial(self):
        self.assertEqual(Read.partiallyAligned, getRead(PrimaryOnly + ".R.3").getReadCategory())

    def test_Read_getNumFragments(self):
        self.assertEqual(2, getRead(PrimaryOnly + ".R.1").getNumFragments())

    def test_Read_fragmentIsAligned_partial(self):
        read = NGS.openReadCollection(PrimaryOnly).getRead(PrimaryOnly + ".R.3")
        self.assertEqual(True, read.fragmentIsAligned(0))
        self.assertEqual(False, read.fragmentIsAligned(1))

# FragmentIterator
    def test_FragmentIterator_ThrowsBeforeNext(self):
        try:
            getRead(PrimaryOnly + ".R.1").getFragmentId()
            self.fail()
        except ErrorMsg:
            pass

    def test_FragmentIterator_Next(self):
        read = getRead(PrimaryOnly + ".R.1")
        self.assertTrue(read.nextFragment())
        read.getReadCategory() # does not throw

# Fragment
    def test_Read_getFragmentId(self):
        read = getRead(PrimaryOnly + ".R.1")
        self.assertTrue(read.nextFragment())
        self.assertEqual(PrimaryOnly + ".FR0.1", read.getFragmentId())

    def test_getFragmentBases(self):
        read = getRead(PrimaryOnly + ".R.1")
        self.assertTrue(read.nextFragment())
        self.assertTrue(read.nextFragment())
        self.assertEqual("GGTA", read.getFragmentBases(2, 4));

    def test_getFragmentQualities(self):
        read = getRead(PrimaryOnly + ".R.1")
        self.assertTrue(read.nextFragment())
        self.assertTrue(read.nextFragment())
        self.assertEqual("@DDA", read.getFragmentQualities(2, 4))


# Alignment

    def test_Alignment_getAlignmentId(self):
        self.assertEqual(PrimaryOnly + ".PA.1", getAlignment(PrimaryOnly + ".PA.1").getAlignmentId())

    def test_Alignment_getReferenceSpec(self):
        self.assertEqual("supercont2.1", getAlignment(PrimaryOnly + ".PA.1").getReferenceSpec())

    def test_Alignment_getMappingQuality(self):
        self.assertEqual(60, getAlignment(PrimaryOnly + ".PA.1").getMappingQuality())

    def test_Alignment_getReferenceBases(self):
        self.assertEqual("ACTCGACATTCTGTCTTCGACCTATCTTTCTCCTCTCCCAGTCATCGCCCAGTAGAATTACCAGGCAATGAACCACGGCCTTTCATCCCAACGGCACAGCA",
                      getAlignment(PrimaryOnly + ".PA.1").getReferenceBases())

    def test_Alignment_getReadGroup(self):
        self.assertEqual("C1ELY.6", getAlignment(PrimaryOnly + ".PA.1").getReadGroup())

    def test_Alignment_getReadId(self):
        self.assertEqual(PrimaryOnly + ".R.165753", getAlignment(PrimaryOnly + ".PA.5").getReadId())

    def test_Alignment_getFragmentId(self):
        self.assertEqual(PrimaryOnly + ".FA0.1", getAlignment(PrimaryOnly + ".PA.1").getFragmentId())

    def test_Alignment_getFragmentBases_Raw(self):
        self.assertEqual("TGGATGCTCTGGAAAATCTGAAAAGTGGTGTTTGTAAGGTTTGCTGGCTGCCCATATACCACATGGATGATGGGGCTTTCCATTTTAATGTTGAAGGAGGA",
                      getAlignment(PrimaryOnly + ".PA.4").getFragmentBases())

    def test_Alignment_getFragmentQualities_Raw(self):
        self.assertEqual("######AA>55;5(;63;;3@;A9??;6..73CDCIDA>DCB>@B=;@B?;;ADAB<DD?1*>@C9:EC?2++A3+F4EEB<E>EEIEDC2?C:;AB+==1",
                      getAlignment(PrimaryOnly + ".PA.4").getFragmentQualities())

    def test_Alignment_getFragmentBases_Clipped(self):
        self.assertEqual("CTTCAACATTAAAATGGAAAGCCCCATCATCCATGTGGTATATGGGCAGCCAGCAAACCTTACAAACACCACTTTTCAGATTTTCCAGAGCATCCA",
                      getAlignment(PrimaryOnly + ".PA.4").getClippedFragmentBases())

    def test_Alignment_getFragmentQualities_Clipped(self):
        self.assertEqual("#AA>55;5(;63;;3@;A9??;6..73CDCIDA>DCB>@B=;@B?;;ADAB<DD?1*>@C9:EC?2++A3+F4EEB<E>EEIEDC2?C:;AB+==1",
                      getAlignment(PrimaryOnly + ".PA.4").getClippedFragmentQualities())

    def test_Alignment_getAlignedFragmentBases(self):
        self.assertEqual("ATATGGGTTCACTCCAACAGTGAACCATTCCAAAAGACCTTGCCTGCGTGGCCATCTCCTCACAAACCCACCATCCCGCAACATCTCAGGTATCATACCTT",
                      getAlignment(PrimaryOnly + ".PA.2").getAlignedFragmentBases())

    def test_Alignment_getAlignmentCategory(self):
        self.assertEqual(Alignment.primaryAlignment, getAlignment(PrimaryOnly + ".PA.4").getAlignmentCategory())

    def test_Alignment_getAlignmentPosition(self):
        self.assertEqual(85, getAlignment(PrimaryOnly + ".PA.1").getAlignmentPosition())

    def test_Alignment_getAlignmentLength(self):
        self.assertEqual(101, getAlignment(PrimaryOnly + ".PA.1").getAlignmentLength())

    def test_Alignment_getIsReversedOrientation_False(self):
        self.assertFalse(getAlignment(PrimaryOnly + ".PA.1").getIsReversedOrientation())

    def test_Alignment_getIsReversedOrientation_True(self):
        self.assertTrue(getAlignment(PrimaryOnly + ".PA.2").getIsReversedOrientation())

    def test_Alignment_getSoftClip_None(self):
        al = getAlignment(PrimaryOnly + ".PA.1")
        self.assertEqual(0, al.getSoftClip(Alignment.clipLeft))
        self.assertEqual(0, al.getSoftClip(Alignment.clipRight))

    def test_Alignment_getSoftClip_Left(self):
        al = getAlignment(PrimaryOnly + ".PA.4")
        self.assertEqual(5, al.getSoftClip(Alignment.clipLeft))
        self.assertEqual(0, al.getSoftClip(Alignment.clipRight))

    def test_Alignment_getSoftClip_Right(self):
        al = getAlignment(PrimaryOnly + ".PA.10")
        self.assertEqual(0,  al.getSoftClip(Alignment.clipLeft))
        self.assertEqual(13, al.getSoftClip(Alignment.clipRight))

    def test_Alignment_getTemplateLength(self):
        self.assertEqual(201, getAlignment(PrimaryOnly + ".PA.1").getTemplateLength())

    def test_Alignment_getShortCigar_Unclipped(self):
        self.assertEqual("5S96M", getAlignment(PrimaryOnly + ".PA.4").getShortCigar(False))

    def test_Alignment_getShortCigar_Clipped(self):
        self.assertEqual("96M", getAlignment(PrimaryOnly + ".PA.4").getShortCigar(True))

    def test_Alignment_getLongCigar_Unclipped(self):
        self.assertEqual("5S1X8=1X39=1X46=", getAlignment(PrimaryOnly + ".PA.4").getLongCigar(False))

    def test_Alignment_getLongCigar_Clipped(self):
        self.assertEqual("1X8=1X39=1X46=", getAlignment(PrimaryOnly + ".PA.4").getLongCigar(True))

    def test_Alignment_hasMate_Primary_No(self):
        self.assertFalse(getAlignment(PrimaryOnly + ".PA.99").hasMate())

    def test_Alignment_hasMate_Primary_Yes(self):
        self.assertTrue(getAlignment(PrimaryOnly + ".PA.1").hasMate())

    def test_Alignment_hasMate_Secondary(self):
        self.assertFalse(getSecondaryAlignment(WithSecondary + ".SA.169").hasMate())

    def test_Alignment_getMateAlignmentId(self):
        self.assertEqual(PrimaryOnly + ".PA.2", getAlignment(PrimaryOnly + ".PA.1").getMateAlignmentId())

    def test_Alignment_getMateAlignmentId_Missing(self):
        try:
            getAlignment(PrimaryOnly + ".PA.99").getMateAlignmentId()
            self.fail()
        except ErrorMsg:
            pass

    def test_Alignment_getMateAlignmentId_SecondaryThrows(self):
        try:
            getSecondaryAlignment(WithSecondary + ".SA.172").getMateAlignmentId()
            self.fail()
        except ErrorMsg:
            pass

    def test_Alignment_getMateAlignment(self):
        self.assertEqual(PrimaryOnly + ".PA.2", getAlignment(PrimaryOnly + ".PA.1").getMateAlignment().getAlignmentId())

    def test_Alignment_getMateAlignment_Missing(self):
        try:
            getAlignment(PrimaryOnly + ".PA.99").getMateAlignment()
            self.fail()
        except ErrorMsg:
            pass

    def test_Alignment_getMateAlignment_SecondaryThrows(self):
        try:
            getSecondaryAlignment(WithSecondary +".SA.172").getMateAlignment ()
            self.fail()
        except ErrorMsg:
            pass

    def test_Alignment_getMateReferenceSpec(self):
        self.assertEqual("supercont2.1",  getAlignment(PrimaryOnly + ".PA.1").getMateReferenceSpec())

    def test_Alignment_getMateIsReversedOrientation_Yes(self):
        self.assertTrue(getAlignment(PrimaryOnly + ".PA.1").getMateIsReversedOrientation())

    def test_Alignment_getMateIsReversedOrientation_No(self):
        self.assertFalse(getAlignment(PrimaryOnly + ".PA.2").getMateIsReversedOrientation())

    def test_Alignment_isPaired_MultiFragmentsPerSpot(self):
        readCollection = NGS.openReadCollection(PrimaryOnly)
        alignment = readCollection.getAlignment(PrimaryOnly + ".PA.1")
        self.assertTrue(alignment.isPaired())

        alignment = readCollection.getAlignment(PrimaryOnly + ".PA.2")
        self.assertTrue(alignment.isPaired())

        # has unaligned mate
        alignment = readCollection.getAlignment (PrimaryOnly + ".PA.6")
        self.assertTrue(alignment.isPaired())

    def test_Alignment_isPaired_SingleFragmentPerSpot(self):
        readCollection = NGS.openReadCollection(SingleFragmentPerSpot)
        alignment = readCollection.getAlignment(SingleFragmentPerSpot + ".PA.1")
        self.assertFalse(alignment.isPaired())

# ReferenceSequence
    def test_ReferenceSequence_getCanonicalName(self):
        self.assertEqual("gi|218511148|ref|NC_011752.1|", getReferenceSequence().getCanonicalName())

    def test_ReferenceSequence_getIsCircular_Yes(self):
        self.assertTrue(getReferenceSequence().getIsCircular())

    def test_ReferenceSequence_getLength(self):
        self.assertEqual(72482, getReferenceSequence().getLength())

    def test_ReferenceSequence_getReferenceBases(self):
        self.assertEqual("ATAAA", getReferenceSequence().getReferenceBases(72482 - 5))

    def test_ReferenceSequence_getReferenceBases_Length(self):
        self.assertEqual("TACA", getReferenceSequence().getReferenceBases(4998, 4))

    def test_ReferenceSequence_getReferenceChunk(self):
        self.assertEqual("TAATA", getReferenceSequence().getReferenceChunk(5000 - 5, 5))

    def test_ReferenceSequence_getReferenceChunk_Length (self):
        self.assertEqual("TAATA", getReferenceSequence().getReferenceChunk(5000 - 5, 10))

# Reference
    def test_Reference_getCommonName(self):
        self.assertEqual("supercont2.1", getReference().getCommonName())

    def test_Reference_getCanonicalName(self):
        self.assertEqual("NC_000007.13", NGS.openReadCollection("SRR821492").getReference("chr7").getCanonicalName())

    def test_Reference_getIsCircular_No(self):
        self.assertFalse(getReference().getIsCircular())

    def test_Reference_getIsCircular_Yes(self):
        self.assertTrue(NGS.openReadCollection("SRR821492").getReference("chrM").getIsCircular())

    def test_Reference_getIsLocal_Yes(self):
        self.assertTrue(getReference().getIsLocal())

    def test_Reference_getIsLocal_No(self):
        self.assertFalse(NGS.openReadCollection("SRR821492").getReference("chrM").getIsLocal())

    def test_Reference_getLength(self):
        self.assertEqual(2291499, getReference().getLength())

    def test_Reference_getReferenceBases(self):
        self.assertEqual("ATCTG", getReference().getReferenceBases(2291499 - 5))

    def test_Reference_getReferenceBases_Length(self):
        self.assertEqual("GCGCTATGAC", getReference().getReferenceBases(9000, 10))

    def test_Reference_getReferenceChunk(self):
        self.assertEqual("CTAGG", getReference().getReferenceChunk(5000 - 5, 5))

    def test_Reference_getReferenceChunk_Length (self):
        self.assertEqual("GCGCTATGAC", getReference().getReferenceChunk(9000, 10))

    def test_Reference_getAlignment(self):
        self.assertEqual(PrimaryOnly + ".PA.1", getReference().getAlignment(PrimaryOnly + ".PA.1").getAlignmentId())

#TODO: getAlignmentCount
#TODO: getAlignmentCount_Filtered

#TODO: getPileups
#TODO: getPileupRange
#TODO: getPileupRange_Filtered

# ReferenceIterator

    def test_ReferenceIterator_ThrowBeforeNext(self):
        it = NGS.openReadCollection(PrimaryOnly).getReferences()
        try:
            it.getCommonName()
            self.fail()
        except ErrorMsg:
            pass

    def test_ReferenceIterator_Next(self):
        it = NGS.openReadCollection(PrimaryOnly).getReferences()
        self.assertTrue(it.nextReference())
        self.assertEqual("supercont2.1", it.getCommonName())

# AlignmentIterator from Reference (ReferenceWindow)
    def test_ReferenceWindow(self):
        it = NGS.openReadCollection(WithSecondary).getReference("gi|169794206|ref|NC_010410.1|").getAlignments(Alignment.all)
        self.assertTrue(it.nextAlignment())

        # the first 2 secondary alignments' locations on the list: #34, #61
        count = 1;
        while it.nextAlignment():
            if it.getAlignmentCategory() == Alignment.secondaryAlignment:
                break
            count += 1

        self.assertEqual(34, count)
        while it.nextAlignment():
            if it.getAlignmentCategory() == Alignment.secondaryAlignment:
                break
            count += 1

        self.assertEqual(61, count)

    def test_ReferenceWindow_Slice(self):
        it = NGS.openReadCollection(WithSecondary).getReference("gi|169794206|ref|NC_010410.1|").getAlignmentSlice(516000, 100000)
        self.assertTrue(it.nextAlignment())
        self.assertEqual(WithSecondary + ".PA.33", it.getAlignmentId())
        self.assertTrue(it.nextAlignment())
        self.assertEqual(WithSecondary + ".PA.34", it.getAlignmentId())
        self.assertTrue(it.nextAlignment())
        self.assertEqual(WithSecondary + ".SA.169", it.getAlignmentId()) #secondary
        self.assertTrue(it.nextAlignment())
        self.assertEqual(WithSecondary + ".PA.35", it.getAlignmentId())
        self.assertFalse(it.nextAlignment())

    def test_ReferenceWindow_Slice_Filtered_Category (self):
        it = NGS.openReadCollection(WithSecondary).getReference("gi|169794206|ref|NC_010410.1|").getAlignmentSlice(516000, 100000, Alignment.primaryAlignment)
        self.assertTrue(it.nextAlignment())
        self.assertEqual(WithSecondary + ".PA.33", it. getAlignmentId())
        self.assertTrue(it.nextAlignment())
        self.assertEqual(WithSecondary + ".PA.34", it. getAlignmentId())
        self.assertTrue(it.nextAlignment())
        self.assertEqual(WithSecondary + ".PA.35", it. getAlignmentId()) # no secondary
        self.assertFalse(it.nextAlignment())

    def test_ReferenceWindow_Slice_Filtered_Start_Within_Slice (self):
        ref = NGS.openReadCollection(WithCircularRef).getReference("NC_012920.1")
        it = ref.getFilteredAlignmentSlice(0, ref.getLength(), Alignment.all, Alignment.startWithinSlice, 0)

        self.assertTrue(it.nextAlignment())
        lastAlignmentPosition = it.getAlignmentPosition()
        while it.nextAlignment():
            currentPosition = it.getAlignmentPosition()
            errorMsg = "Sorting violated. Last position (" + str(lastAlignmentPosition) + ") is higher than current one (" + str(currentPosition) + ")"
            self.assertTrue ( lastAlignmentPosition <= currentPosition, errorMsg )
            lastAlignmentPosition = currentPosition

    # ReadGroup
    def test_ReadGroup_getName(self):
        gr = NGS.openReadCollection(PrimaryOnly).getReadGroup("C1ELY.6")
        self.assertEqual("C1ELY.6", gr.getName())

    def test_ReadGroup_has(self):
        assert ( NGS.openReadCollection(PrimaryOnly).hasReadGroup("C1ELY.6") )
        assert ( not NGS.openReadCollection(PrimaryOnly).hasReadGroup("non-existent read group") )

    def test_ReadGroup_getStatistics(self):
        gr = NGS.openReadCollection(WithGroups).getReadGroup("GS57510-FS3-L03")

        stats = gr.getStatistics()

        self.assertEqual(34164461870, stats.getAsU64("BASE_COUNT"))
        self.assertEqual(34164461870, stats.getAsU64("BIO_BASE_COUNT"))
        self.assertEqual(488063741,   stats.getAsU64("SPOT_COUNT"))
        self.assertEqual(5368875807,  stats.getAsU64("SPOT_MAX"))
        self.assertEqual(4880812067,  stats.getAsU64("SPOT_MIN"))

    # def test_ReadGroup_getRead(self):
        # gr = NGS.openReadCollection(PrimaryOnly).getReadGroup("C1ELY.6")
        # r = gr.getRead(PrimaryOnly + ".R.1")
        # self.assertEqual("C1ELY.6", r.getReadGroup())

    # def test_ReadGroup_getReads(self):
        # gr = NGS.openReadCollection(PrimaryOnly).getReadGroup("C1ELY.6")
        # r = gr.getReads(Read.partiallyAligned)

    # ReadGroupIterator
    def test_ReadGroupIterator_ThrowBeforeNext(self):
        it = NGS.openReadCollection(PrimaryOnly).getReadGroups()
        try:
            it.getName()
            self.fail()
        except ErrorMsg:
            pass

    def test_ReadGroupIterator_Next(self):
        it = NGS.openReadCollection(PrimaryOnly).getReadGroups();
        self.assertTrue(it.nextReadGroup());
        name = it.getName();

if __name__ == "__main__":
    unittest.main()