1 /* 2 This file is part of BioD. 3 Copyright (C) 2012 Artem Tarasov <lomereiter@gmail.com> 4 5 Permission is hereby granted, free of charge, to any person obtaining a 6 copy of this software and associated documentation files (the "Software"), 7 to deal in the Software without restriction, including without limitation 8 the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 and/or sell copies of the Software, and to permit persons to whom the 10 Software is furnished to do so, subject to the following conditions: 11 12 The above copyright notice and this permission notice shall be included in 13 all copies or substantial portions of the Software. 14 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 DEALINGS IN THE SOFTWARE. 22 23 */ 24 module bio.bam.referenceinfo; 25 26 import undead.stream; 27 import std.exception; 28 import std.array; 29 30 /** 31 Stores basic information about reference sequence. 32 */ 33 struct ReferenceSequenceInfo { 34 private { 35 string _name; 36 int _length; 37 } 38 39 /// Reference sequence name 40 /// (null byte is guaranteed to follow the returned slice) 41 string name() @property const nothrow { 42 return _name[0 .. $ - 1]; 43 } 44 45 /// Reference sequence length 46 int length() @property const { 47 return _length; 48 } 49 50 /// 51 this(string name, int length) { 52 _name = name ~ '\0'; 53 _length = length; 54 } 55 56 /// Constructs the structure from input stream 57 this(ref Stream stream) { 58 int l_name; // length of the reference name plus one 59 stream.read(l_name); 60 _name = cast(string)stream.readString(l_name); // keep '\0' at the end 61 stream.read(_length); 62 } 63 }