Browse Source

inputRangeObject sucks (we all <3 inlining!)

remotes/georgeg/bam_output_redesign
lomereiter 10 years ago
parent
commit
7ad0d37b78
  1. 2
      bio/bam/baseinfo.d
  2. 46
      bio/bam/fz/flowcall.d
  3. 6
      bio/bam/read.d

2
bio/bam/baseinfo.d

@ -208,7 +208,7 @@ template FZbaseInfo(R) {
mixin template rangeMethods() {
private {
ForwardRange!ReadFlowCall _flow_calls;
ReadFlowCallRange!(BamRead.SequenceResult) _flow_calls;
ushort _at;
debug {

46
bio/bam/fz/flowcall.d

@ -118,6 +118,7 @@ struct ReadFlowCallRange(S)
private {
string _flow_order = void;
ushort[] _intensities = void;
bool _rev = void;
S _sequence = void;
int _zf = void;
@ -126,9 +127,9 @@ struct ReadFlowCallRange(S)
size_t _current_flow_index;
ushort _current_offset;
ushort _overlap;
ushort _overlap = void;
bool _empty;
bool _empty = false;
// consumes next homopolymer from the sequence,
// and updates _current_base, _current_flow_index,
@ -139,13 +140,24 @@ struct ReadFlowCallRange(S)
return;
}
_current_length = 1;
// setup current base and current length
_current_base = _sequence.front;
_sequence.popFront();
_current_length = 1;
while (!_sequence.empty && _sequence.front == _current_base) {
if (!_rev) {
_current_base = _sequence.front;
_sequence.popFront();
++_current_length;
while (!_sequence.empty && _sequence.front == _current_base) {
_sequence.popFront();
++_current_length;
}
} else {
_current_base = _sequence.back; // complement later
_sequence.popBack(); // because of comparison below
while (!_sequence.empty && _sequence.back == _current_base) {
_sequence.popBack();
++_current_length;
}
_current_base = _current_base.complement;
}
// setup current flow index
@ -157,9 +169,12 @@ struct ReadFlowCallRange(S)
}
}
this(S seq, ushort[] intensities, string flow_order, ushort first_base_overlap, int zf) {
this(S seq, ushort[] intensities, bool reverse_strand,
string flow_order, ushort first_base_overlap, int zf)
{
_sequence = seq;
_intensities = intensities;
_rev = reverse_strand;
_flow_order = flow_order;
_zf = zf;
_overlap = first_base_overlap;
@ -198,10 +213,10 @@ struct ReadFlowCallRange(S)
}
}
private ReadFlowCallRange!S readFlowCallRange(S)(S seq, ushort[] intensities,
private ReadFlowCallRange!S readFlowCallRange(S)(S seq, ushort[] intensities, bool rev,
string flow_order, ushort overlap, int zf)
{
return ReadFlowCallRange!S(seq, intensities, flow_order, overlap, zf);
return ReadFlowCallRange!S(seq, intensities, rev, flow_order, overlap, zf);
}
@ -210,7 +225,7 @@ private ReadFlowCallRange!S readFlowCallRange(S)(S seq, ushort[] intensities,
/// Tag name is an optional argument because it is not standard and will likely
/// be changed in the future (there was a proposal on samtools mailing list
/// to introduce standard FB tag).
ForwardRange!ReadFlowCall readFlowCalls(R)(R read, string flow_order, string key_sequence, string tag="ZF") {
auto readFlowCalls(R)(R read, string flow_order, string key_sequence, string tag="ZF") {
auto zf = cast(int)read[tag];
Value fz_value = read["FZ"];
@ -229,11 +244,6 @@ ForwardRange!ReadFlowCall readFlowCalls(R)(R read, string flow_order, string key
overlap += 100;
}
if (!read.is_reverse_strand) {
auto seq = read.sequence;
return inputRangeObject(readFlowCallRange(seq, intensities, flow_order, overlap, zf));
} else {
auto seq = retro(map!"a.complement"(read.sequence));
return inputRangeObject(readFlowCallRange(seq, intensities, flow_order, overlap, zf));
}
return readFlowCallRange(read.sequence, intensities, read.is_reverse_strand,
flow_order, overlap, zf);
}

6
bio/bam/read.d

@ -308,7 +308,7 @@ struct BamRead {
return opIndex(_len - 1);
}
private auto _getActualPosition(size_t index) const
private size_t _getActualPosition(size_t index) const
{
if (_use_first_4_bits) {
// [0 1] [2 3] [4 5] [6 7] ...
@ -325,7 +325,7 @@ struct BamRead {
}
}
private auto _useFirst4Bits(size_t index) const
private bool _useFirst4Bits(size_t index) const
{
auto res = index % 2 == 0;
if (!_use_first_4_bits) {
@ -555,7 +555,7 @@ struct BamRead {
/// Size of alignment when output to stream in BAM format.
/// Includes block_size as well (see SAM/BAM specification)
@property auto size_in_bytes() const {
@property size_t size_in_bytes() const {
return int.sizeof + _chunk.length;
}

Loading…
Cancel
Save