TrapperParser Class Reference

#include <trapperparser.h>

Inheritance diagram for TrapperParser:

Inheritance graph
[legend]
Collaboration diagram for TrapperParser:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TrapperParser (DbEnv *dbenv, QString projectDir)
bool startElement (const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &attributes)
bool endElement (const QString &namespaceURI, const QString &localName, const QString &qName)

Private Member Functions

QStringList contigNamesInProjectDir ()

Private Attributes

DbEnv * env
QString projDir
TrapperDoccurrent_doc
db_recno_t current_read_recno
bool format_ok
int curr_start_row
std::set< db_recno_t > curr_set

Detailed Description

Definition at line 12 of file trapperparser.h.


Constructor & Destructor Documentation

TrapperParser::TrapperParser ( DbEnv *  dbenv,
QString  projectDir 
) [inline]

Definition at line 16 of file trapperparser.h.

00016                                                   : 
00017     env(dbenv), projDir(projectDir), current_doc(0), format_ok(false) {}


Member Function Documentation

bool TrapperParser::startElement ( const QString namespaceURI,
const QString localName,
const QString qName,
const QXmlAttributes attributes 
)

Definition at line 14 of file trapperparser.cpp.

References Database::SecondaryIterator< T >::answer(), QString::ascii(), contigNamesInProjectDir(), curr_set, curr_start_row, current_doc, current_read_recno, env, format_ok, Database::SecondaryIterator< T >::last(), TrapperView::message(), TrapperDoc::openDocument(), optimize_layout(), projDir, ReadData::row(), FeatureData::setReadRecno(), ReadData::setRow(), TrapperView::TrapperDoc, QXmlAttributes::value(), and QMessageBox::warning().

00018 {
00019 //   cerr<<"qName: "<<qName<<endl;
00020   
00021   //Three cases:
00022   if ( qName == "TRAPPER" ) {
00023     format_ok = true;
00024     return true;
00025   }
00026   else if ( qName == "contig" && format_ok ) {
00027     /* Basically, all the functionality of TrapperApp::slotImport()
00028        has moved here. The other two cases below now contains the
00029        old functionality of TrapperDoc::import(). */
00030 
00031     curr_start_row = 1;
00032     
00033     //Use attributes to get name
00034     QString contigName = attributes.value("name");
00035     cerr<<"Importing contig "<<contigName<<endl;
00036 
00037 
00038     //Some bookkeeping to check if contig is already present
00039     QStringList contigNamesAlreadyPresent = contigNamesInProjectDir();
00040     if ( contigNamesAlreadyPresent.contains( contigName ) ) {
00041       QString message;
00042       message = QString("The contig name \"%1\" was specified in the import file, but that contig is already present in the project dir. Skipping this one").arg(contigName);
00043       QMessageBox::warning(0,"",message);
00044       return false;
00045     }
00046     //Create directory for contig
00047     QString fName = projDir + "/" + contigName;
00048                 
00049 
00050     //Create directories and databases for this contig
00051 
00052     current_doc = new TrapperDoc(env);
00053     current_doc->openDocument(fName);
00054 
00055     return true;
00056   }
00057   else if ( qName == "section" && format_ok ) {
00058     optimize_layout(curr_start_row, curr_set, current_doc);
00059     curr_set.clear();
00060 
00061     //Figure out start row
00062     Database::SecondaryIterator<ReadData>* row_it = new Database::SecondaryIterator<ReadData>( "pos", current_doc, "ReadData" );
00063     int ret_row = row_it->last();
00064     ReadData* r_row = (ret_row != DB_NOTFOUND) ? row_it->answer() : 0;
00065     if ( r_row ) {
00066       curr_start_row = r_row->row() + 5;
00067     }
00068     delete row_it;
00069     return true;
00070   }
00071   else if ( format_ok ) {
00072 //     cerr<<"parsing "<<qName<<endl;
00073     //Get data name from attributes and put into QString generalDataName
00074     
00075     bool no_row(false);
00076 
00077     //Create object factory for this data type
00078     
00079     Database::Creator<GeneralData> creator( current_doc, qName.ascii() );
00080 
00081     creator.data()->readAttributes( attributes );
00082     
00083     if ( qName != "ReadData" ) {//All other cases are FeatureData and need the corresponding read recno
00084       
00085       FeatureData* fdata = dynamic_cast<FeatureData*>(creator.data());
00086       assert( fdata );
00087       fdata->setReadRecno( current_read_recno );
00088       
00089     }
00090     else {
00091       if ( attributes.value("row") == "" ) {
00092         //Data is readdata and row needs to be figured out
00093         
00094         no_row = true;
00095 
00096 //         ReadsInRect* readsInRect = new ReadsInRect( current_doc );
00097         
00098         
00099         ReadData* rdata = dynamic_cast<ReadData*>(creator.data());
00100         assert( rdata );
00101 //         readsInRect->setWindowCoord( rdata->startPos(), curr_start_row,  rdata->endPos() - rdata->startPos() + 1, numeric_limits<TR_DNA>::max() - curr_start_row );
00102 
00103 //         int previous_row(curr_start_row);
00104 //         int row(0);
00105 //         int num(0);
00106 //         for ( ReadData * r = readsInRect->first(); r; r = readsInRect->next() ) {
00107 //           num++;
00108 //           if ( r->row() - previous_row > 1 ) {
00109 //             row = previous_row + 1;
00110 //             break;
00111 //           }
00112 //           previous_row = r->row();
00113 //         }
00114 //         delete readsInRect;
00115 //         if ( !row ) {
00116 //           if ( num == 0 ) {
00117 //             row = curr_start_row;
00118 //           }
00119 //           else {
00120 //             row = previous_row + 1;
00121 //           }
00122 //         }
00123         rdata->setRow( curr_start_row );
00124       }
00125     }
00126 
00127     db_recno_t new_recno = creator.create( false );//Should give dna, quality etc same recno as read (as previously)
00128     if ( qName == "ReadData" ) {
00129 
00130       current_read_recno = new_recno;
00131       if ( no_row ) {
00132         curr_set.insert(new_recno);
00133       }
00134 
00135     }
00136     return true;
00137   }
00138   return false;
00139 }

bool TrapperParser::endElement ( const QString namespaceURI,
const QString localName,
const QString qName 
)

Definition at line 141 of file trapperparser.cpp.

References curr_set, curr_start_row, current_doc, and optimize_layout().

00143 {
00144   if ( qName == "contig" ) {
00145     
00146     optimize_layout(curr_start_row, curr_set, current_doc);
00147     curr_set.clear();
00148 
00149     //Delete old doc, if any
00150     delete current_doc;
00151 //     cerr<<"end contig"<<endl;
00152   }
00153   return true;
00154 }

QStringList TrapperParser::contigNamesInProjectDir (  )  [private]

Definition at line 158 of file trapperparser.cpp.

References QDir::entryList(), QDir::exists(), projDir, QDir::setFilter(), and QDir::setSorting().

Referenced by startElement().

00159 {
00160     QString contigName;
00161     QDir d( projDir );
00162     Q_ASSERT( d.exists() );
00163     d.setFilter( QDir::Dirs | QDir::NoSymLinks );
00164     d.setSorting( QDir::Name );
00165     QStringList slist = d.entryList();
00166     return slist;
00167 }


Member Data Documentation

DbEnv* TrapperParser::env [private]

Definition at line 32 of file trapperparser.h.

Referenced by startElement().

QString TrapperParser::projDir [private]

Definition at line 33 of file trapperparser.h.

Referenced by contigNamesInProjectDir(), and startElement().

TrapperDoc* TrapperParser::current_doc [private]

Definition at line 35 of file trapperparser.h.

Referenced by endElement(), and startElement().

db_recno_t TrapperParser::current_read_recno [private]

Definition at line 36 of file trapperparser.h.

Referenced by startElement().

bool TrapperParser::format_ok [private]

Definition at line 37 of file trapperparser.h.

Referenced by startElement().

int TrapperParser::curr_start_row [private]

Definition at line 38 of file trapperparser.h.

Referenced by endElement(), and startElement().

std::set<db_recno_t> TrapperParser::curr_set [private]

Definition at line 39 of file trapperparser.h.

Referenced by endElement(), and startElement().


The documentation for this class was generated from the following files:
Generated on Fri Jul 17 20:19:54 2009 for ngsview by  doxygen 1.5.1