Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

trapperparser.cpp

Go to the documentation of this file.
00001 #include <qmessagebox.h>
00002 
00003 #include "trapperparser.h"
00004 #include "trapperdoc.h"
00005 #include "generaldata.h"
00006 #include "featuredata.h"
00007 #include "qdir.h"
00008 
00009 bool TrapperParser::startElement(const QString& namespaceURI,
00010                                  const QString& localName,
00011                                  const QString& qName,
00012                                  const QXmlAttributes& attributes)
00013 {
00014   //Three cases:
00015   if ( qName == "TRAPPER" ) {
00016     format_ok = true;
00017     return true;
00018   }
00019   else if ( qName == "contig" && format_ok ) {
00020 //     cerr<<"new contig"<<endl;
00021     /* Basically, all the functionality of TrapperApp::slotImport()
00022        has moved here. The other two cases below now contains the
00023        old functionality of TrapperDoc::import(). */
00024 
00025 
00026     //Use attributes to get name
00027     QString contigName = attributes.value("name");
00028 
00029 
00030     //Some bookkeeping to check if contig is already present
00031     QStringList contigNamesAlreadyPresent = contigNamesInProjectDir();
00032     if ( contigNamesAlreadyPresent.contains( contigName ) ) {
00033       QString message;
00034       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);
00035       QMessageBox::warning(0,"",message);
00036       return false;
00037     }
00038     //Create directory for contig
00039     QString fName = projDir + "/" + contigName;
00040                 
00041 
00042     //Create directories and databases for this contig
00043 
00044     current_doc = new TrapperDoc(env);
00045     current_doc->openDocument(fName);
00046 
00047     return true;
00048   }
00049   else if ( format_ok ) {
00050 //     cerr<<"parsing "<<qName<<endl;
00051     //Get data name from attributes and put into QString generalDataName
00052 
00053     //Create object factory for this data type
00054     
00055     Database::Creator<GeneralData> creator( current_doc, qName.ascii() );
00056 
00057     creator.data()->readAttributes( attributes );
00058     
00059     if ( qName != "ReadData" ) {//All other cases are FeatureData and need the corresponding read recno
00060       
00061       FeatureData* fdata = dynamic_cast<FeatureData*>(creator.data());
00062       assert( fdata );
00063       fdata->setReadRecno( current_read_recno );
00064       
00065     }
00066     db_recno_t new_recno = creator.create( false );//Should give dna, quality etc same recno as read (as previously)
00067     if ( qName == "ReadData" ) {
00068 
00069       current_read_recno = new_recno;
00070     }
00071     return true;
00072   }
00073   return false;
00074 }
00075 
00076 bool TrapperParser::endElement( const QString & namespaceURI, const QString & localName, 
00077                                 const QString & qName)
00078 {
00079   if ( qName == "contig" ) {
00080     //Delete old doc, if any
00081     delete current_doc;
00082 //     cerr<<"end contig"<<endl;
00083   }
00084   return true;
00085 }
00086 
00087 
00088 
00089 QStringList TrapperParser::contigNamesInProjectDir()
00090 {
00091     QString contigName;
00092     QDir d( projDir );
00093     Q_ASSERT( d.exists() );
00094     d.setFilter( QDir::Dirs | QDir::NoSymLinks );
00095     d.setSorting( QDir::Name );
00096     QStringList slist = d.entryList();
00097     return slist;
00098 }

Generated on Fri Mar 17 17:44:24 2006 for trapper by  doxygen 1.4.4