private double calcMean(
     HashMap<Integer, String> singleGeneCaseValueMap,
     String groupType,
     String profileStableId) { // group type: altered or unaltered
   switch (groupType) {
     case "altered":
       int _index_altered = 0;
       double[] alteredArray = new double[alteredSampleIds.size()];
       for (Integer alteredSampleId : alteredSampleIds) {
         if (singleGeneCaseValueMap.containsKey(alteredSampleId)) {
           if (profileStableId.indexOf("rna_seq") != -1) {
             try {
               alteredArray[_index_altered] =
                   Math.log(Double.parseDouble(singleGeneCaseValueMap.get(alteredSampleId)))
                       / Math.log(2);
             } catch (NumberFormatException e) {
               e.getStackTrace();
             }
           } else {
             try {
               alteredArray[_index_altered] =
                   Double.parseDouble(singleGeneCaseValueMap.get(alteredSampleId));
             } catch (NumberFormatException e) {
               e.getStackTrace();
             }
           }
           _index_altered += 1;
         }
       }
       return StatUtils.mean(alteredArray);
     case "unaltered":
       int _index_unaltered = 0;
       double[] unalteredArray = new double[unalteredSampleIds.size()];
       for (Integer unalteredSampleId : unalteredSampleIds) {
         if (singleGeneCaseValueMap.containsKey(unalteredSampleId)) {
           if (profileStableId.indexOf("rna_seq") != -1) {
             try {
               unalteredArray[_index_unaltered] =
                   Math.log(Double.parseDouble(singleGeneCaseValueMap.get(unalteredSampleId)))
                       / Math.log(2);
             } catch (NumberFormatException e) {
               e.getStackTrace();
             }
           } else {
             try {
               unalteredArray[_index_unaltered] =
                   Double.parseDouble(singleGeneCaseValueMap.get(unalteredSampleId));
             } catch (NumberFormatException e) {
               e.getStackTrace();
             }
           }
           _index_unaltered += 1;
         }
       }
       return StatUtils.mean(unalteredArray);
     default:
       return Double.NaN; // error
   }
 }
  private double runTTest(HashMap<Integer, String> singleGeneCaseValueMap, String profileStableId)
      throws IllegalArgumentException {

    double[] unalteredArray = new double[unalteredSampleIds.size()];
    double[] alteredArray = new double[alteredSampleIds.size()];
    int _index_unaltered = 0, _index_altered = 0;

    for (Integer alteredSampleId : alteredSampleIds) {
      if (singleGeneCaseValueMap.containsKey(alteredSampleId)) {
        if (profileStableId.indexOf("rna_seq") != -1) {
          try {
            alteredArray[_index_altered] =
                Math.log(Double.parseDouble(singleGeneCaseValueMap.get(alteredSampleId)))
                    / Math.log(2);
          } catch (NumberFormatException e) {
            e.getStackTrace();
          }
        } else {
          try {
            alteredArray[_index_altered] =
                Double.parseDouble(singleGeneCaseValueMap.get(alteredSampleId));
          } catch (NumberFormatException e) {
            e.getStackTrace();
          }
        }
        _index_altered += 1;
      }
    }
    for (Integer unalteredSampleId : unalteredSampleIds) {
      if (singleGeneCaseValueMap.containsKey(unalteredSampleId)) {
        if (profileStableId.indexOf("rna_seq") != -1) {
          try {
            unalteredArray[_index_unaltered] =
                Math.log(Double.parseDouble(singleGeneCaseValueMap.get(unalteredSampleId)))
                    / Math.log(2);
          } catch (NumberFormatException e) {
            e.getStackTrace();
          }
        } else {
          try {
            unalteredArray[_index_unaltered] =
                Double.parseDouble(singleGeneCaseValueMap.get(unalteredSampleId));
          } catch (NumberFormatException e) {
            e.getStackTrace();
          }
        }
        _index_unaltered += 1;
      }
    }

    if (alteredArray.length < 2 || unalteredArray.length < 2) return Double.NaN;
    else {
      double pvalue = TestUtils.tTest(alteredArray, unalteredArray);
      return pvalue;
    }
  }
 private double calcSTDev(
     HashMap<Integer, String> singleGeneCaseValueMap, String groupType, String profileStableId) {
   switch (groupType) {
     case "altered":
       DescriptiveStatistics stats_altered = new DescriptiveStatistics();
       for (Integer alteredSampleId : alteredSampleIds) {
         if (singleGeneCaseValueMap.containsKey(alteredSampleId)) {
           if (profileStableId.indexOf("rna_seq") != -1) {
             try {
               stats_altered.addValue(
                   Math.log(Double.parseDouble(singleGeneCaseValueMap.get(alteredSampleId)))
                       / Math.log(2));
             } catch (NumberFormatException e) {
               e.getStackTrace();
             }
           } else {
             try {
               stats_altered.addValue(
                   Double.parseDouble(singleGeneCaseValueMap.get(alteredSampleId)));
             } catch (NumberFormatException e) {
               e.getStackTrace();
             }
           }
         }
       }
       return stats_altered.getStandardDeviation();
     case "unaltered":
       DescriptiveStatistics stats_unaltered = new DescriptiveStatistics();
       for (Integer unalteredSampleId : unalteredSampleIds) {
         if (singleGeneCaseValueMap.containsKey(unalteredSampleId)) {
           if (profileStableId.indexOf("rna_seq") != -1) {
             try {
               stats_unaltered.addValue(
                   Math.log(Double.parseDouble(singleGeneCaseValueMap.get(unalteredSampleId)))
                       / Math.log(2));
             } catch (NumberFormatException e) {
               e.getStackTrace();
             }
           } else {
             try {
               stats_unaltered.addValue(
                   Double.parseDouble(singleGeneCaseValueMap.get(unalteredSampleId)));
             } catch (NumberFormatException e) {
               e.getStackTrace();
             }
           }
         }
       }
       return stats_unaltered.getStandardDeviation();
     default:
       return Double.NaN; // error
   }
 }
  private double runFisherExactTest(
      HashMap<Integer, String> singleGeneCaseValueMap, String profileType) {

    int a = 0, // non altered
        b = 0, // x non altered, y altered
        c = 0, // x altered, y non altered
        d = 0; // both alered

    for (Integer alteredSampleId : alteredSampleIds) {
      if (singleGeneCaseValueMap.containsKey(alteredSampleId)) {
        if (profileType.equals(GeneticAlterationType.COPY_NUMBER_ALTERATION.toString())) {
          try {
            Double value = Double.parseDouble(singleGeneCaseValueMap.get(alteredSampleId));
            if (copyNumType.equals("del")) {
              if (value == -2.0) {
                d += 1;
              } else {
                c += 1;
              }
            } else if (copyNumType.equals("amp")) {
              if (value == 2.0) {
                d += 1;
              } else {
                c += 1;
              }
            }
          } catch (NumberFormatException e) {
            e.getStackTrace();
          }
        } else if (profileType.equals(GeneticAlterationType.MUTATION_EXTENDED.toString())) {
          String value = singleGeneCaseValueMap.get(alteredSampleId);
          if (value.equals("Non")) {
            c += 1;
          } else {
            d += 1;
          }
        }
      }
    }

    for (Integer unalteredSampleId : unalteredSampleIds) {
      if (singleGeneCaseValueMap.containsKey(unalteredSampleId)) {
        if (profileType.equals(GeneticAlterationType.COPY_NUMBER_ALTERATION.toString())) {
          try {
            Double value = Double.parseDouble(singleGeneCaseValueMap.get(unalteredSampleId));
            if (copyNumType.equals("del")) {
              if (value == -2.0) {
                b += 1;
              } else {
                a += 1;
              }
            } else if (copyNumType.equals("amp")) {
              if (value == 2.0) {
                b += 1;
              } else {
                a += 1;
              }
            }
          } catch (NumberFormatException e) {
            e.getStackTrace();
          }
        } else if (profileType.equals(GeneticAlterationType.MUTATION_EXTENDED.toString())) {
          String value = singleGeneCaseValueMap.get(unalteredSampleId);
          if (value.equals("Non")) {
            a += 1;
          } else {
            b += 1;
          }
        }
      }
    }

    FisherExact fisher = new FisherExact(a + b + c + d);
    return fisher.getCumlativeP(a, b, c, d);
  }
  private double calcPct(
      HashMap<Integer, String> singleGeneCaseValueMap,
      String profileType,
      String groupType) { // group type: altered or unaltered

    double _result_pct = 0, _count = 0; // altered samples count

    if (profileType.equals(GeneticAlterationType.COPY_NUMBER_ALTERATION.toString())
        && copyNumType.equals("del")) {
      switch (groupType) {
        case "altered":
          for (Integer alteredSampleId : alteredSampleIds) {
            if (singleGeneCaseValueMap.containsKey(alteredSampleId)) {
              try {
                if (Double.parseDouble(singleGeneCaseValueMap.get(alteredSampleId)) == -2.0) {
                  _count += 1;
                }
              } catch (NumberFormatException e) {
                e.getStackTrace();
              }
            }
          }
          _result_pct = _count / alteredSampleIds.size();
          break;
        case "unaltered":
          for (Integer unalteredSampleId : unalteredSampleIds) {
            if (singleGeneCaseValueMap.containsKey(unalteredSampleId)) {
              try {
                if (Double.parseDouble(singleGeneCaseValueMap.get(unalteredSampleId)) == -2.0) {
                  _count += 1;
                }
              } catch (NumberFormatException e) {
                e.getStackTrace();
              }
            }
          }
          _result_pct = _count / unalteredSampleIds.size();
          break;
      }
    } else if (profileType.equals(GeneticAlterationType.COPY_NUMBER_ALTERATION.toString())
        && copyNumType.equals("amp")) {
      switch (groupType) {
        case "altered":
          for (Integer alteredSampleId : alteredSampleIds) {
            if (singleGeneCaseValueMap.containsKey(alteredSampleId)) {
              try {
                if (Double.parseDouble(singleGeneCaseValueMap.get(alteredSampleId)) == 2.0) {
                  _count += 1;
                }
              } catch (NumberFormatException e) {
                e.getStackTrace();
              }
            }
          }
          _result_pct = _count / alteredSampleIds.size();
          break;
        case "unaltered":
          for (Integer unalteredSampleId : unalteredSampleIds) {
            if (singleGeneCaseValueMap.containsKey(unalteredSampleId)) {
              try {
                if (Double.parseDouble(singleGeneCaseValueMap.get(unalteredSampleId)) == 2.0) {
                  _count += 1;
                }
              } catch (NumberFormatException e) {
                e.getStackTrace();
              }
            }
          }
          _result_pct = _count / unalteredSampleIds.size();
          break;
      }
    } else if (profileType.equals(GeneticAlterationType.MUTATION_EXTENDED.toString())) {
      switch (groupType) {
        case "altered":
          for (Integer alteredSampleId : alteredSampleIds) {
            if (singleGeneCaseValueMap.containsKey(alteredSampleId)) {
              if (!singleGeneCaseValueMap.get(alteredSampleId).equals("Non")) {
                _count += 1;
              }
            }
          }
          _result_pct = _count / alteredSampleIds.size();
          break;
        case "unaltered":
          for (Integer unalteredSampleId : unalteredSampleIds) {
            if (singleGeneCaseValueMap.containsKey(unalteredSampleId)) {
              if (!singleGeneCaseValueMap.get(unalteredSampleId).equals("Non")) {
                _count += 1;
              }
            }
          }
          _result_pct = _count / unalteredSampleIds.size();
          break;
      }
    }

    return _result_pct;
  }