3 Copyright (c) 2008 Genome Research Ltd (GRL).
5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
13 The above copyright notice and this permission notice shall be
14 included in all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 /* Contact: Heng Li <lh3@sanger.ac.uk> */
34 Index FASTA files and extract subsequence.
36 @copyright The Wellcome Trust Sanger Institute.
40 typedef struct __faidx_t faidx_t;
47 @abstract Build index for a FASTA or razip compressed FASTA file.
48 @param fn FASTA file name
49 @return 0 on success; or -1 on failure
50 @discussion File "fn.fai" will be generated.
52 int fai_build(const char *fn);
55 @abstract Distroy a faidx_t struct.
56 @param fai Pointer to the struct to be destroyed
58 void fai_destroy(faidx_t *fai);
61 @abstract Load index from "fn.fai".
62 @param fn File name of the FASTA file
64 faidx_t *fai_load(const char *fn);
67 @abstract Fetch the sequence in a region.
68 @param fai Pointer to the faidx_t struct
69 @param reg Region in the format "chr2:20,000-30,000"
70 @param len Length of the region
71 @return Pointer to the sequence; null on failure
73 @discussion The returned sequence is allocated by malloc family
74 and should be destroyed by end users by calling free() on it.
76 char *fai_fetch(const faidx_t *fai, const char *reg, int *len);
79 @abstract Fetch the number of sequences.
80 @param fai Pointer to the faidx_t struct
81 @return The number of sequences
83 int faidx_fetch_nseq(const faidx_t *fai);
86 @abstract Fetch the sequence in a region.
87 @param fai Pointer to the faidx_t struct
88 @param c_name Region name
89 @param p_beg_i Beginning position number (zero-based)
90 @param p_end_i End position number (zero-based)
91 @param len Length of the region
92 @return Pointer to the sequence; null on failure
94 @discussion The returned sequence is allocated by malloc family
95 and should be destroyed by end users by calling free() on it.
97 char *faidx_fetch_seq(const faidx_t *fai, char *c_name, int p_beg_i, int p_end_i, int *len);