TrapperDoc Class Reference

TrapperDoc provides a document object for a document-view model. More...

#include <trapperdoc.h>

Inheritance diagram for TrapperDoc:

Inheritance graph
[legend]
Collaboration diagram for TrapperDoc:

Collaboration graph
[legend]
List of all members.

Public Slots

void updateAllViews (TrapperView *sender)

Public Member Functions

 TrapperDoc (DbEnv *dbenv)
 ~TrapperDoc ()
void addView (TrapperView *view)
void removeView (TrapperView *view)
void changedViewList ()
TrapperViewfirstView ()
bool isLastView ()
bool canCloseFrame (TrapperView *pFrame)
void setModified (bool _m=true)
bool isModified ()
void deleteContents ()
bool newDocument ()
void closeDocument ()
bool openDocument (const QString &dirname)
bool saveDocument (const QString &filename, const char *format=0)
void setPathName (const QString &name)
const QStringpathName () const
void setTitle (const QString &title)
const QStringtitle () const
void saveExport (ostream &stream)
bool import (QDomElement &elem)
void importChromat (const QString &dirname)
void importMates (const QString &filename)
void importTimeCourse (const QString &filename)
void importPhd (const QString &dirname)
std::vector< std::string > all_readnames ()
void openDbs ()
void closeDbs ()
TrDbfindTrDb (string)
void changedAlgoList ()
void addAlgorithm (Algo *)
void removeAlgorithm (Algo *)
QString getStatistics ()

Private Attributes

bool modified
QString m_title
QString m_filename
QList< TrapperView > * pViewList
QList< Algo > * pAlgoList
TrDbMap trDbMap
QString m_contigDir
DbEnv * dbenv

Friends

class TrapperView

Detailed Description

TrapperDoc provides a document object for a document-view model.

The TrapperDoc class provides a document object that can be used in conjunction with the classes TrapperApp and TrapperView to create a document-view model for MDI (Multiple Document Interface) Qt 2.1 applications based on QApplication and QMainWindow as main classes and QWorkspace as MDI manager widget. Thereby, the document object is created by the TrapperApp instance (and kept in a document list) and contains the document structure with the according methods for manipulating the document data by TrapperView objects. Also, TrapperDoc contains the methods for serialization of the document data from and to files.

Author:
Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team.
Version:
KDevelop version 1.1 code generation

Definition at line 56 of file trapperdoc.h.


Constructor & Destructor Documentation

TrapperDoc::TrapperDoc ( DbEnv *  dbenv  ) 

Constructor for the fileclass of the application

Definition at line 44 of file trapperdoc.cpp.

References pAlgoList, pViewList, and setModified().

00044                                     : dbenv( dbenv_ )
00045 {
00046 //     qDebug("in TrapperDoc::TrapperDoc()");
00047     pViewList = new QList<TrapperView>;
00048 //     pViewList->setAutoDelete(false);
00049     pViewList->setAutoDelete(true);
00050     pAlgoList = new QList<Algo>;
00051     pAlgoList->setAutoDelete(false);
00052     setModified(true );
00053 }

TrapperDoc::~TrapperDoc (  ) 

Destructor for the fileclass of the application

Definition at line 55 of file trapperdoc.cpp.

References closeDbs(), pAlgoList, and pViewList.

00056 {
00057 //   cerr<<"closing doc"<<endl;
00058   delete pViewList;
00059   delete pAlgoList;
00060   closeDbs();
00061 }


Member Function Documentation

void TrapperDoc::addView ( TrapperView view  ) 

adds a view to the document which represents the document contents. Usually this is your main view.

Definition at line 63 of file trapperdoc.cpp.

References changedViewList(), and pViewList.

Referenced by TrapperApp::createClient().

00064 {
00065     pViewList->append(view);
00066     changedViewList();
00067 }

void TrapperDoc::removeView ( TrapperView view  ) 

removes a view from the list of currently connected views

Definition at line 75 of file trapperdoc.cpp.

References changedViewList(), deleteContents(), pAlgoList, and pViewList.

Referenced by TrapperApp::eventFilter().

00076 {
00077     pViewList->remove
00078     (view);
00079     if(!pViewList->isEmpty() || !pAlgoList->isEmpty() )
00080         changedViewList();
00081     else
00082         deleteContents();
00083 }

void TrapperDoc::changedViewList (  ) 

gets called if a view is removed or added

Definition at line 95 of file trapperdoc.cpp.

References m_title, TrapperView::mode(), and pViewList.

Referenced by addView(), removeView(), TrapperApp::slotFileSaveAs(), and TrapperView::slotSwitchToMode().

00096 {
00097 
00098     TrapperView *w;
00099     if((int)pViewList->count() == 1)
00100     {
00101         w=pViewList->first();
00102         QString mode = w->mode();
00103         w->setCaption(QString(m_title+" mode=%2").arg(mode));
00104     }
00105     else
00106     {
00107         int i;
00108         for( i=1,w=pViewList->first(); w!=0; i++, w=pViewList->next())
00109         {
00110             QString mode = w->mode();
00111             w->setCaption(QString(m_title+" :%1 mode=%2").arg(i).arg(mode));
00112         }
00113     }
00114 }

TrapperView* TrapperDoc::firstView (  )  [inline]

returns the first view instance

Definition at line 75 of file trapperdoc.h.

References pViewList.

Referenced by TrapperApp::eventFilter(), and TrapperApp::openDocumentFile().

00076   {
00077     return pViewList->first();
00078   };

bool TrapperDoc::isLastView (  ) 

returns true, if the requested view is the last view of the document

Definition at line 120 of file trapperdoc.cpp.

References pViewList.

Referenced by canCloseFrame(), and closeDocument().

00121 {
00122     return ((int) pViewList->count() == 1);
00123 }

bool TrapperDoc::canCloseFrame ( TrapperView pFrame  ) 

This method gets called when the user is about to close a frame window. It checks, if more than one view is connected to the document (then the frame can be closed), if pFrame is the last view and the document is modified, the user gets asked if he wants to save the document.

Definition at line 233 of file trapperdoc.cpp.

References QMessageBox::critical(), QFileDialog::getSaveFileName(), QMessageBox::information(), QString::isEmpty(), isLastView(), isModified(), pathName(), saveDocument(), title(), and QObject::tr().

Referenced by TrapperApp::eventFilter().

00234 {
00235     if(!isLastView())
00236         return true;
00237 
00238     bool ret=false;
00239     if(isModified())
00240     {
00241         QString saveName;
00242         switch(QMessageBox::information(pFrame, title(), tr("The current file has been modified.\n"
00243                                         "Do you want to save it?"),QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel ))
00244         {
00245         case QMessageBox::Yes:
00246             if(title().contains(tr("Untitled")))
00247             {
00248                 saveName=QFileDialog::getSaveFileName(0, 0, pFrame);
00249                 if(saveName.isEmpty())
00250                     return false;
00251             }
00252             else
00253                 saveName=pathName();
00254 
00255             if(!saveDocument(saveName))
00256             {
00257                 switch(QMessageBox::critical(pFrame, tr("I/O Error !"), tr("Could not save the current document !\n"
00258                                              "Close anyway ?"),QMessageBox::Yes ,QMessageBox::No))
00259 
00260                 {
00261                 case QMessageBox::Yes:
00262                     ret=true;
00263                 case QMessageBox::No:
00264                     ret=false;
00265                 }
00266             }
00267             else
00268                 ret=true;
00269             break;
00270         case QMessageBox::No:
00271             ret=true;
00272             break;
00273         case QMessageBox::Cancel:
00274         default:
00275             ret=false;
00276             break;
00277         }
00278     }
00279     else
00280         ret=true;
00281 
00282     return ret;
00283 }

void TrapperDoc::setModified ( bool  _m = true  )  [inline]

sets the modified flag for the document after a modifying action on the view connected to the document.

Definition at line 87 of file trapperdoc.h.

References modified.

Referenced by TrapperDoc().

00088   {
00089     modified=_m;
00090   };

bool TrapperDoc::isModified (  )  [inline]

returns if the document is modified or not. Use this to determine if your document needs saving by the user on closing.

Definition at line 92 of file trapperdoc.h.

References modified.

Referenced by canCloseFrame().

00093   {
00094     return modified;
00095   };

void TrapperDoc::deleteContents (  ) 

deletes the document's contents

Definition at line 225 of file trapperdoc.cpp.

Referenced by removeAlgorithm(), and removeView().

00226 {
00227     /////////////////////////////////////////////////
00228     // TODO: Add implementation to delete the document contents
00229     /////////////////////////////////////////////////
00230 
00231 }

bool TrapperDoc::newDocument (  ) 

initializes the document generally

Definition at line 171 of file trapperdoc.cpp.

References modified.

Referenced by TrapperApp::openDocumentFile().

00172 {
00173     /////////////////////////////////////////////////
00174     // TODO: Add your document initialization code here
00175     /////////////////////////////////////////////////
00176     modified=false;
00177     return true;
00178 }

void TrapperDoc::closeDocument (  ) 

closes the acutal document

Definition at line 155 of file trapperdoc.cpp.

References isLastView(), and pViewList.

Referenced by TrapperApp::slotFileClose().

00156 {
00157   cerr<<"closeDocument()"<<endl;
00158   TrapperView *w;
00159   if(!isLastView()) {
00160     for(w=pViewList->first(); w!=0; w=pViewList->next()) {
00161       if(!w->close())
00162         break;
00163     }
00164   }
00165   if(isLastView()) {
00166     w = pViewList->first();
00167     w->close();
00168   }
00169 }

bool TrapperDoc::openDocument ( const QString dirname  ) 

loads the document by filename and format and emits the updateViews() signal

Definition at line 180 of file trapperdoc.cpp.

References QDir::exists(), m_contigDir, m_title, modified, and openDbs().

Referenced by MacsimParser::endElement(), TrapperApp::openDocumentFile(), TrapperApp::slotImport(), and TrapperParser::startElement().

00181 {
00182 //   cerr<<"openDocument() "<<endl;
00183   m_contigDir=dirname;
00184   QDir dir( m_contigDir );
00185   
00186   if ( !dir.exists() ) {
00187     QDir dir2;
00188     if ( !dir2.mkdir( m_contigDir, true ) ) {
00189       // oops, still doesn't exist
00190       cerr << "creating new dir failed, dir name=" << m_contigDir << endl;
00191       exit(1);
00192       
00193       
00194     }
00195   }
00196   /////////////////////////////////////////////////
00197   // TODO: Add your document opening code here
00198   /////////////////////////////////////////////////
00199   modified=false;
00200   m_title=dirname;
00201   
00202   openDbs();
00203   return true;
00204 }

bool TrapperDoc::saveDocument ( const QString filename,
const char *  format = 0 
)

saves the document under filename and format.

Definition at line 206 of file trapperdoc.cpp.

References m_contigDir, m_title, and modified.

Referenced by canCloseFrame(), TrapperApp::slotFileSave(), and TrapperApp::slotFileSaveAs().

00207 {
00208     /* we are using the berkeley db so changes are automatically changed in the files
00209        after the commit of the transaction.
00210        Here we might instead have some change of m_contigdir, to move the contig dir to
00211        another name to reflect the change of a "sandbox" contig to a regular contig. 
00212     */
00213     return false;
00214 
00215     /////////////////////////////////////////////////
00216     // TODO: Add your document saving code here
00217     /////////////////////////////////////////////////
00218 
00219     modified=false;
00220     m_contigDir=filename;
00221     m_title=filename;
00222     return true;
00223 }

void TrapperDoc::setPathName ( const QString name  ) 

sets the path to the file connected with the document

Definition at line 134 of file trapperdoc.cpp.

References m_contigDir, m_title, and QObject::name().

00135 {
00136     m_contigDir=name;
00137     m_title=QFileInfo(name).fileName();
00138 }

const QString & TrapperDoc::pathName (  )  const

returns the pathname of the current document file

Definition at line 140 of file trapperdoc.cpp.

References m_contigDir.

Referenced by canCloseFrame(), TrapperApp::open_docs_not_already_open(), TrapperApp::openDocumentFile(), saveExport(), and TrapperApp::slotFileSave().

00141 {
00142     return m_contigDir;
00143 }

void TrapperDoc::setTitle ( const QString title  ) 

sets the filename of the document

Definition at line 145 of file trapperdoc.cpp.

References m_title, and title().

00146 {
00147     m_title=title;
00148 }

const QString & TrapperDoc::title (  )  const

returns the title of the document

Definition at line 150 of file trapperdoc.cpp.

References m_title.

Referenced by canCloseFrame(), setTitle(), and TrapperApp::slotFileSave().

00151 {
00152     return m_title;
00153 }

void TrapperDoc::saveExport ( ostream &  stream  ) 

exports the document to a stream.

Definition at line 285 of file trapperdoc.cpp.

References Database::SecondaryIterator< T >::answer(), Database::PrimaryIterator< T >::answer(), Database::PrimaryIterator< T >::first(), GeneralData::getRecno(), Database::SecondaryIterator< T >::key(), GeneralMaker::listRegistered(), Database::PrimaryIterator< T >::next(), Database::SecondaryIterator< T >::nextdup(), pathName(), QString::section(), Database::SecondaryIterator< T >::set(), FeatureData::setReadRecno(), FeatureData::writeXml(), and ReadData::writeXml().

Referenced by TrapperApp::exportToFile().

00286 {
00287 
00288   //Ugly fix for strange behaviour...
00289   int offset(-1);
00290   if ( pathName()[pathName().length() -1] == '/' ) {
00291     --offset;
00292   }
00293   
00294   stream<<"<contig name=\""<<pathName().section('/', offset)<<"\">\n";
00295   
00296   Database::PrimaryIterator<ReadData> iter( this, "ReadData" );
00297 
00298   if ( iter.first() == 0 ) {
00299     do {
00300       //ReadData
00301       iter.answer()->writeXml(stream);
00302       //FeatureData
00303       
00304       list<string> alist = GeneralMaker::listRegistered();
00305       for ( list<string>::iterator  it = alist.begin(); it != alist.end(); ++it ) {
00306         if ( *it == "ReadData") {
00307           continue;
00308         }
00309         Database::SecondaryIterator<FeatureData> f_it( "readRecno", this, *it );
00310         
00311         f_it.key()->setReadRecno( iter.answer()->getRecno() );
00312         
00313         if ( f_it.set() == 0 ) {
00314           do {
00315             f_it.answer()->writeXml(stream);
00316             
00317           }while(f_it.nextdup() == 0);
00318         }
00319       }
00320       
00321       //End ReadData
00322       stream<<"</ReadData>\n";
00323         
00324     }while( iter.next() == 0 );
00325     
00326     
00327   }
00328   
00329   stream<<"</contig>\n";
00330   
00331 }

bool TrapperDoc::import ( QDomElement elem  ) 

imports data from file with filename. I believe QDom holds the entire dom tree in ram. This could be a limiting factor for large xml files. To fix that, this function might be enhanced to use "QXmlReader" to find a record and then letting that record be put in a dom tree.

Definition at line 333 of file trapperdoc.cpp.

References Database::Creator< T >::data(), QDomNode::isElement(), QDomNode::isNull(), QDomNode::nextSibling(), QDomNode::nodeName(), GeneralData::readDom(), and QDomNode::toElement().

Referenced by TrapperApp::slotImport().

00334 {
00335   QDomNode node2 = elem1.firstChild();
00336   
00337   while ( !node2.isNull() )
00338     {
00339       if ( node2.isElement() )
00340         {
00341           QString generalDataName = node2.nodeName();
00342           QDomElement elem2 = node2.toElement();
00343           
00344           Database::Creator<GeneralData> creator( this, generalDataName.ascii() );
00345           
00346           QDomNode node3 = elem2.firstChild();
00347           
00348           while ( !node3.isNull() )
00349             {
00350               if ( node3.isElement() && node3.nodeName() == "record" )
00351                 {
00352                   QDomElement elem3 = node3.toElement();
00353                   
00354                   creator.data()->readDom( elem3 );
00355                   creator.create( true );
00356                 }
00357               node3 = node3.nextSibling();
00358             }
00359         }
00360       node2 = node2.nextSibling();
00361     }
00362   return true;
00363 }

void TrapperDoc::importChromat ( const QString dirname  ) 

Imports chromatogram data

Definition at line 365 of file trapperdoc.cpp.

References all_readnames(), Database::SecondaryIterator< T >::answer(), ChromatData::cagt_vec, GeneralData::copy(), Database::Creator< T >::create(), Database::Creator< T >::data(), Database::SecondaryIterator< T >::key(), QXmlSimpleReader::parse(), ReadMetaData::readRecno, Database::SecondaryIterator< T >::set(), ChromatParser::set_result_array(), ReadMetaData::setName(), FeatureData::setReadRecno(), and ReadMetaData::strand().

00366 {
00367   //Get all readnames
00368   
00369   vector<string> names = all_readnames();
00370   
00371   //Parse files
00372 
00373   for( size_t i = 0; i < names.size(); i++ ) {
00374 
00375 
00376     vector<TrapperVector<Q_UINT32> > chromat_array;
00377     ChromatParser handler;
00378     handler.set_result_array( &chromat_array );
00379     QFile xmlFile( dirname + '/' + names[i] + ".xml" );
00380     QXmlInputSource source( &xmlFile );
00381     QXmlSimpleReader reader;
00382     reader.setContentHandler( &handler );
00383     if ( !reader.parse( source ) ) {
00384       cerr<<"Error, couldn't find chromatogram for "<<names[i]<<endl;
00385       continue;
00386     }
00387     //First, find recno of read
00388 //     Database::SecondaryIterator<ReadData> name_it( "name", this, "ReadData" );
00389 //     name_it.key()->setName( names[i] );
00390 //     if ( name_it.set() != 0 ) {
00391 //       cerr<<"Error, couldn't find "<<names[i]<<" in db"<<endl;
00392 //       continue;
00393 //     }
00394 
00395     Database::SecondaryIterator<ReadMetaData> name_it( "name", this, "ReadMetaData" );
00396     name_it.key()->setName( names[i] );
00397     if ( name_it.set() != 0 ) {
00398       cerr<<"Error, couldn't find "<<names[i]<<" in db"<<endl;
00399       continue;
00400     }
00401     
00402 
00403     //Second, find corresponding chromat feature data
00404     Database::SecondaryIterator<ChromatData>* chr_it = 
00405       new Database::SecondaryIterator<ChromatData>( "readRecno", this, "ChromatData" );
00406     
00407     chr_it->key()->setReadRecno( name_it.answer()->readRecno() );
00408     
00409     if ( chr_it->set() != 0 ) {
00410       cerr<<"Error, couldn't find recno "<<name_it.answer()->readRecno()<<" of read "<<names[i]<<endl;
00411       delete chr_it;
00412       continue;
00413     }
00414 
00415     //Create new data
00416     Database::Creator<ChromatData> creator( this, "ChromatData" );
00417     
00418     creator.data()->copy(chr_it->answer());
00419 
00420     
00421     creator.data()->cagt_vec.clear();
00422     if ( name_it.answer()->strand() == "C" ) {
00423 
00424       creator.data()->cagt_vec.push_back(TrapperVector<Q_UINT32>());
00425       creator.data()->cagt_vec.push_back(TrapperVector<Q_UINT32>());
00426       creator.data()->cagt_vec.push_back(TrapperVector<Q_UINT32>());
00427       creator.data()->cagt_vec.push_back(TrapperVector<Q_UINT32>());
00428 
00429       //Revcomp, must reverse the chromat and switch curves A->T, G->C
00430 
00431       creator.data()->cagt_vec[0].stlVector().clear();
00432       creator.data()->cagt_vec[0].stlVector().insert(creator.data()->cagt_vec[0].stlVector().begin(),
00433                                          chromat_array[2].stlVector().rbegin(), chromat_array[2].stlVector().rend());
00434       creator.data()->cagt_vec[1].stlVector().clear();
00435       creator.data()->cagt_vec[1].stlVector().insert(creator.data()->cagt_vec[1].stlVector().begin(),
00436                                          chromat_array[3].stlVector().rbegin(), chromat_array[3].stlVector().rend());
00437       creator.data()->cagt_vec[2].stlVector().clear();
00438       creator.data()->cagt_vec[2].stlVector().insert(creator.data()->cagt_vec[2].stlVector().begin(),
00439                                          chromat_array[0].stlVector().rbegin(), chromat_array[0].stlVector().rend());
00440       creator.data()->cagt_vec[3].stlVector().clear();
00441       creator.data()->cagt_vec[3].stlVector().insert(creator.data()->cagt_vec[3].stlVector().begin(),
00442                                          chromat_array[1].stlVector().rbegin(), chromat_array[1].stlVector().rend());
00443       
00444     }
00445     else {
00446     
00447       creator.data()->cagt_vec = chromat_array;
00448     }
00449     
00450     delete chr_it;
00451     
00452     creator.create(true);
00453   }
00454 
00455 
00456 }

void TrapperDoc::importMates ( const QString filename  ) 

Imports mate pair data

Definition at line 561 of file trapperdoc.cpp.

References Database::SecondaryIterator< T >::answer(), Database::SecondaryIterator< T >::key(), MateParser::parse_line(), Database::SecondaryIterator< T >::set(), MateParser::set_file(), and ReadMetaData::setName().

00562 {
00563   //Get all readnames
00564   
00565 //   vector<string> names = all_readnames();
00566   
00567   //Parse file
00568   MateParser parser;
00569   parser.set_file(filename);
00570   
00571   string read_name, mate_name;
00572   size_t mate_length;
00573 
00574   while( parser.parse_line( read_name, mate_name, mate_length ) ) {
00575 
00576 
00577     //For each read:
00578     
00579     //Add mate data
00580     //NB, assumes that the same read name is present only once in each contig, might need to fix this
00581 
00582 
00583     Database::Creator<ReadMetaData> creator( this, "ReadMetaData" );
00584     
00585     //First, find recno of read with name read_name
00586 //     Database::SecondaryIterator<ReadData>* name_it =
00587 //       new Database::SecondaryIterator<ReadData>( "name", this, "ReadData" );
00588 //     name_it->key()->setName( read_name );
00589 //     if ( name_it->set() != 0 ) {
00590 //       delete name_it;
00591 //       continue;
00592 //     }
00593     Database::SecondaryIterator<ReadMetaData>* name_it =
00594       new Database::SecondaryIterator<ReadMetaData>( "name", this, "ReadMetaData" );
00595     name_it->key()->setName( read_name );
00596     if ( name_it->set() != 0 ) {
00597       delete name_it;
00598       continue;
00599     }
00600     
00601     creator.data()->copy( name_it->answer() );
00602 
00603     creator.data()->setMate( mate_name );
00604     creator.data()->setMateLength( mate_length );
00605     
00606     
00607     delete name_it;
00608     
00609     creator.create(true);
00610     
00611     //Same for mate
00612       
00613     //First, find recno of read with name mate_name
00614 //     name_it = new Database::SecondaryIterator<ReadData>( "name", this, "ReadData" );
00615 //     name_it->key()->setName( mate_name );
00616 //     if ( name_it->set() != 0 ) {
00617 //       delete name_it;
00618 //       continue;
00619 //     }
00620     name_it = new Database::SecondaryIterator<ReadMetaData>( "name", this, "ReadMetaData" );
00621     name_it->key()->setName( read_name );
00622     if ( name_it->set() != 0 ) {
00623       delete name_it;
00624       continue;
00625     }
00626     
00627 
00628     creator.data()->copy( name_it->answer() );
00629     
00630     creator.data()->setMate( read_name );
00631     creator.data()->setMateLength( mate_length );
00632     
00633     
00634     delete name_it;
00635     
00636     creator.create(true);
00637     
00638   }
00639   
00640 }

void TrapperDoc::importTimeCourse ( const QString filename  ) 

Imports time course data

Definition at line 642 of file trapperdoc.cpp.

References Database::SecondaryIterator< T >::answer(), Database::SecondaryIterator< T >::key(), TcParser::parse_line(), Database::SecondaryIterator< T >::set(), TcParser::set_file(), and ReadMetaData::setName().

Referenced by TrapperApp::slotTcImport().

00643 {
00644   //Get all readnames
00645   
00646 //   vector<string> names = all_readnames();
00647   
00648   //Parse file
00649   TcParser parser;
00650   parser.set_file(filename);
00651   
00652   string read_name;
00653   vector<double> time_course;
00654 
00655   while( parser.parse_line( read_name, time_course ) ) {
00656 
00657 
00658     //For each read:
00659     
00660     //Add tc data
00661     //NB, assumes that the same read name is present only once in each contig, might need to fix this
00662 
00663 
00664     Database::Creator<ReadMetaData> creator( this, "ReadMetaData" );
00665     
00666     //First, find recno of read with name read_name
00667     Database::SecondaryIterator<ReadMetaData>* name_it =
00668       new Database::SecondaryIterator<ReadMetaData>( "name", this, "ReadMetaData" );
00669     name_it->key()->setName( read_name );
00670     if ( name_it->set() != 0 ) {
00671       time_course.clear();
00672       delete name_it;
00673       continue;
00674     }
00675     
00676     creator.data()->copy( name_it->answer() );
00677     
00678     creator.data()->tc_vec.stlVector() = time_course;
00679 //     cerr<<"\nName: "<<read_name<<endl;
00680 //     for( size_t i = 0; i < creator.data()->tc_vec.stlVector().size(); i++ ) {
00681 //       cerr<<creator.data()->tc_vec.stlVector()[i]<<" ";
00682 //     }
00683 //     cerr<<endl;
00684     delete name_it;
00685 //     for( size_t i = 0; i < creator.data()->tc_vec.stlVector().size(); i++ ) {
00686 //       cerr<<creator.data()->tc_vec.stlVector()[i]<<" ";
00687 //     }
00688 //     cerr<<endl;
00689     
00690     creator.create(true);
00691     time_course.clear();
00692   }
00693   
00694 }

void TrapperDoc::importPhd ( const QString dirname  ) 

Imports phd data

Definition at line 458 of file trapperdoc.cpp.

References all_readnames(), Database::SecondaryIterator< T >::answer(), ChromatData::cagt_vec, GeneralData::copy(), Database::Creator< T >::create(), Database::Creator< T >::data(), DnaStrData::dnaVector, FeatureData::endPos(), ChromatData::gap_vec, Database::SecondaryIterator< T >::key(), PhdParser::parse(), ChromatData::phd_vec, ReadMetaData::readRecno, Database::SecondaryIterator< T >::set(), ReadMetaData::setName(), FeatureData::setReadRecno(), TrapperVector< T >::size(), TrapperVector< T >::stlVector(), and ReadMetaData::strand().

00459 {
00460   //Get all readnames
00461   
00462   vector<string> names = all_readnames();
00463   
00464   //Parse files
00465 
00466   for( size_t i = 0; i < names.size(); i++ ) {
00467 
00468     TrapperVector<Q_UINT32> phd_array;
00469 
00470     PhdParser parser(dirname + '/' + names[i] + ".phd.1");
00471     phd_array = parser.parse();
00472     
00473     if ( phd_array.size() == 0 ) {
00474       cerr<<"Error, couldn't find phd file for "<<names[i]<<endl;
00475       continue;
00476     }
00477     //First, find recno of read
00478 //     Database::SecondaryIterator<ReadData> name_it( "name", this, "ReadData" );
00479 //     name_it.key()->setName( names[i] );
00480 //     if ( name_it.set() != 0 ) {
00481 //       cerr<<"Error, couldn't find "<<names[i]<<" in db"<<endl;
00482 //       continue;
00483 //     }
00484 
00485     Database::SecondaryIterator<ReadMetaData> name_it( "name", this, "ReadMetaData" );
00486     name_it.key()->setName( names[i] );
00487     if ( name_it.set() != 0 ) {
00488       cerr<<"Error, couldn't find "<<names[i]<<" in db"<<endl;
00489       continue;
00490     }
00491     //Second, find corresponding chromat feature data
00492     Database::SecondaryIterator<ChromatData>* chr_it = 
00493       new Database::SecondaryIterator<ChromatData>( "readRecno", this, "ChromatData" );
00494     
00495     chr_it->key()->setReadRecno( name_it.answer()->readRecno() );
00496     
00497     if ( chr_it->set() != 0 ) {
00498       cerr<<"Error, couldn't find recno "<<name_it.answer()->readRecno()<<" of read "<<names[i]<<endl;
00499       delete chr_it;
00500       continue;
00501     }
00502     if ( chr_it->answer()->cagt_vec[0].stlVector().size() == 0 ) {
00503       cerr<<"Chromat file for "<<names[i]<<" not imported, skipping phd file"<<endl;
00504       delete chr_it;
00505       continue;
00506     }
00507 
00508     //Create new data
00509     Database::Creator<ChromatData> creator( this, "ChromatData" );
00510 
00511     creator.data()->copy(chr_it->answer());
00512 
00513     if ( name_it.answer()->strand() == "C" ) {
00514       creator.data()->phd_vec.stlVector().clear();
00515       creator.data()->phd_vec.stlVector().insert(creator.data()->phd_vec.stlVector().begin(),
00516                                                  phd_array.stlVector().rbegin(), phd_array.stlVector().rend());
00517       for( size_t i = 0; i < creator.data()->phd_vec.stlVector().size(); i++ ) {
00518         creator.data()->phd_vec.stlVector()[i] = creator.data()->cagt_vec[0].stlVector().size() - 1 - creator.data()->phd_vec.stlVector()[i];
00519       }
00520     }
00521     else {
00522       
00523       creator.data()->phd_vec = phd_array;
00524     }
00525     
00526 
00527     delete chr_it;
00528 
00529     //TEMPORARY FIX OF THE GAP PROBLEM!!!
00530     Database::SecondaryIterator<DnaStrData>* dna_it = 
00531       new Database::SecondaryIterator<DnaStrData>( "readRecno", this, "DnaStrData" );
00532     dna_it->key()->setReadRecno( name_it.answer()->readRecno() );
00533     
00534     if ( dna_it->set() != 0 ) {
00535       cerr<<"Error, couldn't find recno "<<name_it.answer()->readRecno()<<" of read "<<names[i]<<endl;
00536       delete dna_it;
00537       continue;
00538     }
00539     creator.data()->gap_vec.stlVector().clear();
00540     size_t numgap(0);
00541     for( size_t i = 0; i < dna_it->answer()->dnaVector.size(); i++ ) {
00542       if (dna_it->answer()->dnaVector.stlVector()[i] == '*' ) {
00543         numgap++;
00544       }
00545       creator.data()->gap_vec.stlVector().push_back(numgap);
00546     }
00547 
00548     
00549     assert( creator.data()->gap_vec.stlVector().size() == static_cast<size_t>(creator.data()->endPos() + 1) );
00550     delete dna_it;
00551     
00552     //END FIX!!!
00553     
00554     creator.create(true);
00555     
00556   }
00557   
00558 
00559 }

vector< string > TrapperDoc::all_readnames (  ) 

Helper function for importing

Definition at line 697 of file trapperdoc.cpp.

References Database::SecondaryIterator< T >::answer(), Database::SecondaryIterator< T >::first(), ReadMetaData::name(), QObject::name(), and Database::SecondaryIterator< T >::next().

Referenced by importChromat(), and importPhd().

00698 {
00699   vector<string> names;
00700 
00701   Database::SecondaryIterator<ReadMetaData> name_it( "name", this, "ReadMetaData" );
00702   assert(name_it.first() == 0);
00703   string name;
00704   
00705   do {
00706     name = name_it.answer()->name().c_str();
00707     names.push_back(name);//Have to use c_str() due to some straaange bug...
00708   }while( name_it.next() == 0 );
00709   
00710   return names;
00711   
00712 }

void TrapperDoc::openDbs (  ) 

Definition at line 715 of file trapperdoc.cpp.

References QString::ascii(), dbenv, GeneralMaker::listRegistered(), m_contigDir, QDir::mkdir(), GeneralMaker::newData(), TrDb::open(), and trDbMap.

Referenced by openDocument().

00716 {
00717 
00718   list<string> alist = GeneralMaker::listRegistered();
00719 
00720   for (  list<string>::iterator  it = alist.begin(); it != alist.end(); ++it )
00721     {
00722       GeneralData * data = GeneralMaker::newData( *it );
00723       if ( data )
00724         {
00725           QString directoryName(  m_contigDir );
00726           directoryName += "/";
00727           directoryName += it->c_str() ;
00728           
00729           QDir dir;
00730           dir.mkdir( directoryName , true );
00731           
00732           TrDb * trdb = new TrDb( dbenv, directoryName.ascii() , data->getIndexMap() );
00733           trDbMap.insert( make_pair( it->c_str(), trdb ) );
00734           
00735 //           cerr << "trDbMap.insert( make_pair( it->c_str(), trdb ) ) ******* "
00736 //                << it->c_str() << " ***************** "
00737 //                << directoryName.ascii() << endl;
00738           
00739           delete data;
00740           trdb->open();
00741 
00742 //           cerr<<"trdb->primaryDb(): "<<trdb->primaryDb()<<endl;
00743         }
00744     }
00745 
00746 }

void TrapperDoc::closeDbs (  ) 

Definition at line 766 of file trapperdoc.cpp.

References trDbMap.

Referenced by ~TrapperDoc().

00767 {
00768 
00769   TrDbMap::iterator it;
00770   it = trDbMap.begin();
00771 
00772   while (it != trDbMap.end()) {
00773     Q_CHECK_PTR( it->second );
00774     it->second->close();
00775     delete it->second;
00776     ++it;
00777   }
00778   trDbMap.clear();
00779 }

TrDb * TrapperDoc::findTrDb ( string   ) 

Definition at line 748 of file trapperdoc.cpp.

References m_contigDir, and trDbMap.

Referenced by Database::Creator< T >::Creator(), Database::PrimaryIterator< T >::PrimaryIterator(), and Database::SecondaryIterator< T >::SecondaryIterator().

00749 {
00750     TrDb * trdb = NULL;
00751     TrDbMap::iterator it;
00752     it = trDbMap.find( generalDataName );
00753     if (it != trDbMap.end())
00754     {
00755         trdb = it->second;
00756     }
00757     else
00758     {
00759         cerr << "TrDb for generalData type=\""
00760         << generalDataName << "\" and contig=\""
00761         << m_contigDir << "\" not found" << endl;
00762     }
00763     return trdb;
00764 }

void TrapperDoc::changedAlgoList (  ) 

gets called if a algorithm is removed or added

Definition at line 116 of file trapperdoc.cpp.

Referenced by addAlgorithm(), and removeAlgorithm().

00117 {
00118 }

void TrapperDoc::addAlgorithm ( Algo  ) 

adds an algorithm to the document which represents the document contents.

Definition at line 69 of file trapperdoc.cpp.

References changedAlgoList(), and pAlgoList.

Referenced by TrapperView::runAlgo().

00070 {
00071     pAlgoList->append(algo);
00072     changedAlgoList();
00073 }

void TrapperDoc::removeAlgorithm ( Algo  ) 

removes an algorithm from the list of currently connected algorithm

Definition at line 85 of file trapperdoc.cpp.

References changedAlgoList(), deleteContents(), pAlgoList, and pViewList.

Referenced by TrapperView::runAlgo().

00086 {
00087     pAlgoList->remove
00088     (algo);
00089     if(!pViewList->isEmpty() || !pAlgoList->isEmpty() )
00090         changedAlgoList();
00091     else
00092         deleteContents();
00093 }

QString TrapperDoc::getStatistics (  ) 

shows berkeley db statistics about underlying databases

Definition at line 781 of file trapperdoc.cpp.

References trDbMap.

Referenced by TrapperApp::slotShowStatistics().

00782 {
00783     QString res;
00784     TrDbMap::iterator it;
00785     it = trDbMap.begin();
00786     while (it != trDbMap.end())
00787     {
00788         Q_CHECK_PTR( it->second );
00789         res += it->second->statistics();
00790         ++it;
00791     }
00792     return res;
00793 }

void TrapperDoc::updateAllViews ( TrapperView sender  )  [slot]

calls repaint() on all views connected to the document object and is called by the view by which the document has been changed. As this view normally repaints itself, it is excluded from the paintEvent.

Definition at line 125 of file trapperdoc.cpp.

References pViewList, QObject::sender(), and TrapperView::update().

00126 {
00127     TrapperView *w;
00128     for(w=pViewList->first(); w!=0; w=pViewList->next())
00129     {
00130         w->update(sender);
00131     }
00132 }


Friends And Related Function Documentation

friend class TrapperView [friend]

Definition at line 60 of file trapperdoc.h.


Member Data Documentation

bool TrapperDoc::modified [private]

the modified flag of the current document

Definition at line 156 of file trapperdoc.h.

Referenced by isModified(), newDocument(), openDocument(), saveDocument(), and setModified().

QString TrapperDoc::m_title [private]

Definition at line 157 of file trapperdoc.h.

Referenced by changedViewList(), openDocument(), saveDocument(), setPathName(), setTitle(), and title().

QString TrapperDoc::m_filename [private]

Definition at line 158 of file trapperdoc.h.

QList<TrapperView>* TrapperDoc::pViewList [private]

the list of the views currently connected to the document

Definition at line 160 of file trapperdoc.h.

Referenced by addView(), changedViewList(), closeDocument(), firstView(), isLastView(), removeAlgorithm(), removeView(), TrapperDoc(), updateAllViews(), and ~TrapperDoc().

QList<Algo>* TrapperDoc::pAlgoList [private]

Definition at line 161 of file trapperdoc.h.

Referenced by addAlgorithm(), removeAlgorithm(), removeView(), TrapperDoc(), and ~TrapperDoc().

TrDbMap TrapperDoc::trDbMap [private]

Definition at line 162 of file trapperdoc.h.

Referenced by closeDbs(), findTrDb(), getStatistics(), and openDbs().

QString TrapperDoc::m_contigDir [private]

Definition at line 163 of file trapperdoc.h.

Referenced by findTrDb(), openDbs(), openDocument(), pathName(), saveDocument(), and setPathName().

DbEnv* TrapperDoc::dbenv [private]

Definition at line 164 of file trapperdoc.h.

Referenced by openDbs().


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