<commit_before>/*
 * SeparatePlugin.java
 *
 * Created on July 31, 2010
 *
 */
package net.maizegenetics.baseplugins;

import net.maizegenetics.pal.alignment.*;
import net.maizegenetics.plugindef.AbstractPlugin;
import net.maizegenetics.plugindef.DataSet;
import net.maizegenetics.plugindef.Datum;
import net.maizegenetics.plugindef.PluginEvent;

import java.awt.Frame;

import javax.swing.*;

import java.net.URL;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

/**
 *
 * @author terry
 */
public class SeparatePlugin extends AbstractPlugin {

    private static final Logger myLogger = Logger.getLogger(SeparatePlugin.class);

    /** Creates a new instance of SeparatePlugin */
    public SeparatePlugin(Frame parentFrame, boolean isInteractive) {
        super(parentFrame, isInteractive);
    }

    public DataSet performFunction(DataSet input) {

        try {
            List<Datum> inputs = input.getDataSet();
            List<DataSet> result = new ArrayList();

            for (Datum current : inputs) {
                Object currentValue = current.getData();
                if (currentValue instanceof MarkerPhenotype) {

                    MarkerPhenotype mp = (MarkerPhenotype) currentValue;
                    Phenotype pheno = mp.getPhenotype();
                    String phenoName = current.getName() + "_pheno";
                    Datum phenoDatum = new Datum(phenoName, pheno, null);

                    Alignment align = mp.getAlignment();
                    String alignName = current.getName() + "_align";
                    Datum alignDatum = new Datum(alignName, align, null);

                    DataSet tds = new DataSet(new Datum[]{phenoDatum, alignDatum}, this);
                    result.add(tds);

                } else if (currentValue instanceof Alignment) {

                    Alignment align = (Alignment) currentValue;
                    Alignment[] alignments = align.getAlignments();
                    for (int i = 0; i < alignments.length; i++) {
                        int[] offsets = alignments[i].getLociOffsets();
                        if (offsets.length > 1) {
                            Locus[] loci = alignments[i].getLoci();
                            for (int j = 0; j < offsets.length; j++) {
                                String name = current.getName() + "_chrom" + loci[j];
                                int endSite;
                                try {
                                    endSite = offsets[j + 1] - 1;
                                } catch (Exception e) {
                                    endSite = alignments[i].getSiteCount() - 1;
                                }
                                Datum td = new Datum(name, FilterAlignment.getInstance(alignments[i], offsets[j], endSite), null);
                                DataSet tds = new DataSet(td, null);
                                result.add(tds);
                            }
                        } else {
                            if (alignments.length > 1) {
                                String name = current.getName() + "_chrom" + alignments[i].getLocus(0);
                                Datum td = new Datum(name, alignments[i], null);
                                DataSet tds = new DataSet(td, null);
                                result.add(tds);
                            }
                        }
                    }
                }
            }

            if (result.isEmpty()) {
                if (isInteractive()) {
                    JOptionPane.showMessageDialog(getParentFrame(), "Nothing to Separate");
                } else {
                    myLogger.warn("performFunction: Nothing to Separate.");
                }
                return null;
            } else {
                DataSet resultDataSet = DataSet.getDataSet(result, this);
                fireDataSetReturned(new PluginEvent(resultDataSet, SeparatePlugin.class));
                return resultDataSet;
            }
        } finally {
            fireProgress(100);
        }

    }

    /**
     * Icon for this plugin to be used in buttons, etc.
     *
     * @return ImageIcon
     */
    public ImageIcon getIcon() {
        URL imageURL = SeparatePlugin.class.getResource("images/Separate.gif");
        if (imageURL == null) {
            return null;
        } else {
            return new ImageIcon(imageURL);
        }
    }

    /**
     * Button name for this plugin to be used in buttons, etc.
     *
     * @return String
     */
    public String getButtonName() {
        return "Separate";
    }

    /**
     * Tool Tip Text for this plugin
     *
     * @return String
     */
    public String getToolTipText() {
        return "Separate Data into Components";
    }
}
<commit_msg>Added utility method that separates an Alignment into FilterAlignments for each Loci.<commit_after>/*
 * SeparatePlugin.java
 *
 * Created on July 31, 2010
 *
 */
package net.maizegenetics.baseplugins;

import net.maizegenetics.pal.alignment.*;
import net.maizegenetics.plugindef.AbstractPlugin;
import net.maizegenetics.plugindef.DataSet;
import net.maizegenetics.plugindef.Datum;
import net.maizegenetics.plugindef.PluginEvent;

import java.awt.Frame;

import javax.swing.*;

import java.net.URL;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

/**
 *
 * @author terry
 */
public class SeparatePlugin extends AbstractPlugin {

    private static final Logger myLogger = Logger.getLogger(SeparatePlugin.class);

    /**
     * Creates a new instance of SeparatePlugin
     */
    public SeparatePlugin(Frame parentFrame, boolean isInteractive) {
        super(parentFrame, isInteractive);
    }

    public DataSet performFunction(DataSet input) {

        try {
            List<Datum> inputs = input.getDataSet();
            List<DataSet> result = new ArrayList();

            for (Datum current : inputs) {
                Object currentValue = current.getData();
                if (currentValue instanceof MarkerPhenotype) {

                    MarkerPhenotype mp = (MarkerPhenotype) currentValue;
                    Phenotype pheno = mp.getPhenotype();
                    String phenoName = current.getName() + "_pheno";
                    Datum phenoDatum = new Datum(phenoName, pheno, null);

                    Alignment align = mp.getAlignment();
                    String alignName = current.getName() + "_align";
                    Datum alignDatum = new Datum(alignName, align, null);

                    DataSet tds = new DataSet(new Datum[]{phenoDatum, alignDatum}, this);
                    result.add(tds);

                } else if (currentValue instanceof Alignment) {

                    List<Datum> alignments = separateAlignmentIntoLoci((Alignment) currentValue, current.getName());
                    if (alignments.size() > 0) {
                        DataSet tds = new DataSet(alignments, this);
                        result.add(tds);
                    }

                }
            }

            if (result.isEmpty()) {
                if (isInteractive()) {
                    JOptionPane.showMessageDialog(getParentFrame(), "Nothing to Separate");
                } else {
                    myLogger.warn("performFunction: Nothing to Separate.");
                }
                return null;
            } else {
                DataSet resultDataSet = DataSet.getDataSet(result, this);
                fireDataSetReturned(new PluginEvent(resultDataSet, SeparatePlugin.class));
                return resultDataSet;
            }
        } finally {
            fireProgress(100);
        }

    }

    public static List<Datum> separateAlignmentIntoLoci(Alignment alignment, String dataSetName) {

        List<Datum> result = new ArrayList<Datum>();
        Alignment[] alignments = alignment.getAlignments();
        for (int i = 0; i < alignments.length; i++) {
            int[] offsets = alignments[i].getLociOffsets();
            if (offsets.length > 1) {
                Locus[] loci = alignments[i].getLoci();
                for (int j = 0; j < offsets.length; j++) {
                    String name;
                    if (dataSetName == null) {
                        name = "Alignment_chrom" + loci[j];
                    } else {
                        name = dataSetName + "_chrom" + loci[j];
                    }
                    int endSite;
                    try {
                        endSite = offsets[j + 1] - 1;
                    } catch (Exception e) {
                        endSite = alignments[i].getSiteCount() - 1;
                    }
                    Datum td = new Datum(name, FilterAlignment.getInstance(alignments[i], offsets[j], endSite), null);
                    result.add(td);
                }
            } else {
                if (alignments.length > 1) {
                    String name;
                    if (dataSetName == null) {
                        name = "Alignment_chrom" + alignments[i].getLocus(0);
                    } else {
                        name = dataSetName + "_chrom" + alignments[i].getLocus(0);
                    }
                    Datum td = new Datum(name, alignments[i], null);
                    result.add(td);
                }
            }
        }

        return result;

    }

    /**
     * Icon for this plugin to be used in buttons, etc.
     *
     * @return ImageIcon
     */
    public ImageIcon getIcon() {
        URL imageURL = SeparatePlugin.class.getResource("images/Separate.gif");
        if (imageURL == null) {
            return null;
        } else {
            return new ImageIcon(imageURL);
        }
    }

    /**
     * Button name for this plugin to be used in buttons, etc.
     *
     * @return String
     */
    public String getButtonName() {
        return "Separate";
    }

    /**
     * Tool Tip Text for this plugin
     *
     * @return String
     */
    public String getToolTipText() {
        return "Separate Data into Components";
    }
}

{'fraction_non_alphanumeric': 0.09377696806980534, 'fraction_numerical': 0.0036436858759229074, 'mean_word_length': 1.3801916932907348, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3134680', 'n_tokens_mistral': 2823, 'n_tokens_neox': 2541, 'n_words': 628}