Browse Source

renamed read_name to name

remotes/georgeg/bam_output_redesign
lomereiter 10 years ago
parent
commit
5ef136fc9d
  1. 4
      bio/bam/bai/indexing.d
  2. 2
      bio/bam/baseinfo.d
  3. 4
      bio/bam/md/reconstruct.d
  4. 2
      bio/bam/pileuprange.d
  5. 33
      bio/bam/read.d
  6. 2
      bio/bam/serialization/json.d
  7. 2
      bio/bam/serialization/sam.d
  8. 6
      bio/bam/validation/alignment.d
  9. 2
      bio/sam/utils/fastrecordparser.d
  10. 2
      bio/sam/utils/recordparser.d
  11. 2
      src_ragel/sam_alignment.rl
  12. 42
      test/unittests.d

4
bio/bam/bai/indexing.d

@ -242,9 +242,9 @@ void createIndex(BamReader bam, ref Stream stream, void delegate(lazy float p) p
(read.ref_id < prev_read.ref_id))
{
throw new Exception("BAM file is not properly sorted: " ~
"read '" ~ read.read_name ~ "'" ~
"read '" ~ read.name ~ "'" ~
" must be before read '" ~
prev_read.read_name ~
prev_read.name ~
"' (at virtual offset " ~
to!string(prev_block.start_virtual_offset)~
")");

2
bio/bam/baseinfo.d

@ -223,7 +223,7 @@ template FZbaseInfo(R) {
string key_sequence = void;
debug {
_read_name = read.read_name.idup;
_read_name = read.name.idup;
}
enum flowOrderExists = staticIndexOf!(MixinArg!(string, "flowOrder"), Args);

4
bio/bam/md/reconstruct.d

@ -37,7 +37,7 @@ auto dna(T)(T read)
debug {
/*
import std.stdio;
stderr.writeln("[dna] processing read ", read.read_name);
stderr.writeln("[dna] processing read ", read.name);
stderr.flush();
*/
}
@ -197,7 +197,7 @@ auto dna(T)(T read)
import std.stdio;
if (result.empty) {
stderr.writeln("[dna] empty DNA!");
stderr.writeln(" read name: ", read.read_name);
stderr.writeln(" read name: ", read.name);
stderr.writeln(" read sequence: ", read.sequence);
stderr.writeln(" read CIGAR: ", read.cigarString());
stderr.writeln(" read MD tag: ", read["MD"]);

2
bio/bam/pileuprange.d

@ -161,7 +161,7 @@ struct PileupRead(Read=EagerBamRead) {
}
void assertCigarIndexIsValid() {
assert(_cur_op_index < _read.cigar.length, "Invalid read " ~ _read.read_name
assert(_cur_op_index < _read.cigar.length, "Invalid read " ~ _read.name
~ " - CIGAR " ~ _read.cigarString()
~ ", sequence " ~ to!string(_read.sequence));
}

33
bio/bam/read.d

@ -217,19 +217,20 @@ struct BamRead {
}
/// Read name
@property string read_name() const nothrow {
@property string name() const nothrow {
// notice -1: the string is zero-terminated, so we should strip that '\0'
return cast(string)(_chunk[_read_name_offset .. _read_name_offset + _l_read_name - 1]);
}
/// ditto
@property void read_name(string name) {
enforce(name.length >= 1 && name.length <= 255, "name length must be in 1-255 range");
@property void name(string new_name) {
enforce(new_name.length >= 1 && new_name.length <= 255,
"name length must be in 1-255 range");
_dup();
bio.bam.utils.array.replaceSlice(_chunk,
_chunk[_read_name_offset .. _read_name_offset + _l_read_name - 1],
cast(ubyte[])name);
_l_read_name = cast(ubyte)(name.length + 1);
cast(ubyte[])new_name);
_l_read_name = cast(ubyte)(new_name.length + 1);
}
/// List of CIGAR operations
@ -454,7 +455,7 @@ struct BamRead {
// 6) next_pos int
// 7) tlen int
// ----------------------------------------------------
// (after them read_name follows which is string)
// (after them name follows which is string)
//
switchEndianness(_chunk.ptr, 8 * uint.sizeof);
@ -579,7 +580,7 @@ struct BamRead {
///
/// Packs message in the following format:
/// MsgPack array with elements
/// 0) read name - string
/// 0) name - string
/// 1) flag - ushort
/// 2) reference sequence id - int
/// 3) leftmost mapping position (1-based) - int
@ -597,7 +598,7 @@ struct BamRead {
////////////////////////////////////////////////////////////////////////////
void toMsgpack(Packer)(ref Packer packer) const {
packer.beginArray(13);
packer.pack(cast(ubyte[])read_name);
packer.pack(cast(ubyte[])name);
packer.pack(flag);
packer.pack(ref_id);
packer.pack(position + 1);
@ -1033,16 +1034,16 @@ unittest {
import std.math;
auto read = BamRead("readname",
"AGCTGACTACGTAATAGCCCTA",
[CigarOperation(22, 'M')]);
"AGCTGACTACGTAATAGCCCTA",
[CigarOperation(22, 'M')]);
assert(read.sequence_length == 22);
assert(read.cigar.length == 1);
assert(read.cigarString() == "22M");
assert(read.read_name == "readname");
assert(read.name == "readname");
assert(equal(read.sequence(), "AGCTGACTACGTAATAGCCCTA"));
read.read_name = "anothername";
assert(read.read_name == "anothername");
read.name = "anothername";
assert(read.name == "anothername");
assert(read.cigarString() == "22M");
read.phred_base_quality = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
@ -1084,9 +1085,9 @@ unittest {
builder.put("X2", Value([1,2,3]));
read = BamRead("readname",
"AGCTGACTACGTAATAGCCCTA",
[CigarOperation(22, 'M')],
builder.data);
"AGCTGACTACGTAATAGCCCTA",
[CigarOperation(22, 'M')],
builder.data);
assert(read["X0"] == 24);
assert(read["X1"] == "abcd");
assert(read["X2"] == [1,2,3]);

2
bio/bam/serialization/json.d

@ -207,7 +207,7 @@ void jsonSerialize(S)(BamRead alignment, ReferenceSequenceInfo[] info, ref S str
}
putstring(stream, `{"qname":`);
jsonSerializeCharacterRange(stream, alignment.read_name);
jsonSerializeCharacterRange(stream, alignment.name);
putstring(stream, `,"flag":`);
putinteger(stream, alignment.flag);
putstring(stream, `,"rname":`);

2
bio/bam/serialization/sam.d

@ -154,7 +154,7 @@ void serialize(S, R)(auto ref R alignment, ReferenceSequenceInfo[] info, auto re
}
}
putstring(stream, alignment.read_name);
putstring(stream, alignment.name);
putcharacter(stream, '\t');
putinteger(stream, alignment.flag);

6
bio/bam/validation/alignment.d

@ -166,12 +166,12 @@ private:
bool invalidReadName(ref BamRead al) {
// Read name (a.k.a. QNAME) must =~ /^[!-?A-~]{1,255}$/
// according to specification.
if (al.read_name.length == 0) {
if (al.name.length == 0) {
if (!onError(al, AlignmentError.EmptyReadName)) return true;
} else if (al.read_name.length > 255) {
} else if (al.name.length > 255) {
if (!onError(al, AlignmentError.TooLongReadName)) return true;
} else {
foreach (char c; al.read_name)
foreach (char c; al.name)
{
if ((c < '!') || (c > '~') || (c == '@')) {
if (!onError(al, AlignmentError.ReadNameContainsInvalidCharacters)) {

2
bio/sam/utils/fastrecordparser.d

@ -4085,7 +4085,7 @@ unittest {
auto header = new SamHeader("@SQ\tSN:20\tLN:1234567");
auto alignment = parseAlignmentLine(line, header);
assert(alignment.read_name == "ERR016155.15021091");
assert(alignment.name == "ERR016155.15021091");
assert(equal(alignment.sequence(), "AGAAAAAACTGGAAGTTAATAGAGTGGTGACTCAGATCCAGTGGTGGAAGGGTAAGGGATCTTGGAACCCTATAGAGTTGCTGTGTGCCAGGGCCAGATCC"));
assert(alignment.cigarString() == "66S35M");
assert(alignment.flag == 185);

2
bio/sam/utils/recordparser.d

@ -1082,7 +1082,7 @@ unittest {
auto header = new SamHeader("@SQ\tSN:20\tLN:1234567");
auto alignment = parseAlignmentLine(line, header);
assert(alignment.read_name == "ERR016155.15021091");
assert(alignment.name == "ERR016155.15021091");
assert(equal(alignment.sequence(), "AGAAAAAACTGGAAGTTAATAGAGTGGTGACTCAGATCCAGTGGTGGAAGGGTAAGGGATCTTGGAACCCTATAGAGTTGCTGTGTGCCAGGGCCAGATCC"));
assert(alignment.cigarString() == "66S35M");
assert(alignment.flag == 185);

2
src_ragel/sam_alignment.rl

@ -347,7 +347,7 @@ unittest {
auto header = new SamHeader("@SQ\tSN:20\tLN:1234567");
auto alignment = parseAlignmentLine(line, header);
assert(alignment.read_name == "ERR016155.15021091");
assert(alignment.name == "ERR016155.15021091");
assert(equal(alignment.sequence(), "AGAAAAAACTGGAAGTTAATAGAGTGGTGACTCAGATCCAGTGGTGGAAGGGTAAGGGATCTTGGAACCCTATAGAGTTGCTGTGTGCCAGGGCCAGATCC"));
assert(alignment.cigarString() == "66S35M");
assert(alignment.flag == 185);

42
test/unittests.d

@ -74,7 +74,7 @@ unittest {
assert(equal(map!"cast(char)(a + 33)"(read.phred_base_quality),
"<<<7<<<;<<<<<<<<8;;<7;4<;<;;;;;94<;"));
assert(bf.reference(read.ref_id).name == "chr1");
assert(read.read_name == "EAS56_57:6:190:289:82");
assert(read.name == "EAS56_57:6:190:289:82");
assert(read.flag == 69);
assert(read.position == 99);
assert(read.mapping_quality == 0);
@ -85,28 +85,28 @@ unittest {
assert(bf.header.getSequenceIndex("chr1") == read.ref_id);
}
assert(bf.reads.front.read_name == "EAS56_57:6:190:289:82");
assert(bf.reads.front.name == "EAS56_57:6:190:289:82");
writeln("Testing tag parsing...");
fn = buildPath(dirName(__FILE__), "data", "tags.bam");
bf = new BamReader(fn);
foreach (alignment; bf.reads) {
auto read_name = alignment.read_name;
assert(read_name[0..4] == "tag_");
auto name = alignment.name;
assert(name[0..4] == "tag_");
char[] tag;
read_name = read_name[4..$];
while (read_name[0] != ':') {
tag ~= read_name[0];
read_name = read_name[1..$];
name = name[4..$];
while (name[0] != ':') {
tag ~= name[0];
name = name[1..$];
}
read_name = read_name[1..$];
name = name[1..$];
string value = toSam(alignment[tag.idup]);
if (read_name != value) {
writeln("tag: ", tag, "\tread_name: ", read_name, "\tvalue: ", value);
if (name != value) {
writeln("tag: ", tag, "\tname: ", name, "\tvalue: ", value);
writeln("value bam_typeid: ", alignment[tag.idup].bam_typeid);
}
assert(read_name == value);
assert(name == value);
}
writeln("Testing exception handling...");
@ -138,8 +138,8 @@ unittest {
if (!equal(naive, refseq)) {
writeln(beg);
writeln(end);
writeln(array(map!"a.read_name"(refseq)));
writeln(array(map!"a.read_name"(naive)));
writeln(array(map!"a.name"(refseq)));
writeln(array(map!"a.name"(naive)));
}
assert(equal(refseq, naive));
}
@ -173,9 +173,9 @@ unittest {
auto fst_read_small = bf.getReadAt(fst_offset_small);
auto fst_read_large = bf.getReadAt(fst_offset_large);
assert(fst_read_tiny.read_name == "tiny:r1:0..1:len1:bin4681:hexbin0x1249");
assert(fst_read_small.read_name == "small:r1:0..1:len1:bin4681:hexbin0x1249");
assert(fst_read_large.read_name == "large:r1:0..1:len1:bin4681:hexbin0x1249");
assert(fst_read_tiny.name == "tiny:r1:0..1:len1:bin4681:hexbin0x1249");
assert(fst_read_small.name == "small:r1:0..1:len1:bin4681:hexbin0x1249");
assert(fst_read_large.name == "large:r1:0..1:len1:bin4681:hexbin0x1249");
}
writeln("Testing Value code...");
@ -236,7 +236,7 @@ unittest {
auto line = toSam(read, bf.reference_sequences);
auto read2 = parseAlignmentLine(line, bf.header);
if (read != read2) {
writeln(read.read_name);
writeln(read.name);
}
assert(read == read2);
}
@ -247,7 +247,7 @@ unittest {
auto line = toSam(read, bf.reference_sequences);
auto read2 = parseAlignmentLine(line, bf.header);
if (read != read2 && isValid(read)) {
writeln(read.read_name);
writeln(read.name);
}
assert(read == read2 || !isValid(read));
}
@ -303,11 +303,11 @@ unittest {
assert(ref_id > current_ref_id);
switch (ref_id) {
case 0:
assert(column.reads.front.read_name == "EAS56_57:6:190:289:82");
assert(column.reads.front.name == "EAS56_57:6:190:289:82");
assert(column.position == 99);
break;
case 1:
assert(column.reads.front.read_name == "B7_591:8:4:841:340");
assert(column.reads.front.name == "B7_591:8:4:841:340");
assert(column.position == 0);
break;
default:

Loading…
Cancel
Save