File: TestFilter.cpp

package info (click to toggle)
libstatgen 1.0.15-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,588 kB
  • sloc: cpp: 49,624; ansic: 1,408; makefile: 320; sh: 60
file content (126 lines) | stat: -rw-r--r-- 4,864 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
/*
 *  Copyright (C) 2011  Regents of the University of Michigan
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "TestFilter.h"
#include "TestValidate.h"
#include "SamFilter.h"
#include <assert.h>

void testFilter()
{
    // Call generic test which since the sam and bam are identical, should
    // contain the same results.
    FilterTest::testFilter(FilterTest::SAM);
#ifdef __ZLIB_AVAILABLE__
    FilterTest::testFilter(FilterTest::BAM);
#endif
}


void FilterTest::testFilter(FileType inputType)
{
    SamFile inSam;

    if(inputType == SAM)
    {
        assert(inSam.OpenForRead("testFiles/testSam.sam"));
    }
    else
    {
        assert(inSam.OpenForRead("testFiles/testBam.bam"));
    }

   // Read the SAM Header.
    SamFileHeader samHeader;
    assert(inSam.ReadHeader(samHeader));
    validateHeader(samHeader);

    SamRecord samRecord;
    assert(inSam.ReadRecord(samHeader, samRecord) == true);
    validateRead1(samRecord);

    // Clip the read, 2 from the front and 2 from the back, which causes 2D to
    // be dropped.
    assert(SamFilter::softClip(samRecord, 2, 2) == SamFilter::CLIPPED);
    assert(samRecord.get0BasedPosition() == TestValidate::READ1_POS + 2);
    std::string expectedCigar = "2S1M2S";
    assert(samRecord.getCigar() == expectedCigar);
    assert(samRecord.getSequence() == TestValidate::READ1_SEQ);
    assert(samRecord.getQuality() == TestValidate::READ1_QUAL);
    // Only 1 base, so the end is the same as start
    assert(samRecord.get0BasedAlignmentEnd() == TestValidate::READ1_POS + 2);
    assert(samRecord.getAlignmentLength() == 1);
    assert(samRecord.get0BasedUnclippedStart() == TestValidate::READ1_UNCLIP_START);
    // The new unclipped end is not the same as the original end because the
    // 2 deletions are lost.
    assert(samRecord.get0BasedUnclippedEnd() == TestValidate::READ1_UNCLIP_END - 2);


    assert(inSam.ReadRecord(samHeader, samRecord) == true);
    validateRead2(samRecord);

    assert(inSam.ReadRecord(samHeader, samRecord) == true);
    validateRead3(samRecord);

    assert(inSam.ReadRecord(samHeader, samRecord) == true);
    validateRead4(samRecord);

    assert(inSam.ReadRecord(samHeader, samRecord) == true);
    validateRead5(samRecord);

    assert(inSam.ReadRecord(samHeader, samRecord) == true);
    validateRead6(samRecord);

    // Clip the read 2 more from the front and 2 from the back.
    assert(SamFilter::softClip(samRecord, 5, 2) == SamFilter::CLIPPED);
    assert(samRecord.get0BasedPosition() == TestValidate::READ6_POS + 2);
    expectedCigar = "2H5S1M2S";
    assert(samRecord.getCigar() == expectedCigar);
    assert(samRecord.getSequence() == TestValidate::READ6_SEQ);
    assert(samRecord.getQuality() == TestValidate::READ6_QUAL);
    // Only 1 base, so the end is the same as start
    assert(samRecord.get0BasedAlignmentEnd() == TestValidate::READ6_POS + 2);
    assert(samRecord.getAlignmentLength() == 1);
    assert(samRecord.get0BasedUnclippedStart() == TestValidate::READ6_UNCLIP_START);
    assert(samRecord.get0BasedUnclippedEnd() == TestValidate::READ6_UNCLIP_END);

    assert(inSam.ReadRecord(samHeader, samRecord) == true);
    validateRead7(samRecord);

    // Clip the read 2 more from the front and 2 morefrom the back.
    assert(SamFilter::softClip(samRecord, 5, 3) == SamFilter::CLIPPED);
    assert(samRecord.get0BasedPosition() == TestValidate::READ7_POS + 2);
    expectedCigar = "5S1M3S3H";
    assert(samRecord.getCigar() == expectedCigar);
    assert(samRecord.getSequence() == TestValidate::READ7_SEQ);
    assert(samRecord.getQuality() == TestValidate::READ7_QUAL);
    // Only 1 base, so the end is the same as start
    assert(samRecord.get0BasedAlignmentEnd() == TestValidate::READ7_POS + 2);
    assert(samRecord.getAlignmentLength() == 1);
    assert(samRecord.get0BasedUnclippedStart() == TestValidate::READ7_UNCLIP_START);
    assert(samRecord.get0BasedUnclippedEnd() == TestValidate::READ7_UNCLIP_END);

    assert(inSam.ReadRecord(samHeader, samRecord) == true);
    validateRead8(samRecord);

    assert(inSam.ReadRecord(samHeader, samRecord) == true);
    validateRead9(samRecord);

    assert(inSam.ReadRecord(samHeader, samRecord) == true);
    validateRead10(samRecord);
}