25 modTest.testModify(
"testFiles/testSam.sam");
26 #ifdef __ZLIB_AVAILABLE__
27 modTest.testModify(
"testFiles/testBam.bam");
32 void modify::testModify(
const char* filename)
34 myFilename = filename;
44 void modify::modifyPosition()
49 assert(samRecord.
getBin() == 4681);
55 assert(samRecord.
getBin() == 4683);
60 void modify::modifyCigar()
65 assert(samRecord.
getBin() == 4681);
68 assert(samRecord.
setCigar(
"33768M"));
71 assert(samRecord.
getBin() == 585);
75 void modify::modifyFlag()
81 assert(samRecord.
getFlag() == flag);
85 assert(samRecord.
setFlag(flag));
86 assert(samRecord.
getFlag() == 1097);
90 assert(samRecord.
setFlag(flag));
91 assert(samRecord.
getFlag() == 73);
95 void modify::openAndRead1Rec()
104 assert(samIn.
ReadRecord(samHeader, samRecord));
108 void modify::modifyTags()
117 std::string inputType = myFilename.substr(myFilename.find_last_of(
'.'));
118 std::string outFileBase =
"results/updateTagFrom";
119 if(inputType ==
".bam")
121 outFileBase +=
"Bam";
125 outFileBase +=
"Sam";
128 std::string outFile = outFileBase +
".sam";
130 outFile = outFileBase +
".bam";
141 assert(samRecord.
rmTag(
"MD",
'Z'));
145 assert(samRecord.
rmTags(
"XT:A;MD:Z;AB:c;NM:i"));
149 assert(samRecord.
rmTags(
"MD:Z,AB:c,NM:i"));
Allows the user to easily read/write a SAM/BAM file.
bool ReadHeader(SamFileHeader &header)
Reads the header section from the file and stores it in the passed in header.
bool ReadRecord(SamFileHeader &header, SamRecord &record)
Reads the next record from the file & stores it in the passed in record.
bool OpenForRead(const char *filename, SamFileHeader *header=NULL)
Open a sam/bam file for reading with the specified filename, determing the type of file and SAM/BAM b...
bool OpenForWrite(const char *filename, SamFileHeader *header=NULL)
Open a sam/bam file for writing with the specified filename, determining SAM/BAM from the extension (...
bool WriteHeader(SamFileHeader &header)
Writes the specified header into the file.
bool WriteRecord(SamFileHeader &header, SamRecord &record)
Writes the specified record into the file.
static void setNotDuplicate(uint16_t &flag)
Mark the passed in flag as not duplicate.
static void setDuplicate(uint16_t &flag)
Mark the passed in flag as not duplicate.
bool rmTag(const char *tag, char type)
Remove a tag.
uint16_t getBin()
Get the BAM bin for the record.
bool setFlag(uint16_t flag)
Set the bitwise FLAG to the specified value.
uint16_t getFlag()
Get the flag (FLAG).
bool setCigar(const char *cigar)
Set the CIGAR to the specified SAM formatted cigar string.
int32_t get0BasedPosition()
Get the 0-based(BAM) leftmost position of the record.
bool set0BasedPosition(int32_t position)
Set the leftmost position using the specified 0-based (BAM format) value.
bool rmTags(const char *tags)
Remove tags.