Browse Source

[CigarOperation] renamed operation to type

remotes/georgeg/bam_output_redesign
lomereiter 10 years ago
parent
commit
c5711201ff
  1. 10
      bio/bam/pileuprange.d
  2. 21
      bio/bam/read.d
  3. 2
      bio/bam/serialization/json.d
  4. 2
      bio/bam/serialization/sam.d
  5. 10
      bio/bam/validation/alignment.d

10
bio/bam/pileuprange.d

@ -87,7 +87,7 @@ struct PileupRead(Read=EagerBamRead) {
/// If current CIGAR operation is one of 'M', '=', or 'X', returns
/// index of current base in the read sequence.
/// Otherwise, returns -1.
int read_sequence_offset() @property const {
int query_offset() @property const {
assert(_query_offset <= _read.sequence_length);
if (_cur_op.is_query_consuming && _cur_op.is_reference_consuming) {
return _query_offset;
@ -119,7 +119,7 @@ struct PileupRead(Read=EagerBamRead) {
_cur_op = cigar[_cur_op_index];
if (_cur_op.is_reference_consuming) {
if (_cur_op.operation != 'N') {
if (_cur_op.type != 'N') {
break;
}
} else if (_cur_op.is_query_consuming) {
@ -658,15 +658,15 @@ unittest {
break;
case 810:
// last read is not yet fetched by pileup engine
assert(column.reads[$ - 2].cigar_after.front.operation == 'D');
assert(column.reads[$ - 2].cigar_after.front.type == 'D');
pileup.popFront();
break;
case 817:
assert(column.reads[$ - 2].cigar_before.back.operation == 'I');
assert(column.reads[$ - 2].cigar_before.back.type == 'I');
pileup.popFront();
break;
case 821:
assert(column.reads[$ - 3].cigar_operation == 'D');
assert(column.reads[$ - 3].cigar_operation.type == 'D');
assert(equal(column.bases, "AAGG-AA"));
pileup.popFront();
break;

21
bio/bam/read.d

@ -79,9 +79,9 @@ struct CigarOperation {
}
}
this(uint length, char operation) {
this(uint length, char operation_type) {
enforce(length < (1<<28), "Too big length of CIGAR operation");
raw = (length << 4) | char2op(operation);
raw = (length << 4) | char2op(operation_type);
}
/// operation length
@ -91,13 +91,10 @@ struct CigarOperation {
/// CIGAR operation as one of MIDNSHP=X.
/// Absent or invalid operation is represented by '?'
char operation() @property const nothrow {
char type() @property const nothrow {
return "MIDNSHP=X????????"[raw & 0xF];
}
///
alias operation this;
// Each pair of bits has first bit set iff the operation is query consuming,
// and second bit set iff it is reference consuming.
// X = P H S N D I M
@ -112,6 +109,10 @@ struct CigarOperation {
bool is_reference_consuming() @property const {
return ((CIGAR_TYPE >> ((raw & 0xF) * 2)) & 2) != 0;
}
string toString() const {
return to!string(length) ~ type;
}
}
/**
@ -121,8 +122,6 @@ struct BamRead {
mixin TagStorage;
// TODO: better names for properties
@property int ref_id() const nothrow { return _refID; }
/// 0-based leftmost coordinate of the first matching base
@ -262,7 +261,7 @@ struct BamRead {
}
/// Human-readable representation of CIGAR string
string cigarString() {
string cigarString() const {
char[] str;
// guess size of resulting string
@ -270,7 +269,7 @@ struct BamRead {
foreach (cigar_op; cigar) {
str ~= to!string(cigar_op.length);
str ~= cigar_op.operation;
str ~= cigar_op.type;
}
return cast(string)str;
}
@ -604,7 +603,7 @@ struct BamRead {
packer.pack(position + 1);
packer.pack(mapping_quality);
packer.pack(array(map!"a.length"(cigar)));
packer.pack(array(map!"a.operation"(cigar)));
packer.pack(array(map!"a.type"(cigar)));
packer.pack(next_ref_id);
packer.pack(next_pos);
packer.pack(template_length);

2
bio/bam/serialization/json.d

@ -231,7 +231,7 @@ void jsonSerialize(S)(BamRead alignment, ReferenceSequenceInfo[] info, ref S str
} else {
foreach (cigar_op; alignment.cigar) {
putinteger(stream, cigar_op.length);
putcharacter(stream, cigar_op.operation);
putcharacter(stream, cigar_op.type);
}
putstring(stream, `","rnext":`);
}

2
bio/bam/serialization/sam.d

@ -178,7 +178,7 @@ void serialize(S, R)(auto ref R alignment, ReferenceSequenceInfo[] info, auto re
} else {
foreach (cigar_op; alignment.cigar) {
putinteger(stream, cigar_op.length);
putcharacter(stream, cigar_op.operation);
putcharacter(stream, cigar_op.type);
}
putcharacter(stream, '\t');
}

10
bio/bam/validation/alignment.d

@ -209,7 +209,7 @@ private:
static bool internalHardClipping(ref BamRead al) {
return (al.cigar.length > 2 &&
any!"a.operation == 'H'"(al.cigar[1..$-1]));
any!"a.type == 'H'"(al.cigar[1..$-1]));
}
static bool internalSoftClipping(ref BamRead al) {
@ -218,16 +218,16 @@ private:
auto cigar = al.cigar;
/// strip H operations from ends
if (cigar[0].operation == 'H') {
if (cigar[0].type == 'H') {
cigar = cigar[1..$];
}
if (cigar[$-1].operation == 'H') {
if (cigar[$-1].type == 'H') {
cigar = cigar[0..$-1];
}
/// check that S operations are at the ends only
return (cigar.length > 2 &&
any!"a.operation == 'S'"(cigar[1..$-1]));
any!"a.type == 'S'"(cigar[1..$-1]));
}
// Sum of M/I/S/=/X operations must be equal to the sequence length
@ -236,7 +236,7 @@ private:
return (al.sequence_length > 0 &&
al.sequence_length != reduce!`a + b`(0,
map!`a.length`(
filter!`canFind("MIS=X", a.operation)`(
filter!`canFind("MIS=X", a.type)`(
al.cigar))));
}

Loading…
Cancel
Save