map_tk.h

Go to the documentation of this file.
00001 #ifndef _MAP_TK_H_
00002 #define _MAP_TK_H_
00003 
00004 /* Copyright (c) Kyriacos Leptos and the President and Fellows of Harvard University
00005    Release Date: 2004-11-01
00006    Part of the MapQuant suite library "massspec.lib"
00007 */
00008 
00016 /* ************** DEFINE THE MAP (OR PATCH) DATA STRUCTURE ************* */
00017 
00018 #define MAP_VALUE_NOT_SEGMENT FLT_MIN
00019 
00020 extern float MAP2D_MAX_SIZE_IN_POINTS;
00021 
00022 enum {REMOVE_EDGES, INCLUDE_EDGES};
00023 
00024 enum { RT_DIMENSION, MZ_DIMENSION};
00025 
00026 enum { MAP2D_X_AXIS_UNITS_SCANS, MAP2D_X_AXIS_UNITS_TIME};
00027 
00028 enum { MAP2D_Y_AXIS_UNITS_PPM,
00029        MAP2D_Y_AXIS_UNITS_MZ_BINS,
00030        MAP2D_Y_AXIS_UNITS_MZ};
00031 
00032 enum { MAP2D_POINT_INDEX,
00033        MAP2D_POINT_SAMPLING,
00034        MAP2D_POINT_REAL };
00035 
00036 enum {  MAP2D_X_AXIS_MODE_MS_SCANS_ONLY,
00037         MAP2D_X_AXIS_MODE_ALL_SCANS };
00038 
00039 enum {  MAP2D_Y_AXIS_MODE_NO_RULERS_LINEAR_MODEL,
00040         MAP2D_Y_AXIS_MODE_NO_RULERS_QUADRATIC_MODEL,
00041         MAP2D_Y_AXIS_MODE_ONE_RULER_WITHOUT_PROJECTION,
00042         MAP2D_Y_AXIS_MODE_ONE_RULER_WITH_PROJECTION,
00043         MAP2D_Y_AXIS_MODE_MULTIPLE_RULERS_WITHOUT_PROJECTION,
00044         MAP2D_Y_AXIS_MODE_MULTIPLE_RULERS_WITH_PROJECTION };
00045 
00050 typedef struct Map2D Map2D;
00051 
00052 struct Map2D
00053 {
00054     unsigned isLoaded       : 1;
00055     unsigned isBinary       : 1;
00056     unsigned isMultiple     : 1;
00057     unsigned isTile         : 1;
00058     unsigned isSeam         : 1;
00059 
00060     unsigned isProcessed    : 1;
00061     unsigned isGrayscale    : 1;
00062     unsigned isDeconvolved  : 1;
00063 
00064     unsigned isMarked       : 1;
00065     unsigned isFitted       : 1;
00066 
00067     unsigned nScanMode      : 1;
00068 
00069     /* Segmentation info */
00070     unsigned isSegment      : 1;
00071     unsigned isOnEdge       : 1;
00072 
00073     unsigned isStatCalculated : 1;
00074 
00075 
00076 
00077     struct  MQSegmentAttributes*        pAttributes;
00078     int                     nAttributes;
00079     //int*                  pSegmentsOnEdge;
00080     //int                   nSegmentsOnEdge;
00081 
00082 
00083 
00084     struct Map2D*   parentMap;
00085     struct Map2D*   labeledMap;
00086 
00087     // ******** Universal Processing Identifiers ********
00088     // Filename and path location
00089     // MQExperiment pointer
00090     // MQExperiment's name
00091     // Rectangle  within experiment
00092     // Processing script
00093     // Processing script's name
00094 
00095     // Location
00096 
00100     char*       path;
00101 
00105     char*       name;
00106 
00107     // MQExperiment
00108     char*           experiment;
00109     MQExperiment*       expmnt;
00110 
00111     // Session
00112     char*           session;
00113 
00114     // Borders
00115     Insets4i        borders;
00116 
00117     // Processing Script
00118     char*           ps;
00119     ProcScript      procscript;
00120 
00121     // ********* END OF UNIVERSAL PROCESSING IDENTIFIERS ****
00122 
00123     // MSMS Info
00124     void* pMS2Data;
00125     int   nMS2Data;
00126 
00127     Insets4i*   pTiles;
00128     int             nTiles;
00129     MQTileID        bTile;
00130 
00131     MQDescriptiveStatistics stat;
00132 
00133     MQDimensions2i  dim;
00134 
00140     float*          rtsa;
00141     int*            scsa;
00142 
00148     float*          mssa;
00149 
00150     // Stat
00151     float           max;
00152 
00158     float**         abu;
00159 } ;
00160 
00161 
00162 
00163 
00164 // *************** MAP MEMORY ALLOCATION *******************
00165 
00172 Map2D*  Map2D_new();
00173 
00174 
00182 void Map2D_mallocAbundanceMatrix(Map2D* map);
00183 
00184 
00189 void Map2D_mallocScanArray(Map2D* map);
00190 
00191 
00201 void Map2D_mallocDim(Map2D* map, MQDimensions2i dim);
00202 
00203 
00214 void Map2D_malloc(Map2D* map, int no_of_scans, int no_of_bins);
00215 
00216 
00217 // ******************** INIT AND SETTING HEADER ************
00218 
00226 void    Map2D_initHeader(Map2D* map);
00227 void    Map2D_initAbundance(Map2D* map, float value);
00228 int     Map2D_addValue(Map2D* map, int scan, int bin, float value);
00229 void    Map2D_discardZeros(Map2D* map);
00230 void    initMap(Map2D* MP);
00231 
00242 void    Map2D_setScanMode(Map2D* map, int scan_mode);
00243 int     Map2D_setExperiment(Map2D* map, MQExperiment* expmnt);
00244 int     Map2D_setSize(Map2D* map, Insets4i* rect);
00245 void    Map2D_setHeader(Map2D* map, MQExperiment* expmnt, Insets4i rect);
00246 void    Map2D_setSamplingArrays(Map2D* map, Insets4i* rect);
00247 void    Map2D_setBorders(Map2D* map, int x_start, int x_stop, int y_start, int y_stop);
00248 void    Map2D_setProcScript(Map2D* map, ProcScript PS);
00249 int     Map2D_fprintHeader(FILE* fp, Map2D* map);
00250 void    Map2D_fprintAbundanceMatrix(FILE* fp, Map2D* map, int format);
00251 void    Map2D_fprintAbundanceSubMatrix(FILE* fp, Map2D* map, Insets4i* rect);
00252 void    Map2D_printHeader(Map2D *map, char* mapname);
00253 
00254 // *************** COPY OPERATIONS ******************
00255 
00256 void    Map2D_copyHeaderStatusBits(Map2D* dest, Map2D* source);
00257 void    Map2D_copyHeader(Map2D* source, Map2D* dest);
00258 void    Map2D_copy(Map2D* dest, Map2D* source);
00259 
00260 // *************** MAP OPERATIONS *******************
00261 
00262 void    Map2D_create(Map2D* map, MQExperiment* expmnt, Insets4i rect);
00263 void    Map2D_createUsingTemplate(Map2D* output_map, Map2D* template_map, float init_value);
00264 Map2D   Map2D_createBinaryMap(Map2D* map, float threshold);
00265 
00266 void    Map2D_destroy(Map2D *map);
00267 
00268 void    Map2D_invert_new(Map2D* out, Map2D* in);
00269 float   Map2D_calcArea(Map2D* map);
00270 
00271 float   Map2D_getResidualVolume(Map2D *original, Map2D *fitted);
00272 void    Map2D_subtractMaps(Map2D *one, Map2D *two, Map2D *diff);
00273 void    Map2D_mergeMaps(Map2D *one, Map2D *two, Map2D *result);
00274 
00275 void    Map2D_applyLinearInterpolation(Map2D* map);
00276 int     Map2D_applyErosion(Map2D *OMAP, Map2D *IMAP, char* szStructElemName);
00277 int     Map2D_applyDilation(Map2D *OMAP, Map2D *IMAP, char* szStructElemName);
00278 int     Map2D_applyClosing(Map2D *map, char* szStructElemName);
00279 int     Map2D_applyClosingUsingOriginal(Map2D *out, Map2D *in, char* szStructElemName);
00280 int     Map2D_applyOpening(Map2D *map, char* szStructElemName);
00281 
00282 
00283 // ************ BOUNDARY CHECKING FUNCTIONS
00284 
00285 int Map2D_isMOZValid(Map2D *map, float MOZ);
00286 int Map2D_isRTValid(Map2D *map, float RT);
00287 
00288 int Map2D_isMassBinValid(Map2D *map, int mass_bin);
00289 int Map2D_isScanValid(Map2D *map, int rt_bin); // rt_bin = scan
00290 
00291 int Map2D_isMassIndexValid(Map2D *map, int mass_index);
00292 int Map2D_isRTIndexValid(Map2D *map, int rt_index);
00293 
00294 // ************* MAP ROW && COLUMN OPERATIONS
00295 
00296 enum { MASS_TYPE_MOZ, MASS_TYPE_BIN, MASS_TYPE_MZJ };
00297 enum { RT_TYPE_MIN, RT_TYPE_SCAN, RT_TYPE_RTI };
00298 
00299 float* Map2D_getAbundanceArrayFromMassChrm(Map2D *map, int size, float index_value, int index_type);
00300 float* Map2D_getAbundanceArrayFromMassSpec(Map2D *map, int size, float index_value, int index_type);
00301 
00302 float* Map2D_getAbundancePointerFromScan (Map2D* map, int scan);
00303 float* Map2D_getAbundancePointerFromIndex(Map2D* map, int scanIndex);
00304 
00305 float* getAbundanceArrayOfMassSpecAtRTI(Map2D *map, int rt_index,
00306                                                    int start,
00307                                                    int stop);
00308 
00309 void   putMassChrmToMap2D_BIN(Map2D* MP, int bin,      float* array, int size);
00310 void   putMassChrmToMap2D_MZI(Map2D* MP, int mz_index, float* array, int size);
00311 
00312 void   Map2D_transferFloatArrayAsMassSpecIndex(Map2D *map, float* array, int size2, int rt_index);
00313 
00314 Map2D Map2D_extractSubMap(Map2D* map, Insets4i* rect);
00315 
00316 // ************* SAMPLING ARRAY OPERATIONS
00317 
00318 float* getRTSamplingArrayFromMap2D(Map2D* MP);
00319 float* getMSSamplingArrayFromMap2D(Map2D* MP);
00320 
00321 /* ******************************************************************** */
00322 
00323 void    Map2D_transformPeak2i           (Map2D* map, Peak2i* peak, int type);
00324 void    Map2D_transformPeak2iArray(Map2D* map, Peak2i* peaks, int npeaks, int type);
00325 void    Map2D_transformBorders(Map2D* map, Insets4i* target, int type);
00326 
00327 float   Map2D_getValueReal(Map2D *map, float rt, float mz);
00328 float   Map2D_getValue                  (Map2D *map , Peak2i peak);
00329 
00330 void    Peak2i_fprintlnWithMapValue    (FILE* fp, Peak2i peak, Map2D* map);
00331 void    Peak2i_fprintlnWithMapValues   (FILE* fp, Peak2i peak, Map2D* map);
00332 void    Peak2iArray_fprintWithMapValues(FILE* fp, Peak2i* peaks, int start, int stop, Map2D* map);
00333 void    Peak2iArray_fprintWithMapValue (FILE* fp, Peak2i* peaks, int start, int stop, struct Map2D* map);
00334 
00335 int     Map2D_getIndexFromScan   (Map2D *map, int scan);
00336 int     Map2D_getIndexFromMassBin(Map2D *map, int bin);
00337 
00338 int     Map2D_getIndexFromRT(Map2D* map, float RT);
00339 int     Map2D_getIndexFromMOZ(Map2D* map, float MOZ);
00340 
00341 int     Map2D_getScanFromIndex   (Map2D* map, int index);
00342 int     Map2D_getMassBinFromIndex(Map2D* map, int binIndex);
00343 
00344 float   Map2D_getFloatScanFromIndex(Map2D* map, int scanIndex);
00345 float   Map2D_getFloatMassBinFromIndex(Map2D* map, int binIndex);
00346 
00347 float   Map2D_getRTFromScan(Map2D* map, int scanNumber);
00348 float   Map2D_getMOZFromMassBin(Map2D* map, int binNumber);
00349 
00350 float   Map2D_getRTFromIndex(Map2D* map, int scanIndex);
00351 float   Map2D_getMOZFromIndex(Map2D* map, int binIndex);
00352 
00353 int     Map2D_findHighestIntensityScan(Map2D* map);
00354 void    Map2D_findMinMax(Map2D *map, float* max, float* min);
00355 void    Map2D_findMinMaxMultiple(MQExperiment* expmnt, char* szSession, char* type, float* max, float* min);
00356 int*    Map2D_getHistogramMultiple(MQExperiment* expmnt, char* szSession, char* type, float max, int* nbins);
00357 int*    Map2D_getHistogram(Map2D* map,  float max, int* nBinSize, int* nbins);
00358 int     Map2D_getNumberOfSegmentsMultiple(MQExperiment* expmnt, char* szSessionName);
00359 
00370 struct Segment* Map2D_getSegmentArray(Map2D* map, int  nMode, int* nSegment);
00371 
00372 void Map2D_saveRawInfo(char* szPath, char* szMap2D, Map2D* map);
00373 
00374 int     Map2D_isPeakInMap(Map2D* map, int scan, int bin);
00375 float*  Map2D_collapseToTIC(Map2D* map, int* nSize);
00376 int     Map2D_alignMaps(Map2D* map1, Map2D* map2 /* map to be superimposed */);
00377 
00378 void    Map2D_trimEdges(Map2D* map, float value);
00379 void    Map2D_eliminateNegativeValues(Map2D* map);
00380 
00381 void    Map2D_tile(Map2D* map, float mz_width);
00382 void    Map2D_tileUsingSize(Map2D* map, float tile_size);
00383 
00384 Peak3iif* Map2D_getPeak3iifArray(Map2D* MAP, int* npeaks, int type);
00385 
00386 int Map2D_deconvolveUsingWienerFilter(Map2D* pMap, float dSD, int nDimension,
00387                                       int signal_scan, int noisy_scan);
00388 
00389 int Map2D_deconvolve(Map2D* pMap, float dSD, int nDimension);
00390 int Map2D_getStatFromMassChrm(Map2D *map, int index_type, void* index_value, MQDescriptiveStatistics* stat);
00391 int Map2D_getStatFromMassSpec(Map2D *map, int index_type, void* index_value, MQDescriptiveStatistics* stat);
00392 
00393 int Map2D_loadMS2Data(Map2D* map, MQExperiment* ms2_expmnt);
00394 
00395 /* ***************************** Calculate Statistics for Map2D ***************************** */
00396 
00397 int   Map2D_calcDescriptiveStatistics(Map2D* map, int mode);
00398 float Map2D_getMeanAbundanceValue(Map2D* map, int mode);
00399 float Map2D_getMedianAbundanceValue(Map2D* map, int mode);
00400 float Map2D_getStandardDeviationOfAbundanceValues(Map2D* map, float mean, int mode);
00401 float Map2D_getMADM(Map2D* map, float median, int mode);
00402 float Map2D_getAADM(Map2D* map, float median, int mode);
00403 
00404 int   Map2D_calcDescriptiveStatisticsForInsets4i(Map2D* map, Insets4i* borders, int mode);
00405 float Map2D_getMeanAbundanceValueForInsets4i(Map2D* map, Insets4i* borders, int mode);
00406 float Map2D_getMedianAbundanceValueForInsets4i(Map2D* map, Insets4i* borders, int mode);
00407 float Map2D_getMADMForInsets4i(Map2D* map, Insets4i* borders, float median, int mode);
00408 float Map2D_getAADMForInsets4i(Map2D* map, Insets4i* borders, float median, int mode);
00409 
00410 /* ******************************************************************************************* */
00411 
00412 float Map2D_calcMeanRTSamplingTime(Map2D* map);
00413 float Map2D_calcMeanMZSamplingTime(Map2D* map);
00414 
00415 int Map2D_isMassSpecSignalConstant(Map2D *map, int index_type, void* index_value);
00416 
00417 BaselineMark            Map2D_getBaselineForPeak(Map2D* map, Peak2i* peak, int dimension);
00418 BaselineMark*           Map2D_getBaselineForPeak2iArray(Map2D* map, Peak2i* peakarray, int nsize, int dimension);
00419 void                    Map2D_getPeakEndsInRT(Map2D* map, int scan, int bin, int* left, int* right);
00420 
00421 void Map2DArray_merge(Map2D *array, int size, Map2D *result);
00422 
00423 #endif
00424 

Generated on Tue Feb 7 11:54:26 2006 for libmqobject by  doxygen 1.4.6