lib/dnaLoad.c File Reference

#include "common.h"
#include "dnaseq.h"
#include "fa.h"
#include "twoBit.h"
#include "nib.h"
#include "dnaLoad.h"

Include dependency graph for dnaLoad.c:

Go to the source code of this file.

Data Structures

struct  dnaLoadStack
struct  dnaLoad

Functions

dnaLoadStackdnaLoadStackNew (char *fileName)
void dnaLoadStackFree (struct dnaLoadStack **pDls)
void dnaLoadStackFreeList (struct dnaLoadStack **pList)
void dnaLoadClose (struct dnaLoad **pDl)
dnaLoaddnaLoadOpen (char *fileName)
dnaSeqdnaLoadSingle (char *fileName, int *retStart, int *retEnd, int *retParentSize)
static struct dnaSeqdnaLoadNextFromStack (struct dnaLoad *dl)
static struct dnaSeqdnaLoadStackOrSingle (struct dnaLoad *dl)
dnaSeqdnaLoadNext (struct dnaLoad *dl)
dnaSeqdnaLoadAll (char *fileName)
int dnaLoadCurStart (struct dnaLoad *dl)
int dnaLoadCurEnd (struct dnaLoad *dl)
int dnaLoadCurSize (struct dnaLoad *dl)

Variables

static char const rcsid [] = "$Id: dnaLoad.c,v 1.8 2005/03/28 17:21:28 hiram Exp $"


Function Documentation

struct dnaSeq* dnaLoadAll ( char *  fileName  )  [read]

Definition at line 260 of file dnaLoad.c.

References dnaLoadClose(), dnaLoadNext(), dnaLoadOpen(), slAddHead, and slReverse().

00265 {
00266 struct dnaLoad *dl = dnaLoadOpen(fileName);
00267 struct dnaSeq *seqList = NULL, *seq;
00268 while ((seq = dnaLoadNext(dl)) != NULL)
00269     {
00270     slAddHead(&seqList, seq);
00271     }
00272 dnaLoadClose(&dl);
00273 slReverse(seqList);
00274 return seqList;
00275 }

Here is the call graph for this function:

void dnaLoadClose ( struct dnaLoad **  pDl  ) 

Definition at line 85 of file dnaLoad.c.

References dnaLoadStackFreeList(), freeMem(), freez(), dnaLoad::stack, and dnaLoad::topFileName.

Referenced by dnaLoadAll().

00087 {
00088 struct dnaLoad *dl = *pDl;
00089 if (dl != NULL)
00090     {
00091     dnaLoadStackFreeList(&dl->stack);
00092     freeMem(dl->topFileName);
00093     freez(pDl);
00094     }
00095 }

Here is the call graph for this function:

Here is the caller graph for this function:

int dnaLoadCurEnd ( struct dnaLoad dl  ) 

Definition at line 286 of file dnaLoad.c.

References dnaLoad::curEnd.

00291 {
00292 return dl->curEnd;
00293 }

int dnaLoadCurSize ( struct dnaLoad dl  ) 

Definition at line 295 of file dnaLoad.c.

References dnaLoad::curSize.

00298 {
00299 return dl->curSize;
00300 }

int dnaLoadCurStart ( struct dnaLoad dl  ) 

Definition at line 277 of file dnaLoad.c.

References dnaLoad::curStart.

00282 {
00283 return dl->curStart;
00284 }

struct dnaSeq* dnaLoadNext ( struct dnaLoad dl  )  [read]

Definition at line 251 of file dnaLoad.c.

References dnaLoad::curEnd, dnaLoad::curSize, dnaLoad::curStart, and dnaLoadStackOrSingle().

Referenced by dnaLoadAll().

00253 {
00254 struct dnaSeq *seq;
00255 dl->curSize = dl->curStart = dl->curEnd = 0;
00256 seq = dnaLoadStackOrSingle(dl);
00257 return seq;
00258 }

Here is the call graph for this function:

Here is the caller graph for this function:

static struct dnaSeq* dnaLoadNextFromStack ( struct dnaLoad dl  )  [static, read]

Definition at line 161 of file dnaLoad.c.

References AllocVar, cloneString(), dnaLoad::curEnd, dnaLoad::curSize, dnaLoad::curStart, dnaSeq::dna, dnaLoadSingle(), dnaLoadStackFree(), dnaLoadStackNew(), faMixedSpeedReadNext(), dnaLoad::finished, lineFileNextReal(), name, twoBitIndex::name, needLargeMem(), dnaLoadStack::next, twoBitIndex::next, dnaSeq::size, slAddHead, dnaLoad::stack, dnaLoadStack::tbi, dnaLoadStack::textFile, dnaLoadStack::textIsFa, trimSpaces(), TRUE, dnaLoadStack::twoBit, and twoBitReadSeqFrag().

Referenced by dnaLoadStackOrSingle().

00164 {
00165 struct dnaLoadStack *dls;
00166 struct dnaSeq *seq = NULL;
00167 while ((dls = dl->stack) != NULL)
00168     {
00169     if (dls->twoBit)
00170         {
00171         if (dls->tbi != NULL)
00172             {
00173             seq = twoBitReadSeqFrag(dls->twoBit, dls->tbi->name, 0, 0);
00174             dls->tbi = dls->tbi->next;
00175             return seq;
00176             }
00177         else
00178             {
00179             dl->stack = dls->next;
00180             dnaLoadStackFree(&dls);
00181             }
00182         }
00183     else if (dls->textIsFa)
00184         {
00185         DNA *dna;
00186         char *name;
00187         int size;
00188         if (faMixedSpeedReadNext(dls->textFile, &dna, &size, &name))
00189             {
00190             AllocVar(seq);
00191             seq->dna = needLargeMem(size+1);
00192             memcpy((void *)seq->dna, (void *)dna, size);
00193             seq->dna[size] = 0;
00194             seq->size = size;
00195             seq->name = cloneString(name);
00196             dl->curStart = 0;
00197             dl->curEnd = size;
00198             dl->curSize = size;
00199             return seq;
00200             }
00201         else
00202             {
00203             dl->stack = dls->next;
00204             dnaLoadStackFree(&dls);
00205             }
00206         }
00207     else        /* It's a file full of file names. */
00208         {
00209         char *line;
00210         if (lineFileNextReal(dls->textFile, &line))
00211             {
00212             line  = trimSpaces(line);
00213             if ((seq = dnaLoadSingle(line, &dl->curStart, &dl->curEnd, &dl->curSize)) != NULL)
00214                  return seq;
00215             else
00216                  {
00217                  struct dnaLoadStack *newDls;
00218                  newDls = dnaLoadStackNew(line);
00219                  slAddHead(&dl->stack, newDls);
00220                  }
00221             }
00222         else
00223             {
00224             dl->stack = dls->next;
00225             dnaLoadStackFree(&dls);
00226             }
00227         }
00228     }
00229 dl->finished = TRUE;
00230 return NULL;
00231 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct dnaLoad* dnaLoadOpen ( char *  fileName  )  [read]

Definition at line 97 of file dnaLoad.c.

References AllocVar, cloneString(), and dnaLoad::topFileName.

Referenced by dnaLoadAll().

00100 {
00101 struct dnaLoad *dl;
00102 AllocVar(dl);
00103 dl->topFileName = cloneString(fileName);
00104 return dl;
00105 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct dnaSeq* dnaLoadSingle ( char *  fileName,
int *  retStart,
int *  retEnd,
int *  retParentSize 
) [read]

Definition at line 107 of file dnaLoad.c.

References cloneString(), freez(), dnaSeq::name, name, NIB_MASK_MIXED, nibIsFile(), nibLoadAllMasked(), nibOpenVerify(), nibParseName(), PATH_LEN, dnaSeq::size, twoBitClose(), twoBitIsRange(), twoBitOpen(), twoBitParseRange(), twoBitReadSeqFrag(), and twoBitSeqSize().

Referenced by dnaLoadNextFromStack(), and dnaLoadStackOrSingle().

00109 {
00110 struct dnaSeq *seq = NULL;
00111 unsigned start = 0, end = 0;
00112 int parentSize = 0;
00113 if (nibIsFile(fileName))
00114     {
00115     /* Save offset out of fileName for auto-lifting */
00116     char filePath[PATH_LEN];
00117     char name[PATH_LEN];
00118     nibParseName(0, fileName, filePath, name, &start, &end);
00119 
00120     if (end != 0)       /* It's just a range. */
00121         {
00122         FILE *f;
00123         int size;
00124         nibOpenVerify(filePath, &f, &size);
00125         parentSize = size;
00126         }
00127     seq =  nibLoadAllMasked(NIB_MASK_MIXED, fileName);
00128     if (end == 0)
00129          parentSize = end = seq->size;
00130     freez(&seq->name);
00131     seq->name = cloneString(name);
00132     }
00133 else if (twoBitIsRange(fileName))
00134     {
00135     /* Save offset out of fileName for auto-lifting */
00136     char *rangeSpec = cloneString(fileName);
00137     int start, end;
00138     char *file, *seqName;
00139     twoBitParseRange(rangeSpec, &file, &seqName, &start, &end);
00140 
00141     /* Load sequence. */
00142         {
00143         struct twoBitFile *tbf = twoBitOpen(file);
00144         parentSize = twoBitSeqSize(tbf, seqName);
00145         seq = twoBitReadSeqFrag(tbf, seqName, start, end);
00146         twoBitClose(&tbf);
00147         }
00148     if (end == 0)
00149         end = seq->size;
00150     freez(&rangeSpec);
00151     }
00152 if (retStart != NULL)
00153     *retStart = start;
00154 if (retEnd != NULL)
00155     *retEnd = end;
00156 if (retParentSize != NULL)
00157     *retParentSize = parentSize;
00158 return seq;
00159 }

Here is the call graph for this function:

Here is the caller graph for this function:

void dnaLoadStackFree ( struct dnaLoadStack **  pDls  ) 

Definition at line 60 of file dnaLoad.c.

References freez(), lineFileClose(), dnaLoadStack::textFile, dnaLoadStack::twoBit, and twoBitClose().

Referenced by dnaLoadNextFromStack(), and dnaLoadStackFreeList().

00062 {
00063 struct dnaLoadStack *dls = *pDls;
00064 if (dls != NULL)
00065     {
00066     lineFileClose(&dls->textFile);
00067     twoBitClose(&dls->twoBit);
00068     freez(pDls);
00069     }
00070 }

Here is the call graph for this function:

Here is the caller graph for this function:

void dnaLoadStackFreeList ( struct dnaLoadStack **  pList  ) 

Definition at line 72 of file dnaLoad.c.

References dnaLoadStackFree(), and dnaLoadStack::next.

Referenced by dnaLoadClose().

00074 {
00075 struct dnaLoadStack *el, *next;
00076 
00077 for (el = *pList; el != NULL; el = next)
00078     {
00079     next = el->next;
00080     dnaLoadStackFree(&el);
00081     }
00082 *pList = NULL;
00083 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct dnaLoadStack* dnaLoadStackNew ( char *  fileName  )  [read]

Definition at line 35 of file dnaLoad.c.

References AllocVar, twoBitFile::indexList, lineFileNextReal(), lineFileOpen(), lineFileReuse(), dnaLoadStack::tbi, dnaLoadStack::textFile, dnaLoadStack::textIsFa, trimSpaces(), TRUE, dnaLoadStack::twoBit, twoBitIsFile(), and twoBitOpen().

Referenced by dnaLoadNextFromStack(), and dnaLoadStackOrSingle().

00037 {
00038 struct dnaLoadStack *dls;
00039 AllocVar(dls);
00040 if (twoBitIsFile(fileName))
00041     {
00042     dls->twoBit = twoBitOpen(fileName);
00043     dls->tbi = dls->twoBit->indexList;
00044     }
00045 else
00046     {
00047     char *line;
00048     dls->textFile = lineFileOpen(fileName, TRUE);
00049     if (lineFileNextReal(dls->textFile, &line))
00050         {
00051         line = trimSpaces(line);
00052         if (line[0] == '>')
00053             dls->textIsFa = TRUE;
00054         lineFileReuse(dls->textFile);
00055         }
00056     }
00057 return dls;
00058 }

Here is the call graph for this function:

Here is the caller graph for this function:

static struct dnaSeq* dnaLoadStackOrSingle ( struct dnaLoad dl  )  [static, read]

Definition at line 233 of file dnaLoad.c.

References dnaLoad::curEnd, dnaLoad::curSize, dnaLoad::curStart, dnaLoadNextFromStack(), dnaLoadSingle(), dnaLoadStackNew(), dnaLoad::finished, dnaLoad::stack, dnaLoad::topFileName, and TRUE.

Referenced by dnaLoadNext().

00235 {
00236 struct dnaSeq *seq = NULL;
00237 if (dl->finished)
00238     return NULL;
00239 if (dl->stack == NULL)
00240     {
00241     if ((seq = dnaLoadSingle(dl->topFileName, &dl->curStart, &dl->curEnd, &dl->curSize)) != NULL)
00242         {
00243         dl->finished = TRUE;
00244         return seq;
00245         }
00246     dl->stack = dnaLoadStackNew(dl->topFileName);
00247     }
00248 return dnaLoadNextFromStack(dl);
00249 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char const rcsid[] = "$Id: dnaLoad.c,v 1.8 2005/03/28 17:21:28 hiram Exp $" [static]

Definition at line 10 of file dnaLoad.c.


Generated on Tue Dec 25 19:44:33 2007 for blat by  doxygen 1.5.2