+ added compatiblity to PipelineHeuristic parser
authorfabio <fabio@e1793c9e-67f9-0310-80fc-b846ff1f7b36>
Mon, 2 Jun 2008 16:57:29 +0000 (16:57 +0000)
committerfabio <fabio@e1793c9e-67f9-0310-80fc-b846ff1f7b36>
Mon, 2 Jun 2008 16:57:29 +0000 (16:57 +0000)
git-svn-id: http://svn.tuebingen.mpg.de/ag-raetsch/projects/QPalma@9342 e1793c9e-67f9-0310-80fc-b846ff1f7b36

ParaParser/ParaParser.cpp
ParaParser/ParaParser.h

index 53af6be..f0289c4 100644 (file)
@@ -149,7 +149,7 @@ ParaParser::ParaParser(const char* fmt, char** _fields, int num_entries, storage
  *
  */
 
-void ParaParser::create_entry_from_line(const char* current_line, char* format_string) {
+void ParaParser::create_entry_from_line(const char* current_line, char* format_string, char* lineBeginPtr, char* lineEndPtr) {
    //printf("current line is %s",current_line);
    
    // create an array of void ptrs
@@ -178,6 +178,7 @@ void ParaParser::create_entry_from_line(const char* current_line, char* format_s
    if ( current_mode == IN_VECTOR ) {
       //printf("size is %zd\n",v_entries->size());
       v_entries->push_back(current_entries);
+      v_ptr_entries->push_back(make_pair(lineBeginPtr,lineEndPtr));
       //printf("size is %zd\n",v_entries->size());
    }
 
@@ -226,7 +227,7 @@ int ParaParser::parseFile(char* reads_filename) {
    }
 
    off_t reads_filesize = reads_stat.st_size;
-   //printf("Reads file is of size %lu bytes\n",(unsigned long) reads_filesize);
+   printf("Reads file is of size %lu bytes\n",(unsigned long) reads_filesize);
 
    if ( current_mode == IN_VECTOR )
       v_entries = new VECTOR();
@@ -242,7 +243,7 @@ int ParaParser::parseFile(char* reads_filename) {
    }
 
    close(reads_fid);
-   //printf("Successfully mapped %lu bytes of reads file into memory\n",(unsigned long)reads_filesize);
+   printf("Successfully mapped %lu bytes of reads file into memory\n",(unsigned long)reads_filesize);
                                       
    char* lineBeginPtr = (char*) reads_area;
    char* lineEndPtr = (char*) reads_area;     
@@ -261,11 +262,13 @@ int ParaParser::parseFile(char* reads_filename) {
    int readCtr = 0;
    int status = 0;
 
+   printf("Starting to parse file...\n");
+
    while(1) {
       if (strcmp(current_line,"") == 0) 
          break;
 
-      create_entry_from_line(current_line,format_string);
+      create_entry_from_line(current_line,format_string,lineBeginPtr,lineEndPtr);
 
       if (status != 0 )
          printf("Error while parsing line (status=%d).",status);
@@ -280,6 +283,8 @@ int ParaParser::parseFile(char* reads_filename) {
       readCtr += 1;
    }
 
+   printf("Successfully parsed file !\n");
+
    // unmap parsed file
    status = munmap(reads_area,reads_filesize);
    if(status != 0)
@@ -310,6 +315,9 @@ PyObject* ParaParser::fetchEntry(map_key_t id) {
 
    char** current_entry;
 
+   char* lineBeginPtr = 0;
+   char* lineEndPtr = 0;
+
    if ( current_mode == IN_VECTOR ) {
       //printf("IN_VECTOR mode\n");
       if (id >= v_entries->size())
@@ -317,6 +325,9 @@ PyObject* ParaParser::fetchEntry(map_key_t id) {
 
       //printf("size %d\n",v_entries->size());
       current_entry = (*v_entries)[id];
+      pair<char*,char*> ptr_pair = (*v_ptr_entries)[id];
+      lineBeginPtr = ptr_pair.first;
+      lineEndPtr = ptr_pair.second;
    }
 
    if ( current_mode == IN_MAP ) {
@@ -369,5 +380,16 @@ PyObject* ParaParser::fetchEntry(map_key_t id) {
    */
 
    //printf("end of fetchEntry\n");
+   PyObject *return_value = PyTuple_New(2);
+   PyTuple_SetItem(return_value,0,line_dict);
+
+   char* current_line = (char*) malloc(sizeof(char)*512);
+   memset(current_line,0,512);
+   unsigned long line_size = lineEndPtr - lineBeginPtr;
+   strncpy(current_line,lineBeginPtr,line_size);
+
+   PyObject *original_line = PyString_FromString(current_line);
+   PyTuple_SetItem(return_value,1,original_line);
+
    return line_dict;
 }
index 807ab57..8a10955 100644 (file)
@@ -4,6 +4,7 @@
 #include <Python.h>
 #include <map>
 #include <vector>
+#include <utility>
 using namespace std;
 
 struct KeyCmp {
@@ -20,6 +21,7 @@ typedef unsigned long map_key_t;
 typedef map<map_key_t,char**,KeyCmp> MAP;
 
 typedef vector<char**> VECTOR;
+typedef vector<pair<char*,char*> > PTR_VECTOR;
 
 
 class ParaParser{
@@ -34,15 +36,26 @@ class ParaParser{
 
       MAP *entries;
       VECTOR *v_entries;
+      PTR_VECTOR *v_ptr_entries;
 
    public:
       ParaParser(const char* fmt, char** _fields, int num_entries, storage_mode mode);
       int parseFile(char* reads_filename);
-      void create_entry_from_line(const char* current_line, char* format_string);
+      //void create_entry_from_line(const char* current_line, char* format_string);
+      void create_entry_from_line(const char* current_line, char* format_string, char* lineBeginPtr, char* lineEndPtr);
       PyObject* fetchEntry(map_key_t id);
+      int getSize(storage_mode mode) {
+         if ( current_mode == IN_VECTOR )
+            return v_entries->size();
+
+         if ( current_mode == IN_MAP )
+            return v_entries->size();
+      }
 
       ~ParaParser(){}
 };
 
+
+
 #endif // __PARAPARSER_H__