<commit_before>/*
 * Copyright 2008-2010 Microarray Informatics Team, EMBL-European Bioinformatics Institute
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *
 * For further details of the Gene Expression Atlas project, including source code,
 * downloads and documentation, please see:
 *
 * http://gxa.github.com/gxa
 */

package ae3.model;

import uk.ac.ebi.gxa.requesthandlers.base.restutil.RestOut;
import uk.ac.ebi.gxa.requesthandlers.base.restutil.XmlRestResultRenderer;
import uk.ac.ebi.gxa.utils.MappingIterator;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * A class, representing on experiment sample for use in {@link ae3.model.ExperimentalData}
 * Is used only in NetCDFReader and should be replaced with newer model class.
 * 
 * @author pashky
 */
public class Sample {
    private int number;
    private long id;
    private Map<String,String> sampleCharacteristics;
    private Set<Assay> assays = new HashSet<Assay>();

    /**
     * Constructor
     * @param number sample number
     * @param sampleCharacteristics sample characteristics values map
     * @param id sample DW id
     */
    Sample(int number, Map<String, String> sampleCharacteristics, long id) {
        this.number = number;
        this.sampleCharacteristics = sampleCharacteristics;
        this.id = id;
    }

    /**
     * Gets sample characteristics values map
     * @return sample characteristics values map
     */
    @RestOut(name="sampleCharacteristics")
    public Map<String, String> getSampleCharacteristics() {
        return sampleCharacteristics;
    }

    /**
     * Gets iterable for assay numbers, linked to this sample
     * @return iterable for integer assay numbers
     */
    @RestOut(name="relatedAssays", xmlItemName ="assayId")
    public Iterator<Integer> getAssayNumbers() {
        return new MappingIterator<Assay,Integer>(getAssays().iterator()) {
            public Integer map(Assay assay) { return assay.getNumber(); }
        };
    }

    /**
     * Gets sample number
     * @return sample number
     */
    @RestOut(name="id", forRenderer = XmlRestResultRenderer.class)
    public int getNumber() {
        return number;
    }

    /**
     * Gets set of assays, linked to this sample
     * @return set of assays
     */
    public Set<Assay> getAssays() {
        return assays;
    }

    /**
     * Returns DW sample id
     * @return sample id
     */
    long getId() {
        return id;
    }

    /**
     * Links assay to this sample
     * @param assay assay to link
     */
    void addAssay(Assay assay) {
        assays.add(assay);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Sample sample = (Sample) o;

        if (number != sample.number) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return number;
    }

    @Override
    public String toString() {
        return "Sample{" +
                "number=" + number +
                ", id=" + id +
                ", sampleCharacteristics=" + sampleCharacteristics +
                ", assays=" + assays +
                '}';
    }
}
<commit_msg>Added getCompactData() and associated data structures to be returned via API to experiment.js and used in contructing large plots.<commit_after>/*
 * Copyright 2008-2010 Microarray Informatics Team, EMBL-European Bioinformatics Institute
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *
 * For further details of the Gene Expression Atlas project, including source code,
 * downloads and documentation, please see:
 *
 * http://gxa.github.com/gxa
 */

package ae3.model;

import uk.ac.ebi.gxa.requesthandlers.base.restutil.RestOut;
import uk.ac.ebi.gxa.requesthandlers.base.restutil.XmlRestResultRenderer;
import uk.ac.ebi.gxa.utils.MappingIterator;

import java.util.*;

/**
 * A class, representing on experiment sample for use in {@link ae3.model.ExperimentalData}
 * Is used only in NetCDFReader and should be replaced with newer model class.
 *
 * @author pashky
 */
public class Sample {
    private int number;
    private long id;
    private Map<String,String> sampleCharacteristics;
    private Set<Assay> assays = new HashSet<Assay>();

    // Data used passed as JSON to experiment.js via Atlas API and used to contruct large plots on the experiment page
    // Indexes of scvs in JSON, corresponding to this sample
    private Set<Integer> scvIndexes;
    // Index of this sample in JSON, referenced in AssayCompactData
    private Integer indexForPlot;

    /**
     * Constructor
     * @param number sample number
     * @param sampleCharacteristics sample characteristics values map
     * @param scvIndexes
     * @param id sample DW id
     */
    Sample(int number, Map<String, String> sampleCharacteristics, Set<Integer> scvIndexes, long id) {
        this.number = number;
        this.sampleCharacteristics = sampleCharacteristics;
        this.scvIndexes = scvIndexes; // Indexes of scvs in JSON, corresponding to this sample
        this.id = id;
    }

    /**
     * Gets sample characteristics values map
     * @return sample characteristics values map
     */
    @RestOut(name="sampleCharacteristics")
    public Map<String, String> getSampleCharacteristics() {
        return sampleCharacteristics;
    }

    /**
     * Gets iterable for assay numbers, linked to this sample
     * @return iterable for integer assay numbers
     */
    @RestOut(name="relatedAssays", xmlItemName ="assayId")
    public Iterator<Integer> getAssayNumbers() {
        return new MappingIterator<Assay,Integer>(getAssays().iterator()) {
            public Integer map(Assay assay) { return assay.getNumber(); }
        };
    }

    /**
     * Gets sample number
     * @return sample number
     */
    @RestOut(name="id", forRenderer = XmlRestResultRenderer.class)
    public int getNumber() {
        return number;
    }

    /**
     * Gets set of assays, linked to this sample
     * @return set of assays
     */
    public Set<Assay> getAssays() {
        return assays;
    }

    /**
     * Returns DW sample id
     * @return sample id
     */
    long getId() {
        return id;
    }

    /**
     * Links assay to this sample
     * @param assay assay to link
     */
    void addAssay(Assay assay) {
        assays.add(assay);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Sample sample = (Sample) o;

        if (number != sample.number) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return number;
    }

    @Override
    public String toString() {
        return "Sample{" +
                "number=" + number +
                ", id=" + id +
                ", sampleCharacteristics=" + sampleCharacteristics +
                ", assays=" + assays +
                '}';
    }

    /**
     * @return SampleCompactData representing compact Sample data needed to construct large plots on the experiment page.
     */
    public SampleCompactData getCompactData() {
        return new SampleCompactData(scvIndexes);
    }

    /**
     *
     * @return Index of this sample in JSON, referenced in AssayCompactData
     */
    public Integer getIndexForPlot() {
        return indexForPlot;
    }

    public void setIndexForPlot(Integer indexForPlot) {
        this.indexForPlot = indexForPlot;
    }
}

{'fraction_non_alphanumeric': 0.09335810496980956, 'fraction_numerical': 0.003251277287505806, 'mean_word_length': 2.611320754716981, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '815701', 'n_tokens_mistral': 2442, 'n_tokens_neox': 2285, 'n_words': 801}