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

DataTable.h

Go to the documentation of this file.
00001 
00002 //
00003 // This file is part of the MADELINE 2 program 
00004 // written by Edward H. Trager, Ritu Khanna and Adrian Marrs
00005 // Copyright (c) 2005 by the
00006 // Regents of the University of Michigan.
00007 // All Rights Reserved.
00008 // 
00009 // The latest version of this program is available from:
00010 // 
00011 //   http://eyegene.ophthy.med.umich.edu/madeline/
00012 //   
00013 // Released under the GNU General Public License.
00014 // A copy of the GPL is included in the distribution
00015 // package of this software, or see:
00016 // 
00017 //   http://www.gnu.org/copyleft/
00018 //   
00019 // ... for licensing details.
00020 // 
00022 
00023 //
00024 // DataTable.h
00025 //
00026 
00027 #ifndef DATATABLE_INCLUDED
00028 #define DATATABLE_INCLUDED
00029 
00030 #include "FileTypeClassifier.h"
00031 #include "DataColumn.h"
00032 
00033 #include "TableParser.h"
00034 
00035 #include "FieldLabels.h"
00036 
00037 #include "ColorSeriesStack.h"
00038 
00039 #include <set>
00040 #include <string>
00041 #include <vector>
00042 
00059 class DataTable {
00060         
00061 public:
00062         
00063         enum TableType { PEDIGREE, GENETICMAP, DECOMPOSED, RESULTS, ALLELEFREQUENCY, UNKNOWNTABLETYPE };
00064         static const int COLUMN_IS_MISSING = -1;
00065         
00066 private:
00067         
00068         // "less" function for _columnSet:
00069         struct ltstr
00070         {
00071                 bool operator()(DataColumn *c1, DataColumn *c2) const
00072                 {
00073                         //
00074                         // Comparisons done without regard to case:
00075                         //
00076                         return c1->getCaseInvariantName() < c2->getCaseInvariantName();
00077                 }
00078         };
00079         
00080         TableType _tabletype;
00081         
00082         //const char* _fileName;
00083         FileTypeClassifier _fileTypeClassifier;
00084         FileTypeClassifier::FILE_TYPE _fileType;
00085         const char* _fileTypeName;
00086         
00087         // Columns (Fields):
00088         // _columnSet provides lookup by name:
00089         std::set<DataColumn *,ltstr> _columnSet;
00090         
00091         // _columnVector provides lookup by index/ordinal:
00092         std::vector< std::set<DataColumn *,ltstr>::iterator > _columnVector;
00093         
00094         //
00095         // This is the vector of final types
00096         // which may differ from declared types:
00097         // 
00098         std::vector<DATATYPE> _finalTypes;
00099         
00100         //
00101         // Number of rows and columns:
00102         //
00103         unsigned long _rows; // number of rows
00104         unsigned _columns;   // number of columns
00105         
00106         //
00107         // Which columns are displayed?
00108         //
00109         std::vector<unsigned> _iconColumns;  // columns shown on icon;
00110         std::vector<unsigned> _labelColumns; // columns shown as labels or for output;
00111         
00112         ColorSeriesStack *_colorSeriesStack;
00113         ColorSeriesStack *_blackAndWhiteSeriesStack;
00114         
00115         //
00116         // Which optional core data columns exist?
00117         // 
00118         int _affectedColumnIndex;
00119         int _deceasedColumnIndex;
00120         int _dobColumnIndex;
00121         int _dzTwinColumnIndex;
00122         int _mzTwinColumnIndex;
00123         int _probandColumnIndex;
00124         int _sampledColumnIndex;
00125         
00126         //
00127         // Private methods:
00128         //
00129         void _setDeclaredTypesFromParser(const std::vector<char> *pDeclaredTypes);
00130         void _determineTableType(const std::vector<std::string> *pTitles);
00131         void _classifyRemainingColumns(const std::vector<std::string> *pElements, const std::vector<std::string> *pTitles);
00132         void _setColorSeriesStack(void);
00133         
00134         
00135 public:
00136         
00137         static FieldLabels labels;
00138         //
00139         // Constructors
00140         //
00141         DataTable(TableParser &parser);
00142         
00143         //
00144         // Destructor:
00145         //
00146         ~DataTable();
00147         
00148         //
00149         // addColumn: add a column to the table
00150         //
00151         void addColumn( DataColumn *column);
00152         
00153         //
00154         // getColumnOrdinal(): returns the columns physical position:
00155         //
00156         unsigned getColumnOrdinal ( const char *name ) const;
00157         
00158         //
00159         // getColumnName(): returns the name of the column at physical position 'ordinal':
00160         //
00161         std::string getColumnName ( unsigned ordinal ) const;
00162         
00163         //
00164         // getNumberOfColumns(): Returns the number of columns in the table.
00165         //
00166         unsigned getNumberOfColumns( void ) const;
00167         
00168         
00169         //
00170         // get a column by index/ordinal:
00171         //
00172         DataColumn* getColumn( unsigned ordinal ) const;
00173         
00174         //                                                                                      
00175         // get a column by name:
00176         //
00177         DataColumn* getColumn(const std::string &name ) const;
00178         
00179         void deleteFrontColumn();
00180         void display();
00181         
00182         // get the Table type
00183         const TableType getTableType( void ) const { return _tabletype; };
00184         std::string getTableTypeAsString(void) const;
00185         
00186         // get the number of rows
00187         const unsigned getNumberOfRows( void ) const { return _rows; };
00188         
00189         // check if a column exists:
00190         bool columnExists(const std::string &name) const;
00191         
00192         // toggle the columns for pedigree
00193         void toggleColumnsForPedigree(const std::vector<std::string> &columns);
00194         unsigned getNumberOfShowOnPedigreeColumns() const;
00195         Data* getDataAtIndex(const std::string name, unsigned long index) const;
00196         Data* getDataAtIndex(unsigned columnIndex, unsigned long index) const;
00197 
00198         // get the indices for optional core columns:
00199         // -1 if not present
00200         inline int getAffectedColumnIndex(void) const { return _affectedColumnIndex; }
00201         inline int getDeceasedColumnIndex(void) const { return _deceasedColumnIndex; }
00202         inline int getDOBColumnIndex(void) const { return _dobColumnIndex; }
00203         inline int getDZTwinColumnIndex(void)  const { return _dzTwinColumnIndex; }
00204         inline int getMZTwinColumnIndex(void) const { return _mzTwinColumnIndex; }
00205         inline int getProbandColumnIndex(void) const { return _probandColumnIndex; }
00206         inline int getSampledColumnIndex(void) const { return _sampledColumnIndex; }
00207         
00208         //
00209         // getIconColumnCount
00210         //
00211         unsigned getIconColumnCount(void) const;
00212         //
00213         // getIconColumnIndex
00214         //
00215         unsigned getIconColumnIndex(unsigned nth) const;
00216         //
00217         // getLabelColumnIndex
00218         //
00219         unsigned getLabelColumnIndex(unsigned nth) const;
00220         
00221         const std::vector<unsigned> * getIconColumnVector(void) const;
00222         const std::vector<unsigned> * getLabelColumnVector(void) const;
00223         
00224         ColorSeriesStack *getColorSeriesStack(void) const;
00225         ColorSeries *getColorSeriesFromStack(unsigned nth) const;
00226         ColorSeries *getBlackAndWhiteSeriesFromStack(unsigned nth) const;
00227         
00228 };
00229 
00230 #endif

Generated on Tue Feb 27 14:39:23 2007 for MINIMADELINE by  doxygen 1.4.4