<commit_before>package metadata;

import com.google.inject.internal.util.Lists;
import genome.Genome;

import java.awt.Color;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * Created by user on 16/06/16.
 * Used for analysing the meta data of the genomes
 * (e.g. all available metadata types, their possible values
 * and the colours each genome should get based on the metadata type)
 */
public class MetaDataController {

	/**
	 * HashMap with all the meta data.
	 */
    private Map<String, HashSet<String>> allValues = new HashMap<>();
    
    /**
     * HashMap with the colors.
     */
    private Map<String, Color> colorMap = new HashMap<>();
    
    /**
     * All the genomes.
     */
    private List<Genome> genomes;

    /**
     * The preferred colors for the metadata coloring.
     */
    private List<Color> preferredColors = new ArrayList<>();

    /**
     * constructor.
     * @param inputGenomes list of the genomes for which the MetaData is relevant
     */
    public MetaDataController(List<Genome> inputGenomes) {
        genomes = inputGenomes;
        initializeHashMap();
        fillHashMap();
        setColorBlindEnabled(false);
    }

    /**
     * Used to initialize all HashMaps (one is used for each metadata type).
     */
    private void initializeHashMap() {
        allValues.put("genomeId", new HashSet<>());
        allValues.put("age", new HashSet<>());
        allValues.put("sex", new HashSet<>());
        allValues.put("hivStatus", new HashSet<>());
        allValues.put("cohort", new HashSet<>());
        allValues.put("dateOfCollection", new HashSet<>());
        allValues.put("geoGraphicDistrict", new HashSet<>());
        allValues.put("specimenType", new HashSet<>());
        allValues.put("smearStatus", new HashSet<>());
        allValues.put("dnaIsolation", new HashSet<>());
        allValues.put("phenoDSTPattern", new HashSet<>());
        allValues.put("capreomycin", new HashSet<>());
        allValues.put("ethambutol", new HashSet<>());
        allValues.put("ethionamide", new HashSet<>());
        allValues.put("isoniazid", new HashSet<>());
        allValues.put("kanamyicin", new HashSet<>());
        allValues.put("pyrazinamide", new HashSet<>());
        allValues.put("ofloxacin", new HashSet<>());
        allValues.put("rifampin", new HashSet<>());
        allValues.put("streptomycin", new HashSet<>());
        allValues.put("digitalSpoligotype", new HashSet<>());
        allValues.put("lineage", new HashSet<>());
        allValues.put("genoDSTPattern", new HashSet<>());
        allValues.put("xdrType", new HashSet<>());
    }

    /**
     * Fill the HashMap.
     */
    private void fillHashMap() {
        for (Genome g : genomes) {
            if (g.getMetadata() != null) {
                allValues.get("age").add(g.getMetadata().getAge());
                allValues.get("sex").add(g.getMetadata().getSex());
                allValues.get("hivStatus").add(g.getMetadata().getHivStatus());
                allValues.get("cohort").add(g.getMetadata().getCohort());
                allValues.get("dateOfCollection").add(g.getMetadata().getDateOfCollection());
                allValues.get("geoGraphicDistrict").add(g.getMetadata().getGeoGraphicDistrict());
                allValues.get("specimenType").add(g.getMetadata().getSpecimenType());
                allValues.get("smearStatus").add(g.getMetadata().getSmearStatus());
                allValues.get("dnaIsolation").add(g.getMetadata().getDnaIsolation());
                allValues.get("phenoDSTPattern").add(g.getMetadata().getPhenoDSTPattern());
                allValues.get("capreomycin").add(g.getMetadata().getCapreomycin());
                allValues.get("ethambutol").add(g.getMetadata().getEthambutol());
                allValues.get("ethionamide").add(g.getMetadata().getEthionamide());
                allValues.get("isoniazid").add(g.getMetadata().getIsoniazid());
                allValues.get("kanamyicin").add(g.getMetadata().getKanamyicin());
                allValues.get("pyrazinamide").add(g.getMetadata().getPyrazinamide());
                allValues.get("ofloxacin").add(g.getMetadata().getOfloxacin());
                allValues.get("rifampin").add(g.getMetadata().getRifampin());
                allValues.get("streptomycin").add(g.getMetadata().getStreptomycin());
                allValues.get("digitalSpoligotype").add(g.getMetadata().getDigitalSpoligotype());
                allValues.get("lineage").add(g.getMetadata().getLineage());
                allValues.get("genoDSTPattern").add(g.getMetadata().getGenoDSTPattern());
                allValues.get("xdrType").add(g.getMetadata().getXdrType());
            }
        }
    }

    /**
     * Fills the colormap, which maps metadata type + value to a color.
     */
    private void fillColormap() {
        System.out.println(colorMap);
        for (String metaDataType : returnMetaDataTypes()) {
            int i = 0;
            for (String value : returnPossibleValues(metaDataType)) {
                colorMap.put(metaDataType + ":" + value, getPreferredColors(i));
                i++;
            }
        }
        colorMap.put("lineage:LIN 1", Color.decode("0xed00c3"));
        colorMap.put("lineage:LIN 2", Color.decode("0x0000ff"));
        colorMap.put("lineage:LIN 3", Color.decode("0x500079"));
        colorMap.put("lineage:LIN 4", Color.decode("0xff0000"));
        colorMap.put("lineage:LIN 5", Color.decode("0x4e2c00"));
        colorMap.put("lineage:LIN 6", Color.decode("0x69ca00"));
        colorMap.put("lineage:LIN 7", Color.decode("0xff7e00"));
        colorMap.put("lineage:LIN animal", Color.decode("0x00ff9c"));
        colorMap.put("lineage:LIN B", Color.decode("0x00ff9c"));
        colorMap.put("lineage:LIN CANETTII", Color.decode("0x00ffff"));
        System.out.println(colorMap);

    }

    /**
     * Returns all types of metadata that are available.
     * @return All available metadata fields
     */
    public List<String> returnMetaDataTypes() {
        return Lists.newArrayList(allValues.keySet());
    }

    /**
     * Returns all possible values of a certain metadata type.
     * @param metaData a string representing the metadata in which one is interested.
     * @return all possible values of this field
     */
    public List<String> returnPossibleValues(String metaData) {
        return Lists.newArrayList(allValues.get(metaData));
    }<commit_msg>Remove unused println<commit_after>package metadata;

import com.google.inject.internal.util.Lists;
import genome.Genome;

import java.awt.Color;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * Created by user on 16/06/16.
 * Used for analysing the meta data of the genomes
 * (e.g. all available metadata types, their possible values
 * and the colours each genome should get based on the metadata type)
 */
public class MetaDataController {

	/**
	 * HashMap with all the meta data.
	 */
    private Map<String, HashSet<String>> allValues = new HashMap<>();
    
    /**
     * HashMap with the colors.
     */
    private Map<String, Color> colorMap = new HashMap<>();
    
    /**
     * All the genomes.
     */
    private List<Genome> genomes;

    /**
     * The preferred colors for the metadata coloring.
     */
    private List<Color> preferredColors = new ArrayList<>();

    /**
     * constructor.
     * @param inputGenomes list of the genomes for which the MetaData is relevant
     */
    public MetaDataController(List<Genome> inputGenomes) {
        genomes = inputGenomes;
        initializeHashMap();
        fillHashMap();
        setColorBlindEnabled(false);
    }

    /**
     * Used to initialize all HashMaps (one is used for each metadata type).
     */
    private void initializeHashMap() {
        allValues.put("genomeId", new HashSet<>());
        allValues.put("age", new HashSet<>());
        allValues.put("sex", new HashSet<>());
        allValues.put("hivStatus", new HashSet<>());
        allValues.put("cohort", new HashSet<>());
        allValues.put("dateOfCollection", new HashSet<>());
        allValues.put("geoGraphicDistrict", new HashSet<>());
        allValues.put("specimenType", new HashSet<>());
        allValues.put("smearStatus", new HashSet<>());
        allValues.put("dnaIsolation", new HashSet<>());
        allValues.put("phenoDSTPattern", new HashSet<>());
        allValues.put("capreomycin", new HashSet<>());
        allValues.put("ethambutol", new HashSet<>());
        allValues.put("ethionamide", new HashSet<>());
        allValues.put("isoniazid", new HashSet<>());
        allValues.put("kanamyicin", new HashSet<>());
        allValues.put("pyrazinamide", new HashSet<>());
        allValues.put("ofloxacin", new HashSet<>());
        allValues.put("rifampin", new HashSet<>());
        allValues.put("streptomycin", new HashSet<>());
        allValues.put("digitalSpoligotype", new HashSet<>());
        allValues.put("lineage", new HashSet<>());
        allValues.put("genoDSTPattern", new HashSet<>());
        allValues.put("xdrType", new HashSet<>());
    }

    /**
     * Fill the HashMap.
     */
    private void fillHashMap() {
        for (Genome g : genomes) {
            if (g.getMetadata() != null) {
                allValues.get("age").add(g.getMetadata().getAge());
                allValues.get("sex").add(g.getMetadata().getSex());
                allValues.get("hivStatus").add(g.getMetadata().getHivStatus());
                allValues.get("cohort").add(g.getMetadata().getCohort());
                allValues.get("dateOfCollection").add(g.getMetadata().getDateOfCollection());
                allValues.get("geoGraphicDistrict").add(g.getMetadata().getGeoGraphicDistrict());
                allValues.get("specimenType").add(g.getMetadata().getSpecimenType());
                allValues.get("smearStatus").add(g.getMetadata().getSmearStatus());
                allValues.get("dnaIsolation").add(g.getMetadata().getDnaIsolation());
                allValues.get("phenoDSTPattern").add(g.getMetadata().getPhenoDSTPattern());
                allValues.get("capreomycin").add(g.getMetadata().getCapreomycin());
                allValues.get("ethambutol").add(g.getMetadata().getEthambutol());
                allValues.get("ethionamide").add(g.getMetadata().getEthionamide());
                allValues.get("isoniazid").add(g.getMetadata().getIsoniazid());
                allValues.get("kanamyicin").add(g.getMetadata().getKanamyicin());
                allValues.get("pyrazinamide").add(g.getMetadata().getPyrazinamide());
                allValues.get("ofloxacin").add(g.getMetadata().getOfloxacin());
                allValues.get("rifampin").add(g.getMetadata().getRifampin());
                allValues.get("streptomycin").add(g.getMetadata().getStreptomycin());
                allValues.get("digitalSpoligotype").add(g.getMetadata().getDigitalSpoligotype());
                allValues.get("lineage").add(g.getMetadata().getLineage());
                allValues.get("genoDSTPattern").add(g.getMetadata().getGenoDSTPattern());
                allValues.get("xdrType").add(g.getMetadata().getXdrType());
            }
        }
    }

    /**
     * Fills the colormap, which maps metadata type + value to a color.
     */
    private void fillColormap() {
        for (String metaDataType : returnMetaDataTypes()) {
            int i = 0;
            for (String value : returnPossibleValues(metaDataType)) {
                colorMap.put(metaDataType + ":" + value, getPreferredColors(i));
                i++;
            }
        }
        colorMap.put("lineage:LIN 1", Color.decode("0xed00c3"));
        colorMap.put("lineage:LIN 2", Color.decode("0x0000ff"));
        colorMap.put("lineage:LIN 3", Color.decode("0x500079"));
        colorMap.put("lineage:LIN 4", Color.decode("0xff0000"));
        colorMap.put("lineage:LIN 5", Color.decode("0x4e2c00"));
        colorMap.put("lineage:LIN 6", Color.decode("0x69ca00"));
        colorMap.put("lineage:LIN 7", Color.decode("0xff7e00"));
        colorMap.put("lineage:LIN animal", Color.decode("0x00ff9c"));
        colorMap.put("lineage:LIN B", Color.decode("0x00ff9c"));
        colorMap.put("lineage:LIN CANETTII", Color.decode("0x00ffff"));

    }

    /**
     * Returns all types of metadata that are available.
     * @return All available metadata fields
     */
    public List<String> returnMetaDataTypes() {
        return Lists.newArrayList(allValues.keySet());
    }

    /**
     * Returns all possible values of a certain metadata type.
     * @param metaData a string representing the metadata in which one is interested.
     * @return all possible values of this field
     */
    public List<String> returnPossibleValues(String metaData) {
        return Lists.newArrayList(allValues.get(metaData));
    }
{'fraction_non_alphanumeric': 0.15482584011048028, 'fraction_numerical': 0.009206690194874943, 'mean_word_length': 2.8530889742831804, 'pattern_counts': {'":': 2, '<': 73, '<?xml version=': 0, '>': 73, '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': '5040284', 'n_tokens_mistral': 3964, 'n_tokens_neox': 3754, 'n_words': 708}