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_CGDATA_REFERENCESUPPORTREADER_HPP_ 00016 #define CGATOOLS_CGDATA_REFERENCESUPPORTREADER_HPP_ 1 00017 00019 00020 #include "cgatools/core.hpp" 00021 #include "cgatools/util/Streams.hpp" 00022 #include "cgatools/util/DelimitedFile.hpp" 00023 #include "cgatools/reference/CrrFile.hpp" 00024 #include "cgatools/cgdata/GenomeMetadata.hpp" 00025 00026 #include <limits> 00027 #include <boost/noncopyable.hpp> 00028 #include <boost/scoped_ptr.hpp> 00029 #include <boost/shared_ptr.hpp> 00030 00031 namespace cgatools { namespace cgdata { 00032 00035 class ReferenceSupportReader : boost::noncopyable 00036 { 00037 public: 00038 ReferenceSupportReader(const reference::CrrFile& crr, 00039 const GenomeMetadata& exp); 00040 00046 void seek(const reference::Range& r); 00047 00051 int32_t getMinScore(const reference::Range& r, 00052 int32_t noDataValue = 00053 std::numeric_limits<int32_t>::min() ) const; 00054 00057 int32_t getMaxWeightedCoverage(const reference::Range& r, 00058 int32_t noDataValue = 0) const; 00059 00060 private: 00061 struct File 00062 { 00063 std::string filename_; 00064 boost::shared_ptr<std::istream> f_; 00065 util::DelimitedFile parser_; 00066 bool hasWeightedCoverage_; 00067 uint32_t offset_; 00068 int32_t score_; 00069 int32_t uniqueCoverage_; 00070 int32_t weightedCoverage_; 00071 00072 File(const std::string& fn); 00073 }; 00074 00075 struct DataItem 00076 { 00077 bool hasData_; 00078 int32_t score_; 00079 int32_t uniqueCoverage_; 00080 int32_t weightedCoverage_; 00081 00082 DataItem() : hasData_(false), score_(0) {} 00083 }; 00084 00085 const reference::CrrFile& crr_; 00086 const GenomeMetadata& exp_; 00087 00088 uint16_t chromosome_; 00089 uint32_t bufferStartOffset_; 00090 std::vector<DataItem> buffer_; 00091 boost::scoped_ptr<File> file_; 00092 00093 void checkRange(const reference::Range& r) const; 00094 }; 00095 00096 } } // cgatools::cgdata 00097 00098 #endif // CGATOOLS_CGDATA_REFERENCESUPPORTREADER_HPP_