Modify.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "SamFile.h"
00019 #include "Modify.h"
00020
00021 void testModify()
00022 {
00023 modify modTest;
00024 modTest.testModify("testFiles/testSam.sam");
00025 modTest.testModify("testFiles/testBam.bam");
00026
00027
00028 }
00029
00030
00031 void modify::testModify(const char* filename)
00032 {
00033 myFilename = filename;
00034
00035 modifyPosition();
00036 modifyCigar();
00037
00038 modifyTags();
00039 }
00040
00041 void modify::modifyPosition()
00042 {
00043 openAndRead1Rec();
00044
00045
00046 assert(samRecord.getBin() == 4681);
00047
00048
00049 assert(samRecord.set0BasedPosition(33768));
00050
00051
00052 assert(samRecord.getBin() == 4683);
00053 assert(samRecord.get0BasedPosition() == 33768);
00054 }
00055
00056
00057 void modify::modifyCigar()
00058 {
00059 openAndRead1Rec();
00060
00061
00062 assert(samRecord.getBin() == 4681);
00063
00064
00065 assert(samRecord.setCigar("33768M"));
00066
00067
00068 assert(samRecord.getBin() == 585);
00069 }
00070
00071
00072 void modify::openAndRead1Rec()
00073 {
00074
00075 assert(samIn.OpenForRead(myFilename.c_str()));
00076
00077
00078 assert(samIn.ReadHeader(samHeader));
00079
00080
00081 assert(samIn.ReadRecord(samHeader, samRecord));
00082 }
00083
00084
00085 void modify::modifyTags()
00086 {
00087 assert(samIn.OpenForRead(myFilename.c_str()));
00088
00089 assert(samIn.ReadHeader(samHeader));
00090
00091 SamFile samOut;
00092 SamFile bamOut;
00093
00094 std::string inputType = myFilename.substr(myFilename.find_last_of('.'));
00095 std::string outFileBase = "results/updateTagFrom";
00096 if(inputType == ".bam")
00097 {
00098 outFileBase += "Bam";
00099 }
00100 else
00101 {
00102 outFileBase += "Sam";
00103 }
00104
00105 std::string outFile = outFileBase + ".sam";
00106 assert(samOut.OpenForWrite(outFile.c_str()));
00107 outFile = outFileBase + ".bam";
00108 assert(bamOut.OpenForWrite(outFile.c_str()));
00109 assert(samOut.WriteHeader(samHeader));
00110 assert(bamOut.WriteHeader(samHeader));
00111
00112 int count = 0;
00113
00114 while(samIn.ReadRecord(samHeader, samRecord))
00115 {
00116 if((count == 0) || (count == 4))
00117 {
00118 assert(samRecord.rmTag("MD", 'Z'));
00119 }
00120 else if(count == 2)
00121 {
00122 assert(samRecord.rmTags("XT:A;MD:Z;AB:c;NM:i"));
00123 }
00124
00125 assert(bamOut.WriteRecord(samHeader, samRecord));
00126 assert(samOut.WriteRecord(samHeader, samRecord));
00127 ++count;
00128 }
00129
00130 }