File: RefGenome.h

package info (click to toggle)
libseqlib 1.1.2+dfsg-1~bpo9+1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports
  • size: 1,460 kB
  • sloc: cpp: 7,176; sh: 805; makefile: 60
file content (57 lines) | stat: -rw-r--r-- 1,387 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef SEQLIB_REF_GENOME_H
#define SEQLIB_REF_GENOME_H

#include <string>
#include <cstdlib>
#include <iostream>

#include <htslib/faidx.h>

namespace SeqLib {
  
  /** Stores an indexed reference genome
   *
   * RefGenome is currently used as an interface to obtain
   * sequences from the reference given an interval.
   */
  class RefGenome {

  public:

    /** Create an empty RefGenome object */
    RefGenome() { index = NULL; }
    
    /** Destroy the malloc'ed faidx_t index inside object */
    ~RefGenome() { if (index) fai_destroy(index); }
    
    /** Query a region to get the sequence
     * @param chr_name name of the chr to query
     * @param p1 position 1. Zero-based
     * @param p2 position 2. Zero-based
     * 
     * @exception Throws an invalid_argument if p1 > p2, p1 < 0, p2 < 0, chr not found, or seq not found
     * @note This is currently NOT thread safe
     */
    std::string QueryRegion(const std::string& chr_name, int32_t p1, int32_t p2) const;

    /** Load an indexed reference sequence 
     * @param file Path to an indexed reference genome. See samtools faidx to create
     * @return True if succesfully loaded
     */
    bool LoadIndex(const std::string& file);
    
    /** Check if reference has been loaded */
    bool IsEmpty() const { 
      return (index == NULL); 
    }
    
  private:

    faidx_t * index;

  };
  

}

#endif