001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021package org.biojava.nbio.survival.kaplanmeier.metadata;
022
023import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
024import org.biojava.nbio.survival.data.WorkSheet;
025
026/**
027 *
028 * @author Scooter Willis <willishf at gmail dot com>
029 */
030public class MeanQuantizer implements DiscreteQuantizerInterface {
031
032        /**
033         *
034         * @param worksheet
035         * @param column
036         */
037        @Override
038        public void process(WorkSheet worksheet, String column) {
039                DescriptiveStatistics ds = new DescriptiveStatistics();
040                for (String row : worksheet.getRows()) {
041                        try {
042                                Double d = Double.parseDouble(worksheet.getCell(row, column));
043                                ds.addValue(d);
044                        } catch (Exception e) {
045                        }
046                }
047                Double mean = ds.getMean();
048                for (String row : worksheet.getRows()) {
049                        try {
050                                Double d = Double.parseDouble(worksheet.getCell(row, column));
051                                if (d < mean) {
052                                        worksheet.addCell(row, column, "L");
053                                } else {
054                                        worksheet.addCell(row, column, "H");
055                                }
056                        } catch (Exception e) {
057                                try {
058                                        worksheet.addCell(row, column, "");
059                                } catch (Exception e1) {
060                                }
061                        }
062                }
063        }
064}