<commit_before>package org.pdxfinder.services;

import org.pdxfinder.dao.OntologyTerm;
import org.pdxfinder.dao.Sample;
import org.pdxfinder.repositories.OntologyTermRepository;
import org.pdxfinder.repositories.SampleRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * Created by jmason on 25/05/2017.
 */

@Service
public class GraphService {


    private final static Logger log = LoggerFactory.getLogger(GraphService.class);

    private SampleRepository sampleRepository;
    private OntologyTermRepository ontologyTermRepository;

    public GraphService(SampleRepository sampleRepository, OntologyTermRepository ontologyTermRepository) {
        this.sampleRepository = sampleRepository;
        this.ontologyTermRepository = ontologyTermRepository;
    }


    public Set<String> getMappedDOTerms() {


        Collection<OntologyTerm> ontologyTerms = ontologyTermRepository.findAllWithMappings();
        Set<String> dataReport = new HashSet<>();

        for (OntologyTerm ontologyTerm : ontologyTerms) {
            if (ontologyTerm.getLabel() != null) {

                dataReport.add(ontologyTerm.getLabel() + " (" + ontologyTerm.getIndirectMappedSamplesNumber() + ")");
            }
        }
        // Arrange the result alphabetically
        Set<String> sortedData = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        sortedData.addAll(dataReport);

        return sortedData;

    }

    public Set<String> getMappedNCITTerms() {


        Collection<OntologyTerm> ontologyTerms = ontologyTermRepository.findAllWithMappings();
        Set<String> dataReport = new HashSet<>();

        for (OntologyTerm ontologyTerm : ontologyTerms) {
            if (ontologyTerm.getLabel() != null) {
                Set<String> synonyms = ontologyTerm.getSynonyms();
                /*
                if(synonyms.isEmpty()){

                    dataReport.add("["+ontologyTerm.getLabel() + "] (" + ontologyTerm.getIndirectMappedSamplesNumber() + ")");
                }
                else{

                    for(String synonym:synonyms){

                        dataReport.add(synonym + " ["+ontologyTerm.getLabel() + "] (" + ontologyTerm.getIndirectMappedSamplesNumber() + ")");
                    }
                }
                */

                dataReport.add(ontologyTerm.getLabel() + " (" + ontologyTerm.getIndirectMappedSamplesNumber() + ")");


            }
        }
        // Arrange the result alphabetically
        Set<String> sortedData = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        sortedData.addAll(dataReport);

        return sortedData;

    }

    public Map<String, Integer> getCancerSubtypeCounts() {

        log.info("Entering method getCancerSubtypeCounts");


        // Map name of subtype to integer representing the count of that subtype in the database
        Map<String, Integer> cancerSubtypes = new HashMap<>();

        Iterable<Sample> allSamples = sampleRepository.findAll();

        for (Sample sample : allSamples) {

            // Increment the count for a specific subtype
            Integer value = cancerSubtypes.get(sample.getType().getName());
            cancerSubtypes.put(sample.getType().getName(), (value == null) ? 1 : value + 1);

        }
<commit_msg>Fix mappedNumbers error<commit_after>package org.pdxfinder.services;

import org.pdxfinder.dao.OntologyTerm;
import org.pdxfinder.dao.Sample;
import org.pdxfinder.repositories.OntologyTermRepository;
import org.pdxfinder.repositories.SampleRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * Created by jmason on 25/05/2017.
 */

@Service
public class GraphService {


    private final static Logger log = LoggerFactory.getLogger(GraphService.class);

    private SampleRepository sampleRepository;
    private OntologyTermRepository ontologyTermRepository;

    public GraphService(SampleRepository sampleRepository, OntologyTermRepository ontologyTermRepository) {
        this.sampleRepository = sampleRepository;
        this.ontologyTermRepository = ontologyTermRepository;
    }


    public Set<String> getMappedDOTerms() {


        Collection<OntologyTerm> ontologyTerms = ontologyTermRepository.findAllWithMappings();
        Set<String> dataReport = new HashSet<>();

        for (OntologyTerm ontologyTerm : ontologyTerms) {
            if (ontologyTerm.getLabel() != null) {
                int mappedNumber = ontologyTerm.getDirectMappedSamplesNumber() + ontologyTerm.getIndirectMappedSamplesNumber();
                dataReport.add(ontologyTerm.getLabel() + " (" + mappedNumber + ")");
            }
        }
        // Arrange the result alphabetically
        Set<String> sortedData = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        sortedData.addAll(dataReport);

        return sortedData;

    }

    public Set<String> getMappedNCITTerms() {


        Collection<OntologyTerm> ontologyTerms = ontologyTermRepository.findAllWithMappings();
        Set<String> dataReport = new HashSet<>();

        for (OntologyTerm ontologyTerm : ontologyTerms) {
            if (ontologyTerm.getLabel() != null) {

                int mappedNumber = ontologyTerm.getDirectMappedSamplesNumber() + ontologyTerm.getIndirectMappedSamplesNumber();
                dataReport.add(ontologyTerm.getLabel() + " (" + mappedNumber + ")");


            }
        }
        // Arrange the result alphabetically
        Set<String> sortedData = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        sortedData.addAll(dataReport);

        return sortedData;

    }

    public Map<String, Integer> getCancerSubtypeCounts() {

        log.info("Entering method getCancerSubtypeCounts");


        // Map name of subtype to integer representing the count of that subtype in the database
        Map<String, Integer> cancerSubtypes = new HashMap<>();

        Iterable<Sample> allSamples = sampleRepository.findAll();

        for (Sample sample : allSamples) {

            // Increment the count for a specific subtype
            Integer value = cancerSubtypes.get(sample.getType().getName());
            cancerSubtypes.put(sample.getType().getName(), (value == null) ? 1 : value + 1);

        }

{'fraction_non_alphanumeric': 0.09949463044851548, 'fraction_numerical': 0.003790271636133923, 'mean_word_length': 2.931098696461825, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1373580', 'n_tokens_mistral': 1790, 'n_tokens_neox': 1659, 'n_words': 338}