00001 #ifndef BINRANGE_H 00002 #define BINRANGE_H 00003 00004 /* binRange Stuff to handle binning - which helps us restrict 00005 * our attention to the parts of database that contain info 00006 * about a particular window on a chromosome. This scheme 00007 * will work without modification for chromosome sizes up 00008 * to half a gigaBase. The finest sized bin is 128k (1<<17). 00009 * The next coarsest is 8x as big (1<<13). There's a hierarchy 00010 * of bins with the chromosome itself being the final bin. 00011 * Features are put in the finest bin they'll fit in. 00012 * 00013 * This file is copyright 2002 Jim Kent, but license is hereby 00014 * granted for all use - public, private or commercial. */ 00015 00016 #define BINRANGE_MAXEND_512M (512*1024*1024) 00017 #define _binOffsetOldToExtended 4681 00018 00019 int binLevelsExtended(); 00020 /* Return number of levels to bins. */ 00021 00022 int binLevels(); 00023 /* Return number of levels to bins. */ 00024 00025 int binFirstShift(); 00026 /* Return amount to shift a number to get to finest bin. */ 00027 00028 int binNextShift(); 00029 /* Return amount to shift a number to get to next coarser bin. */ 00030 00031 int binOffsetExtended(int level); 00032 /* Return offset for bins of a given level. */ 00033 00034 int binOffset(int level); 00035 /* Return offset for bins of a given level. */ 00036 00037 /***** And now for some higher level stuff - useful for binning 00038 ***** things in memory. ******/ 00039 00040 int binFromRange(int start, int end); 00041 /* Given start,end in chromosome coordinates assign it 00042 * a bin. There's a bin for each 128k segment, for each 00043 * 1M segment, for each 8M segment, for each 64M segment, 00044 * and for each chromosome (which is assumed to be less than 00045 * 512M.) A range goes into the smallest bin it will fit in. */ 00046 00047 struct binElement 00048 /* An element in a bin. */ 00049 { 00050 struct binElement *next; 00051 int start, end; /* 0 based, half open range */ 00052 void *val; /* Actual bin item. */ 00053 }; 00054 00055 int binElementCmpStart(const void *va, const void *vb); 00056 /* Compare to sort based on start. */ 00057 00058 struct binKeeper 00059 /* This keeps things in bins in memory */ 00060 { 00061 struct binKeeper *next; 00062 int minPos; /* Minimum position to bin. */ 00063 int maxPos; /* Maximum position to bin. */ 00064 int binCount; /* Count of bins. */ 00065 struct binElement **binLists; /* A list for each bin. */ 00066 }; 00067 00068 struct binKeeperCookie 00069 /* used by binKeeperFirst/binKeeperNext in tracking location in traversing bins */ 00070 { 00071 struct binKeeper *bk; /* binKeeper we are associated with */ 00072 int blIdx; /* current bin list index */ 00073 struct binElement *nextBel; /* next binElement */ 00074 }; 00075 00076 struct binKeeper *binKeeperNew(int minPos, int maxPos); 00077 /* Create new binKeeper that can cover range. */ 00078 00079 void binKeeperFree(struct binKeeper **pBk); 00080 /* Free up a bin keeper. */ 00081 00082 void binKeeperAdd(struct binKeeper *bk, int start, int end, void *val); 00083 /* Add item to binKeeper. */ 00084 00085 void binKeeperRemove(struct binKeeper *bk, int start, int end, void *val); 00086 /* Remove item from binKeeper. */ 00087 00088 struct binElement *binKeeperFind(struct binKeeper *bk, int start, int end); 00089 /* Return a list of all items in binKeeper that intersect range. 00090 * Free this list with slFreeList. */ 00091 00092 struct binElement *binKeeperFindSorted(struct binKeeper *bk, int start, int end); 00093 /* Like binKeeperFind, but sort list on start coordinates. */ 00094 00095 struct binElement *binKeeperFindAll(struct binKeeper *bk); 00096 /* Get all elements sorted. */ 00097 00098 boolean binKeeperAnyOverlap(struct binKeeper *bk, int start, int end); 00099 /* Return TRUE if start/end overlaps with any items in binKeeper. */ 00100 00101 void binKeeperReplaceVal(struct binKeeper *bk, int start, int end, 00102 void *oldVal, void *newVal); 00103 /* Replace occurences of old val in range from start->end with newVal */ 00104 00105 struct binElement *binKeeperFindLowest(struct binKeeper *bk, int start, int end); 00106 /* Find the lowest overlapping range. Quick even if search range large */ 00107 00108 void binKeeperRemove(struct binKeeper *bk, int start, int end, void *val); 00109 /* Remove item from binKeeper. */ 00110 00111 struct binKeeperCookie binKeeperFirst(struct binKeeper *bk); 00112 /* Return an object to use by binKeeperNext() to traverse the binElements. 00113 * The first call to binKeeperNext() will return the first entry in the 00114 * table. */ 00115 00116 struct binElement* binKeeperNext(struct binKeeperCookie *cookie); 00117 /* Return the next entry in the binKeeper table. */ 00118 00119 #endif /* BINRANGE_H */ 00120
1.5.2