lib/pslTbl.c

Go to the documentation of this file.
00001 /* table of psl alignments, grouped by query */
00002 #include "common.h"
00003 #include "pslTbl.h"
00004 #include "psl.h"
00005 #include "hash.h"
00006 #include "linefile.h"
00007 #include "localmem.h"
00008 
00009 static struct pslQuery *pslQueryGet(struct pslTbl *pslTbl,
00010                                     char *qName)
00011 /* get pslQuery object for qName, creating if it doesn't exist. */
00012 {
00013 struct hashEl *qHel = hashStore(pslTbl->queryHash, qName);
00014 if (qHel->val == NULL)
00015     {
00016     struct pslQuery *pslQuery;
00017     lmAllocVar(pslTbl->queryHash->lm, pslQuery);
00018     pslQuery->qName = qHel->name;
00019     qHel->val = pslQuery;
00020     }
00021 return qHel->val;
00022 }
00023 
00024 static void loadPsl(struct pslTbl *pslTbl, char **row)
00025 /* load a psl record into the table */
00026 {
00027 struct psl *psl = pslLoadLm(row, pslTbl->queryHash->lm);
00028 struct pslQuery *pslQuery = pslQueryGet(pslTbl, psl->qName);
00029 slAddHead(&pslQuery->psls, psl);
00030 }
00031 
00032 static void loadPsls(struct pslTbl *pslTbl, char *pslFile)
00033 /* load a psl records into the table */
00034 {
00035 struct lineFile *lf = lineFileOpen(pslFile, TRUE);
00036 char *row[PSL_NUM_COLS];
00037 while (lineFileNextRowTab(lf, row, ArraySize(row)))
00038     loadPsl(pslTbl, row);
00039 lineFileClose(&lf);
00040 }
00041 
00042 struct pslTbl *pslTblNew(char *pslFile, char *setName)
00043 /* construct a new object, loading the psl file.  If setName is NULL, the file
00044 * name is saved as the set name. */
00045 {
00046 struct pslTbl *pslTbl;
00047 AllocVar(pslTbl);
00048 pslTbl->setName = (setName == NULL) ? cloneString(pslFile)
00049     : cloneString(setName);
00050 pslTbl->queryHash = hashNew(22);
00051 loadPsls(pslTbl, pslFile);
00052 return pslTbl;
00053 }
00054 
00055 void pslTblFree(struct pslTbl **pslTblPtr)
00056 /* free object */
00057 {
00058 struct pslTbl *pslTbl = *pslTblPtr;
00059 if (pslTbl != NULL)
00060     {
00061     /* pslQuery and psl objects are in local mem */
00062     freeMem(pslTbl->setName);
00063     hashFree(&pslTbl->queryHash);
00064     freeMem(pslTbl);
00065     }
00066 }
00067 
00068 void pslTblFreeList(struct pslTbl **pslTblList)
00069 /* free list of pslTbls */
00070 {
00071 struct pslTbl *pslTbl = *pslTblList;
00072 while (pslTbl != NULL)
00073     {
00074     struct pslTbl *pslTblDel = pslTbl;
00075     pslTbl = pslTbl->next;
00076     pslTblFree(&pslTblDel);
00077     }
00078 *pslTblList = NULL;
00079 }
00080 
00081 /*
00082  * Local Variables:
00083  * c-file-style: "jkent-c"
00084  * End:
00085  */
00086 

Generated on Tue Dec 25 18:39:31 2007 for blat by  doxygen 1.5.2