00001 /* 00002 * Copyright (C) 2012 Regents of the University of Michigan 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef __TABIX_H__ 00019 #define __TABIX_H__ 00020 00021 #include <stdint.h> 00022 #include <vector> 00023 #include <map> 00024 #include <stdlib.h> 00025 00026 #include "IndexBase.h" 00027 00028 #include "InputFile.h" 00029 #include "StatGenStatus.h" 00030 00031 class Tabix : public IndexBase 00032 { 00033 public: 00034 00035 Tabix(); 00036 virtual ~Tabix(); 00037 00038 /// Reset the member data for a new index file. 00039 void resetIndex(); 00040 00041 // Read & parse the specified index file. 00042 /// \param filename the bam index file to be read. 00043 /// \return the status of the read. 00044 StatGenStatus::Status readIndex(const char* filename); 00045 00046 /// Get the starting file offset to look for the specified start position. 00047 /// For an entire reference ID, set start to -1. 00048 /// To start at the beginning of the region, set start to 0/-1. 00049 bool getStartPos(const char* refName, int32_t start, 00050 uint64_t& fileStartPos); 00051 private: 00052 struct TabixFormat 00053 { 00054 int32_t format; 00055 int32_t col_seq; 00056 int32_t col_beg; 00057 int32_t col_end; 00058 int32_t meta; // character that starts header lines 00059 int32_t skip; // Number of lines to skip from putting into the index. 00060 }; 00061 00062 TabixFormat myFormat; 00063 00064 char* myChromNamesBuffer; 00065 00066 // vector pointing to the chromosome names. 00067 std::vector<const char*> myChromNamesVector; 00068 }; 00069 00070 00071 #endif