<commit_before>package org.pharmgkb.pharmcat.reporter.io;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import com.google.common.base.Preconditions;
import com.google.gson.Gson;
import org.pharmgkb.pharmcat.haplotype.NamedAlleleMatcher;
import org.pharmgkb.pharmcat.haplotype.ResultSerializer;
import org.pharmgkb.pharmcat.haplotype.model.GeneCall;
import org.pharmgkb.pharmcat.haplotype.model.Result;
import org.pharmgkb.pharmcat.reporter.model.DosingGuideline;
import org.pharmgkb.pharmcat.reporter.model.GuidelinePackage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This class takes JSON files and deserializes them into Objects through GSON.
 */
public class JsonFileLoader {
  private static final Logger sf_logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
  private static final String CPIC_SOURCE = "CPIC";

  private final Gson gson = new Gson();

  /**
   * Load all the gene calls coming from the {@link NamedAlleleMatcher} utility
   */
  public List<GeneCall> loadHaplotypeGeneCalls(@Nonnull Path haplotypeCalledFile) throws IOException{
    Preconditions.checkNotNull(haplotypeCalledFile);
    Preconditions.checkArgument(Files.exists(haplotypeCalledFile));
    Preconditions.checkArgument(Files.isRegularFile(haplotypeCalledFile));

    sf_logger.debug("Loading haplotyper file {}", haplotypeCalledFile);
    Result namResult = new ResultSerializer().fromJson(haplotypeCalledFile);
    return namResult.getGeneCalls();
  }

  /**
   * Load the <strong>CPIC</strong> guideline annotations into {@link DosingGuideline} objects from the list of guideline {@link File}
   * list
   */
  public List<GuidelinePackage> loadGuidelines(List<Path> guidelineFileList) throws IOException {
    List<GuidelinePackage> guidelines = new ArrayList<>();

    for (Path guidelineFile : guidelineFileList) {
      try (BufferedReader br = Files.newBufferedReader(guidelineFile)) {
        GuidelinePackage guidelinePackage = gson.fromJson(br, GuidelinePackage.class);
        if (guidelinePackage.getGuideline().getSource().equals(CPIC_SOURCE)) {
          guidelines.add(guidelinePackage);
        }
      }
    }

    return guidelines;
  }
}<commit_msg>Update reporter guideline filtering<commit_after>package org.pharmgkb.pharmcat.reporter.io;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import com.google.common.base.Preconditions;
import com.google.gson.Gson;
import org.pharmgkb.pharmcat.haplotype.NamedAlleleMatcher;
import org.pharmgkb.pharmcat.haplotype.ResultSerializer;
import org.pharmgkb.pharmcat.haplotype.model.GeneCall;
import org.pharmgkb.pharmcat.haplotype.model.Result;
import org.pharmgkb.pharmcat.reporter.model.DosingGuideline;
import org.pharmgkb.pharmcat.reporter.model.GuidelinePackage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This class takes JSON files and deserializes them into Objects through GSON.
 */
public class JsonFileLoader {
  private static final Logger sf_logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
  private static final String CPIC_SOURCE = "CPIC";

  private final Gson gson = new Gson();

  /**
   * Load all the gene calls coming from the {@link NamedAlleleMatcher} utility
   */
  public List<GeneCall> loadHaplotypeGeneCalls(@Nonnull Path haplotypeCalledFile) throws IOException{
    Preconditions.checkNotNull(haplotypeCalledFile);
    Preconditions.checkArgument(Files.exists(haplotypeCalledFile));
    Preconditions.checkArgument(Files.isRegularFile(haplotypeCalledFile));

    sf_logger.debug("Loading haplotyper file {}", haplotypeCalledFile);
    Result namResult = new ResultSerializer().fromJson(haplotypeCalledFile);
    return namResult.getGeneCalls();
  }

  /**
   * Load the <strong>CPIC</strong> guideline annotations into {@link DosingGuideline} objects from the list of guideline {@link File}
   * list
   */
  public List<GuidelinePackage> loadGuidelines(List<Path> guidelineFileList) throws IOException {
    List<GuidelinePackage> guidelines = new ArrayList<>();

    for (Path guidelineFile : guidelineFileList) {
      try (BufferedReader br = Files.newBufferedReader(guidelineFile)) {
        GuidelinePackage guidelinePackage = gson.fromJson(br, GuidelinePackage.class);
        DosingGuideline guideline = guidelinePackage.getGuideline();

        if (guideline.getSource().equals(CPIC_SOURCE) && guideline.isRecommendation()) {
          guidelines.add(guidelinePackage);
        }
      }
    }

    return guidelines;
  }
}
{'fraction_non_alphanumeric': 0.09939024390243903, 'fraction_numerical': 0.0008130081300813008, 'mean_word_length': 5.060344827586207, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '3140722', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1440, 'n_words': 303}