include/readFasta.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void readFasta_open (char *filename)
int4 readFasta_readSequence ()
void readFasta_close ()

Variables

char * readFasta_descriptionBuffer
char * readFasta_sequenceBuffer
uint4 readFasta_sequenceLength
uint4 readFasta_descriptionLength


Function Documentation

void readFasta_close (  ) 

Definition at line 159 of file readFasta.c.

References readFasta_descriptionBuffer, readFasta_file, readFasta_lineBuffer, and readFasta_sequenceBuffer.

Referenced by determineDbAlphabetType(), and main().

00160 {
00161         free(readFasta_lineBuffer);
00162         free(readFasta_sequenceBuffer);
00163         free(readFasta_descriptionBuffer);
00164     fclose(readFasta_file);
00165 }

Here is the caller graph for this function:

void readFasta_open ( char *  filename  ) 

Definition at line 23 of file readFasta.c.

References global_malloc(), readFasta_bufferAlloc, readFasta_descriptionBuffer, readFasta_endReached, readFasta_file, readFasta_filename, readFasta_lineBuffer, readFasta_lineLength, readFasta_sequenceBuffer, and readFasta_sequenceBufferAlloc.

Referenced by determineDbAlphabetType(), and main().

00024 {
00025         readFasta_file = fopen(filename, "r");
00026 
00027     if (readFasta_file == NULL)
00028     {
00029         fprintf(stderr, "%s\n", strerror(errno));
00030                 fprintf(stderr, "Error opening file %s for reading\n", filename);
00031                 exit(-1);
00032     }
00033 
00034     readFasta_filename = filename;
00035 
00036         readFasta_bufferAlloc = 10;
00037         readFasta_sequenceBufferAlloc = 10;
00038 
00039     // Declare memory for buffers
00040         readFasta_sequenceBuffer = (char*)global_malloc(sizeof(char) * readFasta_bufferAlloc);
00041         readFasta_descriptionBuffer = (char*)global_malloc(sizeof(char) * readFasta_bufferAlloc);
00042         readFasta_lineBuffer = (char*)global_malloc(sizeof(char) * readFasta_bufferAlloc);
00043     readFasta_lineBuffer[0] = '\0'; readFasta_lineBuffer[1] = '\0';
00044     readFasta_lineLength = 1;
00045     readFasta_endReached = 0;
00046 }

Here is the call graph for this function:

Here is the caller graph for this function:

int4 readFasta_readSequence (  ) 

Definition at line 49 of file readFasta.c.

References global_realloc(), readFasta_bufferAlloc, readFasta_descriptionBuffer, readFasta_descriptionLength, readFasta_endReached, readFasta_file, readFasta_lineBuffer, readFasta_lineLength, readFasta_sequenceBuffer, readFasta_sequenceBufferAlloc, readFasta_sequenceLength, and uint4.

Referenced by determineDbAlphabetType(), and main().

00050 {
00051         uint4 pos, pos2;
00052 
00053         // We've reached end of file
00054         if (readFasta_endReached)
00055         return 0;
00056 
00057         // Clear sequence buffer
00058         readFasta_sequenceBuffer[0] = '\0';
00059     readFasta_sequenceLength = 0;
00060 
00061     // Line buffer contains description for new sequence
00062         memcpy(readFasta_descriptionBuffer, readFasta_lineBuffer + 1, readFasta_lineLength);
00063     readFasta_descriptionLength = readFasta_lineLength - 1;
00064 
00065         // Read each line from FASTA file
00066         while (!readFasta_endReached && fgets(readFasta_lineBuffer, readFasta_bufferAlloc, readFasta_file))
00067     {
00068         // If we didn't read an entire line
00069         readFasta_lineLength = strlen(readFasta_lineBuffer);
00070         while (readFasta_lineBuffer[readFasta_lineLength - 1] != '\n')
00071         {
00072 //              printf("Read bit \"%s\"\n", readFasta_lineBuffer);
00073 
00074             // Double size of the buffers and read more
00075                         readFasta_lineBuffer = (char*)global_realloc(readFasta_lineBuffer,
00076                                    sizeof(char) * readFasta_bufferAlloc * 2);
00077                         readFasta_descriptionBuffer = (char*)global_realloc(readFasta_descriptionBuffer,
00078                                           sizeof(char) * readFasta_bufferAlloc * 2);
00079 
00080                         // Read next line
00081                         if (!fgets(readFasta_lineBuffer + readFasta_bufferAlloc - 1, readFasta_bufferAlloc, readFasta_file))
00082                         {
00083                 // If reached end of file
00084                 readFasta_lineLength = strlen(readFasta_lineBuffer);
00085                 readFasta_endReached = 1;
00086                 break;
00087                         }
00088 
00089             readFasta_bufferAlloc = readFasta_bufferAlloc * 2 - 1;
00090             readFasta_lineLength = strlen(readFasta_lineBuffer);
00091         }
00092 
00093         // Remove the trailing \n
00094         if (readFasta_lineBuffer[readFasta_lineLength - 1] == '\n')
00095         {
00096             readFasta_lineLength--;
00097             readFasta_lineBuffer[readFasta_lineLength] = '\0';
00098                 }
00099 
00100 //        printf("Read line \"%s\"\n", readFasta_lineBuffer);
00101 
00102         // If this is a description line
00103         if (readFasta_lineBuffer[0] == '>')
00104         {
00105 //              printf("DESCRIPTION!\n");
00106                         // If the description buffer is not empty
00107             if (readFasta_descriptionBuffer[0] != '\0')
00108                         {
00109                 return 1;
00110             }
00111 
00112 //              printf("(First)\n");
00113             // Else line is description of first sequence
00114             memcpy(readFasta_descriptionBuffer, readFasta_lineBuffer + 1, readFasta_lineLength);
00115             readFasta_descriptionLength = readFasta_lineLength - 1;
00116 
00117 //            printf("(end copy)\n");
00118         }
00119         // Otherwise it is part of a sequence
00120         else
00121         {
00122                 // If there is insufficient space in the current sequence buffer
00123                         if (readFasta_lineLength + readFasta_sequenceLength + 1 > readFasta_sequenceBufferAlloc)
00124             {
00125                 // Increase size of the buffer
00126                                 readFasta_sequenceBufferAlloc = (readFasta_lineLength + readFasta_sequenceLength + 1) * 2;
00127                 readFasta_sequenceBuffer = (char*)global_realloc(readFasta_sequenceBuffer,
00128                                            sizeof(char) * readFasta_sequenceBufferAlloc);
00129                         }
00130 
00131             // Remove non-alphabet characters from the sequence
00132                         pos = 0; pos2 = 0;
00133             while (pos < readFasta_lineLength)
00134             {
00135                 if ((readFasta_lineBuffer[pos] >= 'a' && readFasta_lineBuffer[pos] <= 'z') ||
00136                     (readFasta_lineBuffer[pos] >= 'A' && readFasta_lineBuffer[pos] <= 'Z'))
00137                 {
00138                         readFasta_lineBuffer[pos2] = readFasta_lineBuffer[pos];
00139                     pos2++;
00140                 }
00141                 pos++;
00142             }
00143                         readFasta_lineBuffer[pos2] = '\0';
00144                         readFasta_lineLength = pos2;
00145 
00146             // Append new part of sequence onto the current sequence buffer contents
00147                         memcpy(readFasta_sequenceBuffer + readFasta_sequenceLength, readFasta_lineBuffer,
00148                    readFasta_lineLength + 1);
00149             readFasta_sequenceLength += readFasta_lineLength;
00150         }
00151     }
00152 
00153     // End of file. Return contents of last sequence
00154     readFasta_endReached = 1;
00155     return 1;
00156 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char* readFasta_descriptionBuffer

Definition at line 4 of file readFasta.h.

Referenced by main(), readFasta_close(), readFasta_open(), and readFasta_readSequence().

uint4 readFasta_descriptionLength

Definition at line 7 of file readFasta.h.

Referenced by main(), and readFasta_readSequence().

char* readFasta_sequenceBuffer

Definition at line 5 of file readFasta.h.

Referenced by determineDbAlphabetType(), main(), readFasta_close(), readFasta_open(), and readFasta_readSequence().

uint4 readFasta_sequenceLength

Definition at line 6 of file readFasta.h.

Referenced by determineDbAlphabetType(), main(), and readFasta_readSequence().


Generated on Wed Dec 19 20:51:22 2007 for fsa-blast by  doxygen 1.5.2