Esempio n. 1
0
  private void buildProfiles() {
    log.info("Filling repository with profiles");

    List<String> referenceProfile;
    List<String> referenceGeneNames;

    Set<GctReplicate> gctReplicatePairs = repositoryService.getGctReplicatesCombinations();

    int dummyClusteringOrder = gctReplicatePairs.size();
    for (GctReplicate gctReplicate : gctReplicatePairs) {

      GctFile gctFile = gctReplicate.getGctFile();
      ReplicateAnnotation replicateAnnotation = gctReplicate.getReplicateAnnotation();

      List<PeakArea> peakAreas =
          peakAreaRepository.findByGctFileAndReplicateAnnotation(gctFile, replicateAnnotation);

      AssayType assayType = gctFile.getAssayType();

      referenceProfile = getReferenceProfile(assayType);
      referenceGeneNames = getReferenceGeneNames(assayType);

      Double[] profileVector = new Double[referenceProfile.size()];
      boolean[] imputeVector = new boolean[referenceProfile.size()];

      for (PeakArea peakArea : peakAreas) {
        int index = referenceProfile.indexOf(peakArea.getPeptideAnnotation().getPeptideId());
        profileVector[index] = peakArea.getValue();
      }

      UtilsStatistics.imputeProfileVector(profileVector, imputeVector);

      Profile profile =
          new Profile(
              replicateAnnotation,
              gctFile,
              ArrayUtils.toPrimitive(profileVector),
              imputeVector,
              referenceProfile,
              referenceGeneNames,
              dummyClusteringOrder--);

      profileRepository.save(profile);
    }
  }
Esempio n. 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++;
      }
    }
  }