SamRecordHelper.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "SamRecordHelper.h"
00019 #include <stdexcept>
00020
00021 int SamRecordHelper::checkSequence(SamRecord& record, int32_t pos0Based,
00022 const char* sequence)
00023 {
00024 const char* readSeq = record.getSequence();
00025
00026
00027 Cigar* cigar = record.getCigarInfo();
00028
00029 if(cigar == NULL)
00030 {
00031 throw std::runtime_error("Failed to get Cigar.");
00032 }
00033
00034 int32_t readStartIndex =
00035 cigar->getQueryIndex(pos0Based, record.get0BasedPosition());
00036
00037
00038
00039 if(readStartIndex == Cigar::INDEX_NA)
00040 {
00041 return(false);
00042 }
00043
00044
00045 readSeq += readStartIndex;
00046 if(strncmp(readSeq, sequence, strlen(sequence)) == 0)
00047 {
00048
00049 return(readStartIndex);
00050 }
00051
00052 return(-1);
00053 }
00054
00055
00056 bool SamRecordHelper::genSamTagsString(SamRecord& record,
00057 String& returnString,
00058 char delim)
00059 {
00060 char tag[3];
00061 char vtype;
00062 void* value;
00063
00064
00065 record.resetTagIter();
00066
00067
00068 bool firstEntry = true;
00069 bool returnStatus = true;
00070 while(record.getNextSamTag(tag, vtype, &value) != false)
00071 {
00072 if(!firstEntry)
00073 {
00074 returnString += delim;
00075 }
00076 else
00077 {
00078 firstEntry = false;
00079 }
00080 returnStatus &= genSamTagString(tag, vtype, value, returnString);
00081 }
00082 return(returnStatus);
00083 }
00084
00085
00086 bool SamRecordHelper::genSamTagString(const char* tag, char vtype,
00087 void* value, String& returnString)
00088 {
00089 returnString += tag;
00090 returnString += ":";
00091 returnString += vtype;
00092 returnString += ":";
00093 if(SamRecord::isIntegerType(vtype))
00094 {
00095 returnString += (int)*(int*)value;
00096 }
00097 else if(SamRecord::isDoubleType(vtype))
00098 {
00099 returnString += (double)*(double*)value;
00100 }
00101 else if(SamRecord::isCharType(vtype))
00102 {
00103 returnString += (char)*(char*)value;
00104 }
00105 else if(SamRecord::isStringType(vtype))
00106 {
00107
00108 returnString += (String)*(String*)value;
00109 }
00110 else
00111 {
00112
00113 return(false);
00114 }
00115 return(true);
00116 }