Example #1
0
  private void mergeProfiles(int p100Length, int gcpLength) {

    log.info("Merging profiles");

    ArrayList<AssayType> dummyAssay = new ArrayList<>();
    dummyAssay.add(AssayType.GCP);
    dummyAssay.add(AssayType.P100);

    List<Profile> profiles = profileRepository.findByAssayTypeInOrderByConcatDesc(dummyAssay);

    String prevConcat = null;
    String curConcat;
    List<Profile> bunchOfProfiles = null;

    for (Profile profile : profiles) {
      curConcat =
          profile.getReplicateAnnotation().getCellId()
              + profile.getReplicateAnnotation().getPertiname();
      if (prevConcat == null) {
        prevConcat = curConcat;
        bunchOfProfiles = new ArrayList<>();
      }

      if (!curConcat.equals(prevConcat)) {
        prevConcat = curConcat;

        MergedProfile mergedProfile =
            UtilsTransform.mergeProfiles(bunchOfProfiles, p100Length, gcpLength);
        mergedProfileRepository.save(mergedProfile);

        bunchOfProfiles = new ArrayList<>();

      } else {
        bunchOfProfiles.add(profile);
      }
    }
  }
Example #2
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++;
      }
    }
  }