lib/nt4.c File Reference

#include "common.h"
#include "dnautil.h"
#include "shaRes.h"
#include "dnaseq.h"
#include "nt4.h"
#include "sig.h"

Include dependency graph for nt4.c:

Go to the source code of this file.

Functions

static size_t bits32PaddedSize (size_t size)
static struct nt4SeqallocNt4 (size_t baseCount, char *name)
nt4SeqnewNt4 (DNA *dna, int size, char *name)
void freeNt4 (struct nt4Seq **pSeq)
static FILE * nt4OpenVerify (char *fileName)
nt4SeqloadNt4 (char *fileName, char *seqName)
void saveNt4 (char *fileName, DNA *dna, bits32 dnaSize)
int nt4BaseCount (char *fileName)
static void unpackRightSide (bits32 tile, int baseCount, DNA *out)
static void unpackLeftSide (bits32 tile, int baseCount, DNA *out)
static void unpackMidWord (bits32 tile, int startBase, int baseCount, DNA *out)
void unalignedUnpackDna (bits32 *tiles, int start, int size, DNA *unpacked)
DNAnt4Unpack (struct nt4Seq *n, int start, int size)
DNAnt4LoadPart (char *fileName, int start, int size)

Variables

static char const rcsid [] = "$Id: nt4.c,v 1.5 2005/04/10 14:41:24 markd Exp $"


Function Documentation

static struct nt4Seq* allocNt4 ( size_t  baseCount,
char *  name 
) [static, read]

Definition at line 20 of file nt4.c.

References bits32PaddedSize(), cloneString(), needLargeMem(), and needMem().

Referenced by loadNt4(), and newNt4().

00022 {
00023 size_t memSize = bits32PaddedSize(baseCount);
00024 struct nt4Seq *seq = needMem(sizeof(*seq));
00025 seq->baseCount = baseCount;
00026 seq->bases = needLargeMem(memSize);
00027 seq->name = cloneString(name);
00028 return seq;
00029 }

Here is the call graph for this function:

Here is the caller graph for this function:

static size_t bits32PaddedSize ( size_t  size  )  [static]

Definition at line 15 of file nt4.c.

Referenced by allocNt4(), and loadNt4().

00016 {
00017     return (((size+15)>>4)<<2);
00018 }

Here is the caller graph for this function:

void freeNt4 ( struct nt4Seq **  pSeq  ) 

Definition at line 55 of file nt4.c.

References nt4Seq::bases, freeMem(), freez(), and nt4Seq::name.

Referenced by flyFreeNt4Genome(), wormFreeNt4Genome(), and xenAlignBig().

00057 {
00058 struct nt4Seq *seq = *pSeq;
00059 if (seq == NULL)
00060     return;
00061 freeMem(seq->bases);
00062 freeMem(seq->name);
00063 freez(pSeq);
00064 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct nt4Seq* loadNt4 ( char *  fileName,
char *  seqName 
) [read]

Definition at line 78 of file nt4.c.

References allocNt4(), nt4Seq::bases, bits32, bits32PaddedSize(), carefulClose(), mustRead(), mustReadOne, and nt4OpenVerify().

Referenced by flyLoadNt4Genome(), and wormLoadNt4Genome().

00080 {
00081 bits32 size;
00082 struct nt4Seq *seq;
00083 FILE *f = nt4OpenVerify(fileName);
00084 
00085 mustReadOne(f, size);
00086 if (seqName == NULL)
00087     seqName = fileName;
00088 seq = allocNt4(size, seqName);
00089 mustRead(f, seq->bases, bits32PaddedSize(size));
00090 carefulClose(&f);
00091 return seq;
00092 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct nt4Seq* newNt4 ( DNA dna,
int  size,
char *  name 
) [read]

Definition at line 32 of file nt4.c.

References allocNt4(), nt4Seq::bases, bits32, and packDna16().

Referenced by xenAlignBig().

00034 {
00035 bits32 *packed;
00036 DNA *unpacked;
00037 char last[16];
00038 struct nt4Seq *seq = allocNt4(size, name);
00039 packed = seq->bases;
00040 unpacked = dna;
00041 while (size > 16)
00042     {
00043     *packed++ = packDna16(dna);
00044     dna += 16;
00045     size -= 16;
00046     }
00047 if (size > 0)
00048     {
00049     memcpy(last, dna, size);
00050     *packed++ = packDna16(dna);
00051     }
00052 return seq;
00053 }

Here is the call graph for this function:

Here is the caller graph for this function:

int nt4BaseCount ( char *  fileName  ) 

Definition at line 121 of file nt4.c.

References bits32, mustReadOne, and nt4OpenVerify().

Referenced by wormChromSize().

00123 {
00124 bits32 size;
00125 FILE *f = nt4OpenVerify(fileName);
00126 
00127 mustReadOne(f, size);
00128 fclose(f);
00129 return (int)size;
00130 }

Here is the call graph for this function:

Here is the caller graph for this function:

DNA* nt4LoadPart ( char *  fileName,
int  start,
int  size 
)

Definition at line 226 of file nt4.c.

References bits32, freeMem(), mustRead(), mustReadOne, needLargeMem(), nt4OpenVerify(), SEEK_CUR, and unalignedUnpackDna().

Referenced by wormChromPart().

00228 {
00229 bits32 basesInFile;
00230 int tStart, tEnd, tSize;
00231 int end;
00232 FILE *f;
00233 DNA *unpacked;
00234 bits32 *tiles;
00235 
00236 /* Open file, and make sure request is covered by file. */
00237 f = nt4OpenVerify(fileName);
00238 mustReadOne(f, basesInFile);
00239 
00240 assert(start >= 0);
00241 end = start + size;
00242 assert(end <= (int)basesInFile);
00243 
00244 /* Figure out tiles to load */
00245 tStart = (start>>4);
00246 tEnd = ((end+15)>>4);
00247 tSize = tEnd - tStart;
00248 
00249 /* Allocate tile array and read it from disk. */
00250 tiles = needLargeMem(tSize * sizeof(*tiles));
00251 fseek(f, tStart * sizeof(*tiles), SEEK_CUR);
00252 mustRead(f, tiles, tSize * sizeof(*tiles) );
00253 
00254 /* Allocate and unpack array. */
00255 unpacked = needLargeMem(size+1);
00256 unalignedUnpackDna(tiles, start - (tStart<<4), size, unpacked);
00257 
00258 freeMem(tiles);
00259 fclose(f);
00260 return unpacked;
00261 }

Here is the call graph for this function:

Here is the caller graph for this function:

static FILE* nt4OpenVerify ( char *  fileName  )  [static]

Definition at line 66 of file nt4.c.

References bits32, errAbort(), mustOpen(), mustReadOne, and nt4Signature.

Referenced by loadNt4(), nt4BaseCount(), and nt4LoadPart().

00069 {
00070 FILE *f = mustOpen(fileName, "rb");
00071 bits32 signature;
00072 mustReadOne(f, signature);
00073 if (signature != nt4Signature)
00074     errAbort("%s is not a good Nt4 file", fileName);
00075 return f;
00076 }

Here is the call graph for this function:

Here is the caller graph for this function:

DNA* nt4Unpack ( struct nt4Seq n,
int  start,
int  size 
)

Definition at line 217 of file nt4.c.

References nt4Seq::bases, needLargeMem(), and unalignedUnpackDna().

Referenced by scoreNoninsertingExtensions().

00219 {
00220 DNA *unpacked = needLargeMem(size+1);
00221 unalignedUnpackDna(n->bases, start, size, unpacked);
00222 return unpacked;
00223 }

Here is the call graph for this function:

Here is the caller graph for this function:

void saveNt4 ( char *  fileName,
DNA dna,
bits32  dnaSize 
)

Definition at line 94 of file nt4.c.

References nt4Seq::bases, bits32, mustOpen(), nt4Signature, packDna16(), writeOne, and zeroBytes().

00096 {
00097 FILE *f = mustOpen(fileName, "wb");
00098 bits32 signature = nt4Signature;
00099 bits32 bases;
00100 char last[16];
00101 
00102 writeOne(f, signature);
00103 writeOne(f, dnaSize);
00104 while (dnaSize >= 16)
00105     {
00106     bases = packDna16(dna);
00107     writeOne(f, bases);
00108     dna += 16;
00109     dnaSize -= 16;
00110     }
00111 if (dnaSize > 0)
00112     {
00113     zeroBytes(last, sizeof(last));
00114     memcpy(last, dna, dnaSize);
00115     bases = packDna16(last);
00116     writeOne(f, bases);
00117     }
00118 fclose(f);
00119 }

Here is the call graph for this function:

void unalignedUnpackDna ( bits32 *  tiles,
int  start,
int  size,
DNA unpacked 
)

Definition at line 169 of file nt4.c.

References bits32, dnaUtilOpen(), unpackDna(), unpackLeftSide(), unpackMidWord(), and unpackRightSide().

Referenced by nt4LoadPart(), and nt4Unpack().

00172 {
00173 DNA *pt = unpacked;
00174 int sizeLeft = size;
00175 int firstBases, middleBases;
00176 bits32 *startTile, *endTile;
00177 
00178 dnaUtilOpen();
00179 
00180 /* See if all data is in a single word. */
00181 startTile = tiles + (start>>4);
00182 endTile = tiles + ((start + size - 1)>>4);
00183 if (startTile == endTile)
00184     {
00185     unpackMidWord(*startTile, start&0xf, size, unpacked);
00186     return;
00187     }
00188 
00189 /* Skip over initial stuff. */
00190 tiles = startTile;
00191 
00192 /* See if just have one tile to 
00193  * Unpack the right hand side of the first tile. */
00194 firstBases = (16 - (start&0xf));
00195 unpackRightSide(*tiles, firstBases, pt);
00196 pt += firstBases;
00197 sizeLeft -= firstBases;
00198 tiles += 1;
00199 
00200 /* Unpack all of the middle tiles. */
00201 middleBases = (sizeLeft&0x7ffffff0);
00202 unpackDna(tiles, middleBases>>4, pt);
00203 pt += middleBases;
00204 sizeLeft -= middleBases;
00205 tiles += (middleBases>>4);
00206 
00207 /* Unpack the left side of last tile. */
00208 if (sizeLeft > 0)
00209     unpackLeftSide(*tiles, sizeLeft, pt);
00210 pt += sizeLeft;
00211 
00212 /* Add trailing zero to make it a DNA string. */
00213 assert(pt == unpacked+size);
00214 *pt = 0;
00215 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void unpackLeftSide ( bits32  tile,
int  baseCount,
DNA out 
) [static]

Definition at line 144 of file nt4.c.

References valToNt.

Referenced by unalignedUnpackDna().

00146 {
00147 int bitsToDump = ((16-baseCount)<<1);
00148 tile >>= bitsToDump;
00149 out += baseCount;
00150 while (--baseCount >= 0)
00151     {
00152     *--out = valToNt[tile&0x3];
00153     tile >>= 2;
00154     }
00155 }

Here is the caller graph for this function:

static void unpackMidWord ( bits32  tile,
int  startBase,
int  baseCount,
DNA out 
) [static]

Definition at line 157 of file nt4.c.

References valToNt.

Referenced by unalignedUnpackDna().

00159 {
00160 tile >>= ((16-startBase-baseCount)<<1);
00161 out += baseCount;
00162 while (--baseCount >= 0)
00163     {
00164     *--out = valToNt[tile&0x3];
00165     tile >>= 2;
00166     }
00167 }

Here is the caller graph for this function:

static void unpackRightSide ( bits32  tile,
int  baseCount,
DNA out 
) [static]

Definition at line 132 of file nt4.c.

References valToNt.

Referenced by unalignedUnpackDna().

00134 {
00135 int j;
00136 
00137 for (j=baseCount; --j>=0; )
00138     {
00139     out[j] = valToNt[tile & 0x3];
00140     tile >>= 2;
00141     }
00142 }

Here is the caller graph for this function:


Variable Documentation

char const rcsid[] = "$Id: nt4.c,v 1.5 2005/04/10 14:41:24 markd Exp $" [static]

Definition at line 13 of file nt4.c.


Generated on Tue Dec 25 20:06:00 2007 for blat by  doxygen 1.5.2