You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

107 lines
3.0 KiB

  1. /*
  2. This file is part of BioD.
  3. Copyright (C) 2012 Artem Tarasov <lomereiter@gmail.com>
  4. Permission is hereby granted, free of charge, to any person obtaining a
  5. copy of this software and associated documentation files (the "Software"),
  6. to deal in the Software without restriction, including without limitation
  7. the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. and/or sell copies of the Software, and to permit persons to whom the
  9. Software is furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  17. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  18. DEALINGS IN THE SOFTWARE.
  19. */
  20. module bio.core.call;
  21. import bio.core.base;
  22. import bio.core.genotype;
  23. /// A genotype call
  24. struct Call(alias Gt, B)
  25. {
  26. alias Gt!B G;
  27. private {
  28. string _sample = void;
  29. string _chr = void;
  30. ulong _pos = void;
  31. B _refbase = void;
  32. G _gt = void;
  33. float _qual = void;
  34. }
  35. /// Constructor
  36. this(string sample, string chr, ulong pos,
  37. B refbase, G genotype, float quality=float.nan)
  38. {
  39. _sample = sample;
  40. _chr = chr;
  41. _pos = pos;
  42. _refbase = refbase;
  43. _gt = genotype;
  44. _qual = quality;
  45. }
  46. /// Sample name
  47. string sample() @property const {
  48. return _sample;
  49. }
  50. /// Chromosome name
  51. string chromosome() @property const {
  52. return _chr;
  53. }
  54. /// 0-based position on the reference
  55. ulong position() @property const {
  56. return _pos;
  57. }
  58. /// Reference base at the site
  59. B reference_base() @property const {
  60. return _refbase;
  61. }
  62. /// Most probable genotype
  63. ref const(G) genotype() @property const {
  64. return _gt;
  65. }
  66. ///
  67. alias genotype this;
  68. /// Phred-scaled quality score. If unknown, set to NaN.
  69. float quality() @property const {
  70. return _qual;
  71. }
  72. /// Returns true if this call is not a reference one.
  73. bool is_variant() @property const {
  74. return _gt != G(_refbase);
  75. }
  76. }
  77. alias Call!(DiploidGenotype, Base5) DiploidCall5;
  78. alias Call!(DiploidGenotype, Base16) DiploidCall;
  79. alias DiploidCall DiploidCall16;
  80. unittest {
  81. auto call = DiploidCall("NA01234", "chr10", 543210,
  82. Base('T'), diploidGenotype(Base('C'), Base('T')),
  83. 47.0);
  84. assert(call.is_variant);
  85. assert(call.is_heterozygous);
  86. assert(call.reference_base == 'T');
  87. }