+ minor modifications
authorfabio <fabio@e1793c9e-67f9-0310-80fc-b846ff1f7b36>
Thu, 15 May 2008 16:59:59 +0000 (16:59 +0000)
committerfabio <fabio@e1793c9e-67f9-0310-80fc-b846ff1f7b36>
Thu, 15 May 2008 16:59:59 +0000 (16:59 +0000)
TODO
+ fix bug in the array access (fetch function)

git-svn-id: http://svn.tuebingen.mpg.de/ag-raetsch/projects/QPalma@9040 e1793c9e-67f9-0310-80fc-b846ff1f7b36

cparser/qparser.c
cparser/test.py

index 3e52d16..f8df208 100644 (file)
@@ -24,28 +24,25 @@ int num_reads;
 const char* line_format = "%lu\t%d\t%c\t%s\t%d\t%d\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n";
 
 int create_read_from_line(Read* newRead, const char* current_line) {
-
-   int size = 72;
-   newRead->seq      = malloc(sizeof(char)*(size));
-
-   size = 36;
-   newRead->prb      = malloc(sizeof(char)*(size));
-   newRead->cal_prb  = malloc(sizeof(char)*(size));
-   newRead->chastity = malloc(sizeof(char)*(size));
-   newRead->gene_id  = malloc(sizeof(char)*(size));
+   int buffer_size= 64;                                                                                                                                                                                                        
+   printf("current line is %s\n",current_line);
 
    int entries_found = sscanf(current_line,line_format,&(newRead->id),
    &(newRead->chr),&(newRead->strand),newRead->seq,&(newRead->splitpos),&(newRead->size),
    newRead->prb,newRead->cal_prb,newRead->chastity,newRead->gene_id,&(newRead->p_start),
    &(newRead->exon_stop),&(newRead->exon_start),&(newRead->p_stop),&(newRead->true_cut));
 
+   if (entries_found != 15) {
+      return -1;
+   }
+
    Py_ssize_t idx;
    for(idx=0;idx<strlen(newRead->seq);idx++) {
       if ( 65 <= newRead->seq[idx] && newRead->seq[idx] < 85)
          newRead->seq[idx] = newRead->seq[idx]+32;
    }
 
-   for(idx=0;idx<size;idx++) {
+   for(idx=0;idx<newRead->size;idx++) {
       newRead->prb[idx]       -= 50;
       newRead->cal_prb[idx]   -= 64;
       newRead->chastity[idx]  += 10;
@@ -57,11 +54,11 @@ int create_read_from_line(Read* newRead, const char* current_line) {
    if ( newRead->strand == 'P' )
       newRead->strand = '-';
 
-   return entries_found;
+   return 0;
 }
 
 
-static void Py_free_everything(){
+static void Py_free_everything() {
 
    size_t idx;
    for(idx=0;idx<num_reads;idx++)
@@ -73,18 +70,16 @@ static void Py_free_everything(){
 
 
 static int set_item_from_line(const char* current_line) {
-   printf("current line is %s\n",current_line);
-
    Read* current_read = read_alloc();
-   int entries_found = create_read_from_line(current_read,current_line);
-
-   if (entries_found != 15) {
-      return entries_found;
-   }
+   int status = create_read_from_line(current_read,current_line);
+   if(status != 0)
+      return status;
 
    read_array[num_reads] = current_read;
    id_map[num_reads] = current_read->id;
    num_reads++;
+
+   return 0;
 }
 
 
@@ -131,11 +126,13 @@ static PyObject * Py_fetch_read(PyObject *obj, PyObject *args) {
    unsigned long read_id;
    unsigned long current_read_id;
 
-   if (!PyArg_ParseTuple(args, "i", &read_id)) {
+   if (!PyArg_ParseTuple(args, "l", &read_id)) {
                PyErr_Warn(PyExc_Warning, "qparser.parse_reads: Invalid parameters.");
       return NULL;
    }
-   
+  
+   //printf("got index %lu\n",read_id);
+  
    PyObject* read_dict = PyDict_New();
 
    size_t idx;
@@ -251,7 +248,8 @@ static PyObject * Py_parse_reads(PyObject *obj, PyObject *args) {
 
 static PyMethodDef qparserMethods[] = {
        {"parse_reads",  Py_parse_reads, METH_VARARGS,"Test UInt8 behaviour."},
-       {"free_everything",  Py_free_everything, METH_VARARGS,"Test UInt8 behaviour."},
+   {"fetch_read", Py_fetch_read, METH_VARARGS,"Test UInt8 behaviour."},
+       //{"free_everything",  Py_free_everything, 0,"Test UInt8 behaviour."},
        {NULL, NULL, 0, NULL}        /* Sentinel */
 };
 
index abbaf87..81c3cb1 100644 (file)
@@ -22,6 +22,8 @@ def test_module():
 
    print 'found %d num reads' % num_reads
 
+   current_read = qparser.fetch_read(1000000000002)
+   print current_read
 
 def _test_module():
    filename = '/fml/ag-raetsch/share/projects/qpalma/solexa/new_run/allReads.full_10k'