class SamParser {
public:
- SamParser(char, const char*, Transcripts&, const char* = 0);
+ SamParser(char, const char*, const char*, Transcripts&, const char*);
~SamParser();
/**
char SamParser::rtTag[STRLEN] = ""; // default : no tag, thus no Type 2 reads
// aux, if not 0, points to the file name of fn_list
-SamParser::SamParser(char inpType, const char* inpF, Transcripts& transcripts, const char* aux)
+SamParser::SamParser(char inpType, const char* inpF, const char* aux, Transcripts& transcripts, const char* imdName)
: transcripts(transcripts)
{
switch(inpType) {
header = sam_in->header;
general_assert(header != 0, "Fail to parse sam header!");
- transcripts.buildMappings(header->n_targets, header->target_name);
+ transcripts.buildMappings(header->n_targets, header->target_name, imdName);
b = bam_init1();
b2 = bam_init1();
bam1_t *mp1 = NULL, *mp2 = NULL;
- if ((b->core.flag & 0x0040) && (b2->core.flag & 0x0080)) {
+ // If lose mate info, discard. is it necessary?
+ if (!((b->core.flag & 0x0040) && (b2->core.flag & 0x0080)) && !((b->core.flag & 0x0080) && (b2->core.flag & 0x0040))) return 4;
+ // If only one mate is mapped, discard
+ if (((b->core.flag & 0x0004) && !(b2->core.flag & 0x0004)) || (!(b->core.flag & 0x0004) && (b2->core.flag & 0x0004))) return 4;
+
+ if (b->core.flag & 0x0040) {
mp1 = b; mp2 = b2;
}
- else if ((b->core.flag & 0x0080) && (b2->core.flag & 0x0040)) {
+ else {
mp1 = b2; mp2 = b;
}
- else return 4; // If lose mate info, discard. is it necessary?
int readType = getReadType(mp1, mp2);
std::string name = getName(mp1);
bam1_t *mp1 = NULL, *mp2 = NULL;
- if ((b->core.flag & 0x0040) && (b2->core.flag & 0x0080)) {
+ // If lose mate info, discard. is it necessary?
+ if (!((b->core.flag & 0x0040) && (b2->core.flag & 0x0080)) && !((b->core.flag & 0x0080) && (b2->core.flag & 0x0040))) return 4;
+ // If only one mate is mapped, discard
+ if (((b->core.flag & 0x0004) && !(b2->core.flag & 0x0004)) || (!(b->core.flag & 0x0004) && (b2->core.flag & 0x0004))) return 4;
+
+ if (b->core.flag & 0x0040) {
mp1 = b; mp2 = b2;
}
- else if ((b->core.flag & 0x0080) && (b2->core.flag & 0x0040)) {
+ else {
mp1 = b2; mp2 = b;
}
- else return 4;
int readType = getReadType(mp1, mp2);
std::string name = getName(mp1);
return (bam_aux2i(p) > 0 ? 2 : 0);
}
-
//For paired-end reads, do not print out type 2 reads
inline int SamParser::getReadType(const bam1_t* b, const bam1_t* b2) {
- if ((b->core.flag & 0x0002) && (b2->core.flag & 0x0002)) return 1;
+ if (!(b->core.flag & 0x0004) && !(b2->core.flag & 0x0004)) return 1;
+
+ if (!strcmp(rtTag, "")) return 0;
+
+ uint8_t *p = bam_aux_get(b, rtTag);
+ if (p != NULL && bam_aux2i(p) > 0) return 2;
+
+ p = bam_aux_get(b2, rtTag);
+ if (p != NULL && bam_aux2i(p) > 0) return 2;
return 0;
}