1 /* mm_file.h - defines m_file_str for mmap()ed files */ 2 3 /* $Id: mm_file.h 938 2012-06-04 16:15:06Z wrp $ */ 4 5 /* copyright (c) 1999, 2014 by William R. Pearson and The Rector & 6 Vistors of the University of Virginia */ 7 8 9 /* Licensed under the Apache License, Version 2.0 (the "License"); 10 you may not use this file except in compliance with the License. 11 You may obtain a copy of the License at 12 13 http://www.apache.org/licenses/LICENSE-2.0 14 15 Unless required by applicable law or agreed to in writing, 16 software distributed under this License is distributed on an "AS 17 IS" BASIS, WITHOUT WRRANTIES OR CONDITIONS OF ANY KIND, either 18 express or implied. See the License for the specific language 19 governing permissions and limitations under the License. 20 */ 21 22 #include <sys/types.h> 23 24 #ifndef FSEEK_T_DEF 25 #ifndef USE_FSEEKO 26 #define FSEEK_T_DEF 27 #define FSEEK fseek 28 #define FTELL ftell 29 typedef long fseek_t; 30 #else 31 #define FSEEK fseeko 32 #define FTELL ftello 33 typedef off_t fseek_t; 34 #endif 35 #endif 36 37 #ifdef HAS_INTTYPES 38 #include <inttypes.h> 39 #else 40 #ifdef WIN32 41 typedef __int64 int64_t; 42 typedef unsigned __int64 uint64_t; 43 #else 44 typedef long int64_t; 45 typedef unsigned long uint64_t; 46 #endif 47 #endif 48 typedef int64_t MM_OFF; 49 50 #ifdef MYSQL_DB 51 #include <mysql.h> 52 #endif 53 #ifdef PGSQL_DB 54 #include <libpq-fe.h> 55 #endif 56 57 #ifndef MAX_FN 58 #include "defs.h" 59 #endif 60 61 extern unsigned long adler32(); 62 63 struct lmf_str { 64 FILE *libf; /* sequence file being read */ 65 char *lb_name; /* file name */ 66 char opt_text[MAX_FN]; /* text after filename */ 67 int lb_type; /* library type */ 68 int *sascii; /* ascii -> sq mapping */ 69 int *vascii; /* annotation to ann mapping */ 70 71 char *annot_sname; /* annotation script name */ 72 73 /* used by flat files */ 74 char *lline; /* last line read */ 75 int acc_off; /* start of libstr (+1 for agetlib/fasta) */ 76 unsigned char *cpsave; /* position in line for lgetlib() */ 77 fseek_t lpos; /* position in file */ 78 79 /* blast2.0 stuff */ 80 FILE *hfile; /* BLAST2.0 description file */ 81 int bl_format_ver; /* blast formatdb version */ 82 int bl_lib_pos; /* for ncbl2 */ 83 int pref_db; /* preferred database */ 84 int have_oid_list; /* we have an oid file, must read oid's */ 85 unsigned int *oid_list; /* oid list for subsets */ 86 int oid_seqs; /* start offset for mask array */ 87 unsigned int max_oid; /* start offset for mask array */ 88 89 /* Genbank Flat files */ 90 int lfflag; /* flag for CRLF in EMBL CDROM files */ 91 92 /* stuff for GCG format files (5,6) */ 93 int gcg_binary; /* flag for binary gcg format */ 94 long gcg_len; /* length of GCG sequence */ 95 96 /* used when memory mapping */ 97 int mm_flg; /* mmap worked */ 98 int mmap_fd; /* mmap_fd */ 99 char *mmap_base; /* base */ 100 char *mmap_addr; /* current pos */ 101 long st_size; /* file size */ 102 103 MM_OFF *d_pos_arr; /* pointer to desc. offsets */ 104 MM_OFF *s_pos_arr; /* pointer to seq. offsets */ 105 MM_OFF *b_pos_arr; /* pointer to binary seq. offsets */ 106 MM_OFF *a_pos_arr; /* pointer to aux offsets */ 107 108 /* currently available only for memory mapped files */ 109 int max_cnt; /* # database entries */ 110 int64_t tot_len; /* total residue length */ 111 long max_len; /* maximum sequence lengh */ 112 long maxn; /* maximum possible length */ 113 long mdup; /* duplication for overlapping sequences */ 114 int lib_aa; /* 0 = DNA, 1 = prot */ 115 char *tmp_buf; /* temporary buffer */ 116 int tmp_buf_max; /* max size */ 117 int (*sel_acc_p)(char *, int gi, void *); /* used to select subset of library */ 118 void *sel_local; /* local data structure for sel_acc_p() */ 119 120 /* used for SQL database queries */ 121 char *sql_db, *sql_query, *sql_getdesc, *sql_getseq, *sql_close_tables; 122 int sql_reopen; 123 char **sql_uid_arr; /* indexed by lpos */ 124 /* used to get sequence data */ 125 char *sql_seqp; 126 127 #ifdef MYSQL_DB 128 /* used to open the database */ 129 MYSQL *mysql_conn; 130 MYSQL_RES *mysql_res; 131 MYSQL_ROW mysql_row; 132 #endif 133 134 #ifdef PGSQL_DB 135 /* used to open the database */ 136 PGconn *pgsql_conn; 137 PGresult *pgsql_res; 138 #endif 139 140 int (*getlib)(unsigned char *seq, int maxs, char *ann, 141 int n_libstr, 142 fseek_t *libpos, 143 int *lcont, 144 struct lmf_str *lm_fd, 145 long *l_off); 146 147 void (*ranlib)(char *str, int cnt, 148 fseek_t libpos, char *libstr, 149 struct lmf_str *lm_fd); 150 151 int (*get_mmap_chain)(struct seqr_chain *cur_seqr_chain, 152 struct lmf_str *m_fd, struct db_str *db); 153 }; 154