Beispiel #1
0
  private void computeCorrelations() {
    log.info("Filling repository with most correlated profiles");

    List<String> referenceProfile;

    for (AssayType assayType : AssayType.values()) {

      referenceProfile = getReferenceProfile(assayType);
      List<Profile> profiles = profileRepository.findByAssayType(assayType);

      String[] profileNames = new String[profiles.size()];
      double[][] distanceMatrix = new double[profiles.size()][profiles.size()];

      int i = 0;

      for (Profile profileA : profiles) {

        profileNames[i] = profileA.getId().toString();

        Double maxPearson = Double.MIN_VALUE;
        Profile maxProfile = profileA;

        int j = 0;

        for (Profile profileB : profiles) {
          if (profileA.equals(profileB)) {
            distanceMatrix[i][j] = 0;
            j++;
            continue;
          }

          double[] vectorA = profileA.getVector();
          double[] vectorB = profileB.getVector();

          PearsonsCorrelation pearson = new PearsonsCorrelation();
          Double pearsonCorrelation = pearson.correlation(vectorA, vectorB);

          if (pearsonCorrelation >= maxPearson) {
            maxPearson = pearsonCorrelation;
            maxProfile = profileB;
          }

          double[] profileAasDouble = UtilsTransform.intArrayToDouble(profileA.getColors());
          double[] profileBasDouble = UtilsTransform.intArrayToDouble(profileB.getColors());

          Double pearsonOfColors = pearson.correlation(profileAasDouble, profileBasDouble);
          distanceMatrix[i][j] = pearsonOfColors;
          j++;
        }

        profileA.setCorrelatedVector(maxProfile.getListWrapper());

        SortedSet<StringDouble> positivePeptides =
            UtilsStatistics.influentialPeptides(
                profileA.getVector(), maxProfile.getVector(), referenceProfile, true);

        profileA.setPositivePeptides(UtilsTransform.SortedSetToHTML(positivePeptides, false));

        DecimalFormat df = new DecimalFormat("0.0000");
        String peptideCorrelation = " <br/><br/><b style=\"color: #23527c;\">%s</b>";

        profileA.setPositiveCorrelation(
            maxProfile.toString() + String.format(peptideCorrelation, df.format(maxPearson)));

        profileRepository.save(profileA);
        i++;
      }
    }
  }
 @Override
 public String toString() {
   return "P: " + profile.toString() + " L: " + level.toString();
 }