TestFilter.cpp

00001 /*
00002  *  Copyright (C) 2011  Regents of the University of Michigan
00003  *
00004  *   This program is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #include "TestFilter.h"
00019 #include "Validate.h"
00020 #include "SamFilter.h"
00021 #include <assert.h>
00022 
00023 void testFilter()
00024 {
00025     // Call generic test which since the sam and bam are identical, should
00026     // contain the same results.
00027     FilterTest::testFilter(FilterTest::SAM);
00028     FilterTest::testFilter(FilterTest::BAM);
00029 }
00030 
00031 
00032 void FilterTest::testFilter(FileType inputType)
00033 {
00034     SamFile inSam;
00035 
00036     if(inputType == SAM)
00037     {
00038         assert(inSam.OpenForRead("testFiles/testSam.sam"));
00039     }
00040     else
00041     {
00042         assert(inSam.OpenForRead("testFiles/testBam.bam"));
00043     }
00044 
00045    // Read the SAM Header.
00046     SamFileHeader samHeader;
00047     assert(inSam.ReadHeader(samHeader));
00048     validateHeader(samHeader);
00049 
00050     SamRecord samRecord;
00051     assert(inSam.ReadRecord(samHeader, samRecord) == true);
00052     validateRead1(samRecord);
00053 
00054     // Clip the read, 2 from the front and 2 from the back, which causes 2D to
00055     // be dropped.
00056     assert(SamFilter::softClip(samRecord, 2, 2) == SamFilter::CLIPPED);
00057     assert(samRecord.get0BasedPosition() == Validate::READ1_POS + 2);
00058     std::string expectedCigar = "2S1M2S";
00059     assert(samRecord.getCigar() == expectedCigar);
00060     assert(samRecord.getSequence() == Validate::READ1_SEQ);
00061     assert(samRecord.getQuality() == Validate::READ1_QUAL);
00062     // Only 1 base, so the end is the same as start
00063     assert(samRecord.get0BasedAlignmentEnd() == Validate::READ1_POS + 2);
00064     assert(samRecord.getAlignmentLength() == 1);
00065     assert(samRecord.get0BasedUnclippedStart() == Validate::READ1_UNCLIP_START);
00066     // The new unclipped end is not the same as the original end because the
00067     // 2 deletions are lost.
00068     assert(samRecord.get0BasedUnclippedEnd() == Validate::READ1_UNCLIP_END - 2);
00069 
00070 
00071     assert(inSam.ReadRecord(samHeader, samRecord) == true);
00072     validateRead2(samRecord);
00073 
00074     assert(inSam.ReadRecord(samHeader, samRecord) == true);
00075     validateRead3(samRecord);
00076 
00077     assert(inSam.ReadRecord(samHeader, samRecord) == true);
00078     validateRead4(samRecord);
00079 
00080     assert(inSam.ReadRecord(samHeader, samRecord) == true);
00081     validateRead5(samRecord);
00082 
00083     assert(inSam.ReadRecord(samHeader, samRecord) == true);
00084     validateRead6(samRecord);
00085 
00086     // Clip the read 2 more from the front and 2 from the back.
00087     assert(SamFilter::softClip(samRecord, 5, 2) == SamFilter::CLIPPED);
00088     assert(samRecord.get0BasedPosition() == Validate::READ6_POS + 2);
00089     expectedCigar = "2H5S1M2S";
00090     assert(samRecord.getCigar() == expectedCigar);
00091     assert(samRecord.getSequence() == Validate::READ6_SEQ);
00092     assert(samRecord.getQuality() == Validate::READ6_QUAL);
00093     // Only 1 base, so the end is the same as start
00094     assert(samRecord.get0BasedAlignmentEnd() == Validate::READ6_POS + 2);
00095     assert(samRecord.getAlignmentLength() == 1);
00096     assert(samRecord.get0BasedUnclippedStart() == Validate::READ6_UNCLIP_START);
00097     assert(samRecord.get0BasedUnclippedEnd() == Validate::READ6_UNCLIP_END);
00098 
00099     assert(inSam.ReadRecord(samHeader, samRecord) == true);
00100     validateRead7(samRecord);
00101 
00102     // Clip the read 2 more from the front and 2 morefrom the back.
00103     assert(SamFilter::softClip(samRecord, 5, 3) == SamFilter::CLIPPED);
00104     assert(samRecord.get0BasedPosition() == Validate::READ7_POS + 2);
00105     expectedCigar = "5S1M3S3H";
00106     assert(samRecord.getCigar() == expectedCigar);
00107     assert(samRecord.getSequence() == Validate::READ7_SEQ);
00108     assert(samRecord.getQuality() == Validate::READ7_QUAL);
00109     // Only 1 base, so the end is the same as start
00110     assert(samRecord.get0BasedAlignmentEnd() == Validate::READ7_POS + 2);
00111     assert(samRecord.getAlignmentLength() == 1);
00112     assert(samRecord.get0BasedUnclippedStart() == Validate::READ7_UNCLIP_START);
00113     assert(samRecord.get0BasedUnclippedEnd() == Validate::READ7_UNCLIP_END);
00114 
00115     assert(inSam.ReadRecord(samHeader, samRecord) == true);
00116     validateRead8(samRecord);
00117 
00118     assert(inSam.ReadRecord(samHeader, samRecord) == true);
00119     validateRead9(samRecord);
00120 
00121     assert(inSam.ReadRecord(samHeader, samRecord) == true);
00122     validateRead10(samRecord);
00123 }
00124 
Generated on Tue Aug 23 18:19:04 2011 for libStatGen Software by  doxygen 1.6.3