00001 // Copyright 2010 Complete Genomics, Inc. 00002 // 00003 // Licensed under the Apache License, Version 2.0 (the "License"); you 00004 // may not use this file except in compliance with the License. You 00005 // may obtain a copy of the License at 00006 // 00007 // http://www.apache.org/licenses/LICENSE-2.0 00008 // 00009 // Unless required by applicable law or agreed to in writing, software 00010 // distributed under the License is distributed on an "AS IS" BASIS, 00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 00012 // implied. See the License for the specific language governing 00013 // permissions and limitations under the License. 00014 00015 #ifndef CGATOOLS_VARIANTS_LOCUS_HPP_ 00016 #define CGATOOLS_VARIANTS_LOCUS_HPP_ 1 00017 00019 00020 #include "cgatools/core.hpp" 00021 #include "cgatools/variants/Call.hpp" 00022 #include "cgatools/variants/Allele.hpp" 00023 #include "cgatools/reference/CrrFile.hpp" 00024 00025 #include <map> 00026 00027 namespace cgatools { namespace variants { 00028 00031 class Locus 00032 { 00033 typedef reference::CrrFile CrrFile; 00034 typedef reference::Location Location; 00035 typedef reference::Range Range; 00036 public: 00038 Locus() 00039 : crr_(0) 00040 { 00041 } 00042 00046 Locus(const CrrFile& crr) 00047 : crr_(&crr) 00048 { 00049 } 00050 00053 Locus(const Locus& other); 00054 00057 Locus& operator=(const Locus& other); 00058 00061 const std::vector<Call>& getCalls() const 00062 { 00063 return calls_; 00064 } 00065 00068 std::vector<Call>& getCalls() 00069 { 00070 return calls_; 00071 } 00072 00074 const std::vector<Allele>& getAlleles() const 00075 { 00076 return alleles_; 00077 } 00078 00080 const Range& getRange() const 00081 { 00082 return range_; 00083 } 00084 00086 void setRange(const Range& range); 00087 00089 const CrrFile& getReference() const 00090 { 00091 return *crr_; 00092 } 00093 00095 boost::uint32_t getId() const; 00096 00099 void setId(boost::uint32_t locusId); 00100 00102 boost::uint16_t getPloidy() const; 00103 00105 void setHapLink(size_t alleleOffset, const std::string& hapLink); 00106 00109 bool isRefCallLocus() const; 00110 00112 bool isNoCallLocus() const; 00113 00116 bool isRefConsistent() const; 00117 00120 bool hasNoCalls() const; 00121 00123 void clearCalls(); 00124 00126 void addCall(const Call& call); 00127 00130 void initFromCalls(bool relaxedReferenceValidation = true); 00131 00136 void locationCalls(const Location& loc, std::vector< std::pair<char, const Call*> >& calls) const; 00137 00139 std::string getType() const; 00140 00142 std::string getZygosity() const; 00143 00146 void reorderAlleles(); 00147 00150 void writeAsOneLine(std::ostream& out, bool writeExtras = true, char sep = '\t') const; 00151 00152 static void writeOneLineFileHeader(std::ostream& out, char sep = '\t'); 00153 private: 00154 void validateCalls(bool relaxedReferenceValidation) const; 00155 void validateAllelesAndInitRange(); 00156 void callError (const std::string&, const Call&) const; 00157 void locusError(const std::string&) const; 00158 00159 Range range_; 00160 const CrrFile* crr_; 00161 std::vector<Call> calls_; 00162 std::vector<Allele> alleles_; 00163 00164 public: 00166 std::vector<std::string> extras_; 00167 }; 00168 00169 std::ostream& operator<<(std::ostream& out, const Locus& locus); 00170 00171 } } // cgatools::variants 00172 00173 #endif // CGATOOLS_VARIANTS_LOCUS_HPP_