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         int _superscriptColumnIndex;
00126         int _consultandColumnIndex;
00127         int _carrierColumnIndex;
00128         int _relationshipEndedColumnIndex;
00129         int _infertilityColumnIndex;
00130         int _sterilityColumnIndex;
00131         
00132         //
00133         // Private methods:
00134         //
00135         void _setDeclaredTypesFromParser(const std::vector<char> *pDeclaredTypes);
00136         void _determineTableType(const std::vector<std::string> *pTitles);
00137         void _classifyRemainingColumns(const std::vector<std::string> *pElements, const std::vector<std::string> *pTitles);
00138         void _setColorSeriesStack(void);
00139         
00140         
00141 public:
00142         
00143         static FieldLabels labels;
00144         //
00145         // Constructors
00146         //
00147         DataTable(TableParser &parser);
00148         
00149         //
00150         // Destructor:
00151         //
00152         ~DataTable();
00153         
00154         //
00155         // addColumn: add a column to the table
00156         //
00157         void addColumn( DataColumn *column);
00158         
00159         //
00160         // getColumnOrdinal(): returns the columns physical position:
00161         //
00162         unsigned getColumnOrdinal ( const char *name ) const;
00163         
00164         //
00165         // getColumnName(): returns the name of the column at physical position 'ordinal':
00166         //
00167         std::string getColumnName ( unsigned ordinal ) const;
00168         
00169         //
00170         // getNumberOfColumns(): Returns the number of columns in the table.
00171         //
00172         unsigned getNumberOfColumns( void ) const;
00173         
00174         
00175         //
00176         // get a column by index/ordinal:
00177         //
00178         DataColumn* getColumn( unsigned ordinal ) const;
00179         
00180         //                                                                                      
00181         // get a column by name:
00182         //
00183         DataColumn* getColumn(const std::string &name ) const;
00184         
00185         void deleteFrontColumn();
00186         void display();
00187         void printInputTableAsTabDelimited(std::string filename) const;
00188         void printPedigreeTableAsTabDelimited(std::string filename) const;
00189         
00190         // get the Table type
00191         const TableType getTableType( void ) const { return _tabletype; };
00192         std::string getTableTypeAsString(void) const;
00193         
00194         // get the number of rows
00195         const unsigned getNumberOfRows( void ) const { return _rows; };
00196         
00197         // check if a column exists:
00198         bool columnExists(const std::string &name) const;
00199         
00200         // toggle the columns for pedigree
00201         void toggleColumnsForPedigree(const std::vector<std::string> &columns);
00202         unsigned getNumberOfShowOnPedigreeColumns() const;
00203         Data* getDataAtIndex(const std::string name, unsigned long index) const;
00204         Data* getDataAtIndex(unsigned columnIndex, unsigned long index) const;
00205 
00206         // get the indices for optional core columns:
00207         // -1 if not present
00208         inline int getAffectedColumnIndex(void) const { return _affectedColumnIndex; }
00209         inline int getDeceasedColumnIndex(void) const { return _deceasedColumnIndex; }
00210         inline int getDOBColumnIndex(void) const { return _dobColumnIndex; }
00211         inline int getDZTwinColumnIndex(void)  const { return _dzTwinColumnIndex; }
00212         inline int getMZTwinColumnIndex(void) const { return _mzTwinColumnIndex; }
00213         inline int getProbandColumnIndex(void) const { return _probandColumnIndex; }
00214         inline int getSampledColumnIndex(void) const { return _sampledColumnIndex; }
00215         inline int getSuperscriptColumnIndex(void) const { return _superscriptColumnIndex; }
00216         inline int getConsultandColumnIndex(void)  const { return _consultandColumnIndex; }
00217         inline int getCarrierColumnIndex(void)     const { return _carrierColumnIndex; }
00218         inline int getRelationshipEndedColumnIndex(void) const { return _relationshipEndedColumnIndex; }
00219         inline int getInfertilityColumnIndex(void) const { return _infertilityColumnIndex; }
00220         inline int getSterilityColumnIndex(void) const { return _sterilityColumnIndex; }
00221         
00222         //
00223         // getIconColumnCount
00224         //
00225         unsigned getIconColumnCount(void) const;
00226         //
00227         // getIconColumnIndex
00228         //
00229         unsigned getIconColumnIndex(unsigned nth) const;
00230         //
00231         // getLabelColumnIndex
00232         //
00233         unsigned getLabelColumnIndex(unsigned nth) const;
00234         
00235         const std::vector<unsigned> * getIconColumnVector(void) const;
00236         const std::vector<unsigned> * getLabelColumnVector(void) const;
00237         
00238         ColorSeriesStack *getColorSeriesStack(void) const;
00239         ColorSeries *getColorSeriesFromStack(unsigned nth) const;
00240         ColorSeries *getBlackAndWhiteSeriesFromStack(unsigned nth) const;
00241         
00242 };
00243 
00244 #endif

Generated on Fri Nov 18 16:24:39 2011 for MADELINE by  doxygen 1.4.4