lib/flydna.c

Go to the documentation of this file.
00001 /* flydna.c - routines for accessing fly genome and cDNA sequences. 
00002  *
00003  * This file is copyright 2002 Jim Kent, but license is hereby
00004  * granted for all use - public, private or commercial. */
00005 #include "common.h"
00006 #include "snof.h"
00007 #include "dnautil.h"
00008 #include "dnaseq.h"
00009 #include "fa.h"
00010 #include "nt4.h"
00011 #include "cda.h"
00012 #include "wormdna.h"
00013 #include "flydna.h"
00014 
00015 static char const rcsid[] = "$Id: flydna.c,v 1.4 2003/05/06 07:33:42 kate Exp $";
00016 
00017 static char *chromNames[] = {"adh"};
00018 static char *ntFileNames[] = {"c:/biodata/fly/chrom/adh.nt"};
00019 
00020 void flyLoadNt4Genome(struct nt4Seq ***retNt4Seq, int *retNt4Count)
00021 /* Load up entire packed fly genome into memory. */
00022 {
00023 struct nt4Seq **pSeq;
00024 int i;
00025 
00026 pSeq = needMem(ArraySize(ntFileNames) * sizeof(pSeq[0]) );
00027 for (i=0; i<ArraySize(ntFileNames); ++i)
00028         {
00029         pSeq[i] = loadNt4(ntFileNames[i], chromNames[i]);
00030         }
00031 *retNt4Seq = pSeq;
00032 *retNt4Count = ArraySize(ntFileNames);
00033 }
00034 
00035 void flyFreeNt4Genome(struct nt4Seq ***pNt4Seq)
00036 /* Free up packed fly genome. */
00037 {
00038 struct nt4Seq **pSeq;
00039 int i;
00040 
00041 if ((pSeq = *pNt4Seq) == NULL)
00042         return;
00043 for (i=0; i<ArraySize(ntFileNames); ++i)
00044         freeNt4(&pSeq[i]);
00045 freez(pNt4Seq);
00046 }
00047 
00048 void flyChromNames(char ***retNames, int *retNameCount)
00049 /* Get list of fly chromosome names. */
00050 {
00051 *retNames = chromNames;
00052 *retNameCount = ArraySize(chromNames);
00053 }
00054 
00055 void flyFaCommentIntoInfo(char *faComment, struct wormCdnaInfo *retInfo)
00056 /* Process line from .fa file containing information about cDNA into binary
00057  * structure. */
00058 {
00059 if (retInfo)
00060     {
00061     char *s;
00062     zeroBytes(retInfo, sizeof(*retInfo));
00063     /* Separate out first word and use it as name. */
00064     s = strchr(faComment, ' ');
00065     if (s != NULL)
00066             *s++ = 0;
00067     retInfo->name = faComment+1;
00068     retInfo->motherString = faComment;
00069         s = strrchr(retInfo->name, '.');
00070         retInfo->orientation = '+';
00071         if (s != NULL)
00072                 retInfo->orientation = (s[1] == '3' ? '-' : '+');
00073     }
00074 }
00075 
00076 
00077 boolean flyCdnaSeq(char *name, struct dnaSeq **retDna, struct wormCdnaInfo *retInfo)
00078 /* Get a single fly cDNA sequence. Optionally (if retInfo is non-null) get additional
00079  * info about the sequence. */
00080 {
00081 long offset;
00082 char *faComment;
00083 char **pFaComment = (retInfo == NULL ? NULL : &faComment);
00084 static struct snof *cdnaSnof = NULL;
00085 static FILE *cdnaFa;
00086 
00087 if (cdnaSnof == NULL)
00088         cdnaSnof = snofMustOpen("c:/biodata/fly/cDna/allcdna");
00089 if (cdnaFa == NULL)
00090         cdnaFa = mustOpen("c:/biodata/fly/cDna/allcdna.fa", "rb");
00091 if (!snofFindOffset(cdnaSnof, name, &offset))
00092     return FALSE;
00093 fseek(cdnaFa, offset, SEEK_SET);
00094 if (!faReadNext(cdnaFa, name, TRUE, pFaComment, retDna))
00095     return FALSE;
00096 flyFaCommentIntoInfo(faComment, retInfo);
00097 return TRUE;
00098 }
00099 
00100 
00101 char *flyFeaturesDir()
00102 /* Return the features directory. (Includes trailing slash.) */
00103 {
00104 return "C:/biodata/fly/features/";
00105 }
00106 
00107 FILE *flyOpenGoodAli()
00108 /* Opens good alignment file and reads signature. 
00109  * (You can then cdaLoadOne() it.) */
00110 {
00111 return cdaOpenVerify("C:/biodata/fly/cDNA/good.ali");
00112 }

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