<commit_before>package org.mousephenotype.cda.solr.service;

import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.PivotField;
import org.apache.solr.common.util.NamedList;
import org.mousephenotype.cda.enumerations.SexType;
import org.mousephenotype.cda.enumerations.ZygosityType;
import org.mousephenotype.cda.solr.service.dto.ImpressBaseDTO;
import org.mousephenotype.cda.solr.service.dto.ObservationDTO;
import org.mousephenotype.cda.solr.service.dto.ObservationDTOBase;
import org.mousephenotype.cda.solr.service.dto.StatisticalResultDTO;
import org.mousephenotype.cda.solr.web.dto.HistopathPageTableRow;
import org.mousephenotype.cda.solr.web.dto.HistopathPageTableRow.ParameterValueBean;
import org.mousephenotype.cda.solr.web.dto.HistopathSumPageTableRow;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.configurationprocessor.json.JSONArray;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toSet;

@Service
public class HistopathService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private ObservationService observationService;
    private StatisticalResultService statisticalResultService;
    private String delimeter = " - ";
    public static String histoDelimeter = "||";


    @Inject
    public HistopathService(ObservationService observationService, StatisticalResultService statisticalResultService) {
        this.observationService = observationService;
        this.statisticalResultService = statisticalResultService;
    }

    public HistopathService() {

    }

    public List<HistopathPageTableRow> getTableData(Map<String, List<ObservationDTO>> uniqueSampleSequeneAndAnatomyName, Map<String, String> sampleIds) {
        List<HistopathPageTableRow> rows = new ArrayList<>();

        for (String key : uniqueSampleSequeneAndAnatomyName.keySet()) {

            // just for images here as no anatomy currently

            List<ObservationDTO> observations = uniqueSampleSequeneAndAnatomyName.get(key);
            Set<String> parameterNames = new TreeSet<>();

            HistopathPageTableRow row = new HistopathPageTableRow();// a row is a unique sampleId and anatomy and sequence id combination
            row.setAnatomyName(this.getAnatomyStringFromObservation(observations.get(0)));//anatomy should be the same from any in this dataset
            row.setSampleId(sampleIds.get(observations.get(0).getExternalSampleId()));
            row.setSex(SexType.valueOf(observations.get(0).getSex()));

            for (ObservationDTO obs : observations) {

                String zyg = ZygosityType.valueOf(obs.getZygosity()).getShortName();
                row.setZygosity(zyg);
                if (obs.getAgeInWeeks() != null) {
                    row.setAgeInWeeks(obs.getAgeInWeeks());
                }

                //System.out.println("sequenceId in observation="+obs.getSequenceId());
                row.setSequenceId(obs.getSequenceId());


                ImpressBaseDTO parameter = new ImpressBaseDTO(null, null, obs.getParameterStableId(),
                        obs.getParameterName());

                parameterNames.add(obs.getParameterName());

                if (obs.getObservationType().equalsIgnoreCase("categorical")) {
                    row.addCategoricalParam(parameter, obs.getCategory());
                    if (parameter.getName().contains("Significance")) {
                        row.addSignficance(parameter, obs.getCategory());
                    }
                    if (parameter.getName().contains("Severity")) {
                        row.addSeverity(parameter, obs.getCategory());
                    }
                }
                if (obs.getObservationType().equalsIgnoreCase("ontological")) {
                    if (obs.getSubTermName() != null) {
                        for (int i = 0; i < obs.getSubTermId().size(); i++) {
                            //System.out.println("subtermId=" + obs.getSubTermId() + "subtermname="
                            //+ obs.getSubTermName().get(i));
                            String termName = obs.getSubTermName().get(i);
                            String termId = obs.getSubTermId().get(i);
                            String termDesc = i < obs.getSubTermDescription().size() ? obs.getSubTermDescription().get(i) : "";
                            OntologyBean subOntologyBean = new OntologyBean(termId, termName, termDesc);

                            row.addOntologicalParam(parameter, subOntologyBean);
                            if (parameter.getName().contains("MPATH process term")) {
                                row.addMpathProcessParam(parameter, subOntologyBean);
                            }
                            if (parameter.getName().contains("MPATH diagnostic term")) {
                                row.addMpathDiagnosticParam(parameter, subOntologyBean);
                            }
                            if (parameter.getName().contains("PATO")) {<commit_msg>[FIX] Histopath broken links from gene pages #666<commit_after>package org.mousephenotype.cda.solr.service;

import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.PivotField;
import org.apache.solr.common.util.NamedList;
import org.mousephenotype.cda.enumerations.SexType;
import org.mousephenotype.cda.enumerations.ZygosityType;
import org.mousephenotype.cda.solr.service.dto.ImpressBaseDTO;
import org.mousephenotype.cda.solr.service.dto.ObservationDTO;
import org.mousephenotype.cda.solr.service.dto.ObservationDTOBase;
import org.mousephenotype.cda.solr.service.dto.StatisticalResultDTO;
import org.mousephenotype.cda.solr.web.dto.HistopathPageTableRow;
import org.mousephenotype.cda.solr.web.dto.HistopathPageTableRow.ParameterValueBean;
import org.mousephenotype.cda.solr.web.dto.HistopathSumPageTableRow;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.configurationprocessor.json.JSONArray;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toSet;

@Service
public class HistopathService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private ObservationService observationService;
    private StatisticalResultService statisticalResultService;
    private String delimeter = " - ";
    public static String histoDelimeter = "||";


    @Inject
    public HistopathService(ObservationService observationService, StatisticalResultService statisticalResultService) {
        this.observationService = observationService;
        this.statisticalResultService = statisticalResultService;
    }

    public HistopathService() {

    }

    public List<HistopathPageTableRow> getTableData(Map<String, List<ObservationDTO>> uniqueSampleSequeneAndAnatomyName, Map<String, String> sampleIds) {
        List<HistopathPageTableRow> rows = new ArrayList<>();

        for (String key : uniqueSampleSequeneAndAnatomyName.keySet()) {

            // just for images here as no anatomy currently

            List<ObservationDTO> observations = uniqueSampleSequeneAndAnatomyName.get(key);
            Set<String> parameterNames = new TreeSet<>();

            HistopathPageTableRow row = new HistopathPageTableRow();// a row is a unique sampleId and anatomy and sequence id combination
            row.setAnatomyName(this.getAnatomyStringFromObservation(observations.get(0)));//anatomy should be the same from any in this dataset
            row.setSampleId(sampleIds.get(observations.get(0).getExternalSampleId()));
            row.setSex(SexType.valueOf(observations.get(0).getSex()));

            for (ObservationDTO obs : observations) {

                String zyg = ZygosityType.valueOf(obs.getZygosity()).getShortName();
                row.setZygosity(zyg);
                if (obs.getAgeInWeeks() != null) {
                    row.setAgeInWeeks(obs.getAgeInWeeks());
                }

                //System.out.println("sequenceId in observation="+obs.getSequenceId());
                row.setSequenceId(obs.getSequenceId());


                ImpressBaseDTO parameter = new ImpressBaseDTO(null, null, obs.getParameterStableId(),
                        obs.getParameterName());

                parameterNames.add(obs.getParameterName());

                if (obs.getObservationType().equalsIgnoreCase("categorical")) {
                    row.addCategoricalParam(parameter, obs.getCategory());
                    if (parameter.getName().contains("Significance")) {
                        row.addSignficance(parameter, obs.getCategory());
                    }
                    if (parameter.getName().contains("Severity")) {
                        row.addSeverity(parameter, obs.getCategory());
                    }
                }
                if (obs.getObservationType().equalsIgnoreCase("ontological")) {
                    if (obs.getSubTermName() != null) {
                        for (int i = 0; i < obs.getSubTermId().size(); i++) {
                            //System.out.println("subtermId=" + obs.getSubTermId() + "subtermname="
                            //+ obs.getSubTermName().get(i));
                            String termName = obs.getSubTermName().get(i);
                            String termId = obs.getSubTermId().get(i);
                            String termDesc = obs.getSubTermDescription() != null && i < obs.getSubTermDescription().size() ? obs.getSubTermDescription().get(i) : "";
                            OntologyBean subOntologyBean = new OntologyBean(termId, termName, termDesc);

                            row.addOntologicalParam(parameter, subOntologyBean);
                            if (parameter.getName().contains("MPATH process term")) {
                                row.addMpathProcessParam(parameter, subOntologyBean);
                            }
                            if (parameter.getName().contains("MPATH diagnostic term")) {
                                row.addMpathDiagnosticParam(parameter, subOntologyBean);
                            }
                            if (parameter.getName().contains("PATO")) {
{'fraction_non_alphanumeric': 0.10336785147868272, 'fraction_numerical': 0.001399384270920795, 'mean_word_length': 2.6057854019508913, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 21, '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': '4559678', 'n_tokens_mistral': 2946, 'n_tokens_neox': 2810, 'n_words': 465}