00001 /***************************************************************************** 00002 * Copyright (C) 2000 Jim Kent. This source code may be freely used * 00003 * for personal, academic, and non-profit purposes. Commercial use * 00004 * permitted only by explicit agreement with Jim Kent (jim_kent@pacbell.net) * 00005 *****************************************************************************/ 00006 /* nib.h - interface to nucleotides stored 4 bits per base (so have 00007 * room for N. */ 00008 #ifndef NIB_H 00009 #define NIB_H 00010 00011 #ifndef DNAUTIL_H 00012 #include "dnautil.h" 00013 #endif 00014 00015 #ifndef HASH_H 00016 #include "hash.h" 00017 #endif 00018 00020 #define NIB_MASK_MIXED 0x01 /* Read uses case to indicate masking. 00021 * Write sets mask bit for lower-case */ 00022 #define NIB_MASK_MAP 0x02 /* Read builds dnaSeq->mask bit map. Write 00023 * uses mask to set mask bases. Note: the 00024 * bit map indicates which bases are not repeats 00025 */ 00026 #define NIB_BASE_NAME 0x04 /* Return a sequence name that is the base name 00027 * the file. */ 00028 00029 void nibOpenVerify(char *fileName, FILE **retFile, int *retSize); 00030 /* Open file and verify it's in good nibble format. */ 00031 00032 struct dnaSeq *nibLoadPart(char *fileName, int start, int size); 00033 /* Load part of an .nib file. */ 00034 00035 struct dnaSeq *nibLoadPartMasked(int options, char *fileName, int start, int size); 00036 /* Load part of an .nib file, with control over handling of masked positions */ 00037 00038 struct dnaSeq *nibLdPart(char *fileName, FILE *f, int seqSize, int start, int size); 00039 /* Load part of an open .nib file. */ 00040 00041 struct dnaSeq *nibLdPartMasked(int options, char *fileName, FILE *f, int seqSize, int start, int size); 00042 /* Load part of an open .nib file, with control over handling of masked 00043 * positions. */ 00044 00045 struct dnaSeq *nibLoadAll(char *fileName); 00046 /* Load all of a nib file. */ 00047 00048 struct dnaSeq *nibLoadAllMasked(int options, char *fileName); 00049 /* Load part of a .nib file, with control over handling of masked 00050 * positions. Subranges of nib files may specified in the file name 00051 * using the syntax: 00052 * /path/file.nib:seqid:start-end 00053 * or\n" 00054 * /path/file.nib:start-end 00055 * With the first form, seqid becomes the id of the subrange, with the second 00056 * form, a sequence id of file:start-end will be used. 00057 */ 00058 00059 void nibWrite(struct dnaSeq *seq, char *fileName); 00060 /* Write out file in format of four bits per nucleotide. */ 00061 00062 void nibWriteMasked(int options, struct dnaSeq *seq, char *fileName); 00063 /* Write out file in format of four bits per nucleotide, with control over 00064 * handling of masked positions. */ 00065 00066 boolean nibIsFile(char *fileName); 00067 /* Return TRUE if file is a nib file. */ 00068 00069 boolean nibIsRange(char *fileName); 00070 /* Return TRUE if file specifies a subrange of a nib file. */ 00071 00072 void nibParseName(unsigned options, char *fileSpec, char *filePath, 00073 char *name, unsigned *start, unsigned *end); 00074 /* Parse the nib name, getting the file name, seq name to use, and 00075 * optionally the start and end positions. Zero is return for start 00076 * and end if they are not specified. Return the path to the file 00077 * and the name to use for the sequence. */ 00078 00079 struct nibStream *nibStreamOpen(char *fileName); 00080 /* Create a new nib stream. Open file and stuff. */ 00081 00082 void nibStreamClose(struct nibStream **pNs); 00083 /* Close a nib stream. Flush last nibble if need be. Fix up header. */ 00084 00085 void nibStreamOne(struct nibStream *ns, DNA base); 00086 /* Write out one base to nibStream. */ 00087 00088 void nibStreamMany(struct nibStream *ns, DNA *dna, int size); 00089 /* Write many bases to nibStream. */ 00090 00091 struct nibInfo 00092 /* Info on a nib file. */ 00093 { 00094 struct nibInfo *next; 00095 char *fileName; /* Name of nib file. */ 00096 int size; /* Number of bases in nib. */ 00097 FILE *f; /* Open file. */ 00098 }; 00099 00100 struct nibInfo *nibInfoNew(char *path); 00101 /* Make a new nibInfo with open nib file. */ 00102 00103 void nibInfoFree(struct nibInfo **pNib); 00104 /* Free up nib info and close file if open. */ 00105 00106 struct nibInfo *nibInfoFromCache(struct hash *hash, char *nibDir, char *nibName); 00107 /* Get nibInfo on nibDir/nibName.nib from cache, filling cache if need be. */ 00108 00109 int nibGetSize(char* nibFile); 00110 /* Get the number of nucleotides in a nib */ 00111 00112 #endif /* NIB_H */ 00113
1.5.2