00001 #include "format.h" 00002 #include "log.h" 00003 #include "linestream.h" 00004 #include "common.h" 00005 #include "elandParser.h" 00006 00007 00008 00016 static LineStream ls = NULL; 00017 00018 00019 00024 void elandParser_init (char *fileName) 00025 { 00026 ls = ls_createFromFile (fileName); 00027 } 00028 00029 00030 00034 void elandParser_deInit (void) 00035 { 00036 ls_destroy (ls); 00037 } 00038 00039 00040 00041 static void elandParser_freeQuery (ElandQuery *currElandQuery) 00042 { 00043 if (currElandQuery == NULL) { 00044 return; 00045 } 00046 hlr_free (currElandQuery->sequenceName); 00047 hlr_free (currElandQuery->sequence); 00048 hlr_free (currElandQuery->matchCode); 00049 if (currElandQuery->chromosome != NULL) { 00050 hlr_free (currElandQuery->chromosome); 00051 } 00052 freeMem (currElandQuery); 00053 } 00054 00055 00056 00069 ElandQuery* elandParser_nextQuery (void) 00070 { 00071 WordIter w; 00072 char *line,*token,*pos; 00073 static ElandQuery *currElandQuery = NULL; 00074 00075 while (line = ls_nextLine (ls)) { 00076 if (line[0] == '\0') { 00077 continue; 00078 } 00079 elandParser_freeQuery (currElandQuery); 00080 currElandQuery = NULL; 00081 AllocVar (currElandQuery); 00082 w = wordIterCreate (line,"\t",0); 00083 currElandQuery->sequenceName = hlr_strdup (wordNext (w) + 1); // remove the '>' character at beginning of the line 00084 currElandQuery->sequence = hlr_strdup (wordNext (w)); 00085 currElandQuery->matchCode = hlr_strdup (wordNext (w)); 00086 if (strEqual (currElandQuery->matchCode,"QC")) { 00087 wordIterDestroy (w); 00088 return currElandQuery; 00089 } 00090 currElandQuery->exactMatches = atoi (wordNext (w)); 00091 currElandQuery->oneErrorMatches = atoi (wordNext (w)); 00092 currElandQuery->twoErrorMatches = atoi (wordNext (w)); 00093 token = wordNext (w); 00094 if (token == NULL) { 00095 wordIterDestroy (w); 00096 return currElandQuery; 00097 } 00098 if (!(pos = strchr (token,'.'))) { 00099 die ("Expected '.' in chromosome name: %s",token); 00100 } 00101 *pos = '\0'; 00102 currElandQuery->chromosome = hlr_strdup (pos + 1); 00103 currElandQuery->position = atoi (wordNext (w)); 00104 token = wordNext (w); 00105 if (token[0] == 'F') { 00106 currElandQuery->strand = '+'; 00107 } 00108 else if (token[0] == 'R') { 00109 currElandQuery->strand = '-'; 00110 } 00111 wordIterDestroy (w); 00112 return currElandQuery; 00113 } 00114 elandParser_freeQuery (currElandQuery); 00115 currElandQuery = NULL; 00116 return currElandQuery; 00117 }