@@ -295,8 +295,7 @@ struct dnaSeq *faReadAa(char *fileName)
295295return faReadSeq (fileName , FALSE);
296296}
297297
298- static unsigned faFastBufSize = 0 ;
299- static DNA * faFastBuf ;
298+
300299
301300static void expandFaFastBuf (int bufPos , int minExp , DNA * * faFastBuf , unsigned * faFastBufSize )
302301/* Make faFastBuf bigger. */
@@ -328,15 +327,15 @@ static void expandFaFastBuf(int bufPos, int minExp, DNA **faFastBuf, unsigned *f
328327 }
329328}
330329
331- void faFreeFastBuf ()
330+ void faFreeFastBuf (DNA * * faFastBuf , unsigned * faFastBufSize )
332331/* Free up buffers used in fa fast and speedreading. */
333332{
334- freez (& faFastBuf );
335- faFastBufSize = 0 ;
333+ freez (faFastBuf );
334+ * faFastBufSize = 0 ;
336335}
337336
338337
339- boolean faFastReadNext (FILE * f , DNA * * retDna , int * retSize , char * * retName )
338+ boolean faFastReadNext (FILE * f , DNA * * retDna , int * retSize , char * * retName , DNA * * faFastBuf , unsigned * faFastBufSize )
340339/* Read in next FA entry as fast as we can. Return FALSE at EOF.
341340 * The returned DNA and name will be overwritten by the next call
342341 * to this function. */
@@ -347,8 +346,6 @@ boolean faFastReadNext(FILE *f, DNA **retDna, int *retSize, char **retName)
347346 int nameIx = 0 ;
348347 boolean gotSpace = FALSE;
349348
350- unsigned faFastBufSize = 0 ;
351- DNA * faFastBuf ;
352349
353350 /* Seek to next '\n' and save first word as name. */
354351 dnaUtilOpen ();
@@ -389,8 +386,8 @@ boolean faFastReadNext(FILE *f, DNA **retDna, int *retSize, char **retName)
389386 if (c == 0 ) c = 'n' ;
390387 }
391388 if (bufIx >= faFastBufSize )
392- expandFaFastBuf (bufIx , 0 , & faFastBuf , & faFastBufSize );
393- faFastBuf [bufIx ++ ] = c ;
389+ expandFaFastBuf (bufIx , 0 , faFastBuf , faFastBufSize );
390+ * faFastBuf [bufIx ++ ] = c ;
394391 if (c == 0 )
395392 {
396393 * retDna = faFastBuf ;
@@ -532,15 +529,14 @@ for (i=0; i<size; ++i)
532529 }
533530}
534531
535- boolean faSomeSpeedReadNext (struct lineFile * lf , DNA * * retDna , int * retSize , char * * retName , boolean isDna )
532+ boolean faSomeSpeedReadNext (struct lineFile * lf , DNA * * retDna , int * retSize , char * * retName , boolean isDna ,
533+ DNA * * faFastBuf , unsigned * faFastBufSize )
536534/* Read in DNA or Peptide FA record. */
537535{
538536 char * poly ;
539537 int size ;
540- unsigned faFastBufSize = 0 ;
541- DNA * faFastBuf ;
542538
543- if (!faMixedSpeedReadNext (lf , retDna , retSize , retName , & faFastBuf , & faFastBufSize ))
539+ if (!faMixedSpeedReadNext (lf , retDna , retSize , retName , faFastBuf , faFastBufSize ))
544540 return FALSE;
545541 size = * retSize ;
546542 poly = * retDna ;
@@ -551,23 +547,25 @@ boolean faSomeSpeedReadNext(struct lineFile *lf, DNA **retDna, int *retSize, cha
551547 return TRUE;
552548}
553549
554- boolean faPepSpeedReadNext (struct lineFile * lf , DNA * * retDna , int * retSize , char * * retName )
550+ boolean faPepSpeedReadNext (struct lineFile * lf , DNA * * retDna , int * retSize , char * * retName ,
551+ DNA * * faFastBuf , unsigned * faFastBufSize )
555552/* Read in next peptide FA entry as fast as we can. */
556553{
557- return faSomeSpeedReadNext (lf , retDna , retSize , retName , FALSE);
554+ return faSomeSpeedReadNext (lf , retDna , retSize , retName , FALSE, faFastBuf , faFastBufSize );
558555}
559556
560- boolean faSpeedReadNext (struct lineFile * lf , DNA * * retDna , int * retSize , char * * retName )
557+ boolean faSpeedReadNext (struct lineFile * lf , DNA * * retDna , int * retSize , char * * retName ,
558+ DNA * * faFastBuf , unsigned * faFastBufSize )
561559/* Read in next FA entry as fast as we can. Faster than that old,
562560 * pokey faFastReadNext. Return FALSE at EOF.
563561 * The returned DNA and name will be overwritten by the next call
564562 * to this function. */
565563{
566- return faSomeSpeedReadNext (lf , retDna , retSize , retName , TRUE);
564+ return faSomeSpeedReadNext (lf , retDna , retSize , retName , TRUE, faFastBuf , faFastBufSize );
567565}
568566
569567static struct dnaSeq * faReadAllMixableInLf (struct lineFile * lf ,
570- boolean isDna , boolean mixed )
568+ boolean isDna , boolean mixed , DNA * * faFastBuf , unsigned * faFastBufSize )
571569/* Return list of all sequences from open fa file.
572570 * Mixed case parameter overrides isDna. If mixed is false then
573571 * will return DNA in lower case and non-DNA in upper case. */
@@ -578,15 +576,13 @@ static struct dnaSeq *faReadAllMixableInLf(struct lineFile *lf,
578576 char * name = buf ;
579577 int size ;
580578 boolean ok ;
581- unsigned faFastBufSize = 0 ;
582- DNA * faFastBuf ;
583579
584580 for (;;)
585581 {
586582 if (mixed )
587- ok = faMixedSpeedReadNext (lf , & dna , & size , & name , & faFastBuf , & faFastBufSize );
583+ ok = faMixedSpeedReadNext (lf , & dna , & size , & name , faFastBuf , faFastBufSize );
588584 else
589- ok = faSomeSpeedReadNext (lf , & dna , & size , & name , isDna );
585+ ok = faSomeSpeedReadNext (lf , & dna , & size , & name , isDna , faFastBuf , faFastBufSize );
590586 if (!ok )
591587 break ;
592588 AllocVar (seq );
@@ -596,27 +592,27 @@ static struct dnaSeq *faReadAllMixableInLf(struct lineFile *lf,
596592 slAddHead (& seqList , seq );
597593 }
598594 slReverse (& seqList );
599- faFreeFastBuf (& faFastBuf , & faFastBufSize );
600595 return seqList ;
601596}
602597
603- static struct dnaSeq * faReadAllSeqMixable (char * fileName , boolean isDna , boolean mixed )
598+ static struct dnaSeq * faReadAllSeqMixable (char * fileName , boolean isDna , boolean mixed ,
599+ DNA * * faFastBuf , unsigned * faFastBufSize )
604600/* Return list of all sequences in FA file.
605601 * Mixed case parameter overrides isDna. If mixed is false then
606602 * will return DNA in lower case and non-DNA in upper case. */
607603{
608604struct lineFile * lf = lineFileOpen (fileName , FALSE);
609- struct dnaSeq * seqList = faReadAllMixableInLf (lf , isDna , mixed );
605+ struct dnaSeq * seqList = faReadAllMixableInLf (lf , isDna , mixed , faFastBuf , faFastBufSize );
610606lineFileClose (& lf );
611607return seqList ;
612608}
613609
614- struct hash * faReadAllIntoHash (char * fileName , enum dnaCase dnaCase )
610+ struct hash * faReadAllIntoHash (char * fileName , enum dnaCase dnaCase , DNA * * faFastBuf , unsigned * faFastBufSize )
615611/* Return hash of all sequences in FA file. */
616612{
617613boolean isDna = (dnaCase == dnaLower );
618614boolean isMixed = (dnaCase == dnaMixed );
619- struct dnaSeq * seqList = faReadAllSeqMixable (fileName , isDna , isMixed );
615+ struct dnaSeq * seqList = faReadAllSeqMixable (fileName , isDna , isMixed , faFastBuf , faFastBufSize );
620616struct hash * hash = hashNew (18 );
621617struct dnaSeq * seq ;
622618for (seq = seqList ; seq != NULL ; seq = seq -> next )
@@ -629,32 +625,32 @@ return hash;
629625}
630626
631627
632- struct dnaSeq * faReadAllSeq (char * fileName , boolean isDna )
628+ struct dnaSeq * faReadAllSeq (char * fileName , boolean isDna , DNA * * faFastBuf , unsigned * faFastBufSize )
633629/* Return list of all sequences in FA file. */
634630{
635- return faReadAllSeqMixable (fileName , isDna , FALSE);
631+ return faReadAllSeqMixable (fileName , isDna , FALSE, faFastBuf , faFastBufSize );
636632}
637633
638- struct dnaSeq * faReadAllDna (char * fileName )
634+ struct dnaSeq * faReadAllDna (char * fileName , DNA * * faFastBuf , unsigned * faFastBufSize )
639635/* Return list of all DNA sequences in FA file. */
640636{
641- return faReadAllSeq (fileName , TRUE);
637+ return faReadAllSeq (fileName , TRUE, faFastBuf , faFastBufSize );
642638}
643639
644- struct dnaSeq * faReadAllPep (char * fileName )
640+ struct dnaSeq * faReadAllPep (char * fileName , DNA * * faFastBuf , unsigned * faFastBufSize )
645641/* Return list of all peptide sequences in FA file. */
646642{
647- return faReadAllSeq (fileName , FALSE);
643+ return faReadAllSeq (fileName , FALSE, faFastBuf , faFastBufSize );
648644}
649645
650- struct dnaSeq * faReadAllMixed (char * fileName )
646+ struct dnaSeq * faReadAllMixed (char * fileName , DNA * * faFastBuf , unsigned * faFastBufSize )
651647/* Read in mixed case fasta file, preserving case. */
652648{
653- return faReadAllSeqMixable (fileName , FALSE, TRUE);
649+ return faReadAllSeqMixable (fileName , FALSE, TRUE, faFastBuf , faFastBufSize );
654650}
655651
656- struct dnaSeq * faReadAllMixedInLf (struct lineFile * lf )
652+ struct dnaSeq * faReadAllMixedInLf (struct lineFile * lf , DNA * * faFastBuf , unsigned * faFastBufSize )
657653/* Read in mixed case sequence from open fasta file. */
658654{
659- return faReadAllMixableInLf (lf , FALSE, TRUE);
655+ return faReadAllMixableInLf (lf , FALSE, TRUE, faFastBuf , faFastBufSize );
660656}
0 commit comments