<commit_before>/*
 * Copyright 2006-2012 The MZmine 2 Development Team
 * 
 * This file is part of MZmine 2.
 * 
 * MZmine 2 is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * MZmine 2 is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * MZmine 2; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
 * Fifth Floor, Boston, MA 02110-1301 USA
 */

package net.sf.mzmine.modules.visualization.spectra.datasets;

import java.util.Map;

import net.sf.mzmine.data.DataPoint;
import net.sf.mzmine.data.Scan;
import net.sf.mzmine.util.Range;

import org.jfree.data.xy.AbstractXYDataset;
import org.jfree.data.xy.IntervalXYDataset;

/**
 * Spectra visualizer data set for scan data points
 */
public class ScanDataSet extends AbstractXYDataset implements IntervalXYDataset {

	private String label;
	private Scan scan;
	private Map<DataPoint, String> annotation;

	/*
	 * Save a local copy of m/z and intensity values, because accessing the scan
	 * every time may cause reloading the data from HDD
	 */
	private DataPoint dataPoints[];

	public ScanDataSet(Scan scan) {
		this("Scan #" + scan.getScanNumber(), scan);
	}

	public ScanDataSet(String label, Scan scan) {
		this.dataPoints = scan.getDataPoints();
		this.scan = scan;
		this.label = label;
	}

	@Override
	public int getSeriesCount() {
		return 1;
	}

	@Override
	public Comparable getSeriesKey(int series) {
		return label;
	}

	public int getItemCount(int series) {
		return dataPoints.length;
	}

	public Number getX(int series, int item) {
		return dataPoints[item].getMZ();
	}

	public Number getY(int series, int item) {
		return dataPoints[item].getIntensity();
	}

	public Number getEndX(int series, int item) {
		return getX(series, item);
	}

	public double getEndXValue(int series, int item) {
		return getXValue(series, item);
	}

	public Number getEndY(int series, int item) {
		return getY(series, item);
	}

	public double getEndYValue(int series, int item) {
		return getYValue(series, item);
	}

	public Number getStartX(int series, int item) {
		return getX(series, item);
	}

	public double getStartXValue(int series, int item) {
		return getXValue(series, item);
	}

	public Number getStartY(int series, int item) {
		return getY(series, item);
	}

	public double getStartYValue(int series, int item) {
		return getYValue(series, item);
	}

	/**
	 * This function finds highest data point intensity in given m/z range. It
	 * is important for normalizing isotope patterns.
	 */
	public double getHighestIntensity(Range mzRange) {

		double maxIntensity = 0;
		for (DataPoint dp : dataPoints) {
			if ((mzRange.contains(dp.getMZ()))
					&& (dp.getIntensity() > maxIntensity))
				maxIntensity = dp.getIntensity();
		}

		return maxIntensity;
	}

	public Scan getScan() {
		return scan;
	}

	public void addAnnotation(Map<DataPoint, String> annotation) {
		this.annotation = annotation;
	}

	public String getAnnotation(int item) {
		if (annotation == null)
			return null;
		return annotation.get(dataPoints[item]);
	}
	
}<commit_msg>Fixed the annotation of MS/MS spectra in case continuous data are used<commit_after>/*
 * Copyright 2006-2012 The MZmine 2 Development Team
 * 
 * This file is part of MZmine 2.
 * 
 * MZmine 2 is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * MZmine 2 is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * MZmine 2; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
 * Fifth Floor, Boston, MA 02110-1301 USA
 */

package net.sf.mzmine.modules.visualization.spectra.datasets;

import java.util.Map;

import net.sf.mzmine.data.DataPoint;
import net.sf.mzmine.data.Scan;
import net.sf.mzmine.util.Range;

import org.jfree.data.xy.AbstractXYDataset;
import org.jfree.data.xy.IntervalXYDataset;

/**
 * Spectra visualizer data set for scan data points
 */
public class ScanDataSet extends AbstractXYDataset implements IntervalXYDataset {

    private String label;
    private Scan scan;
    private Map<DataPoint, String> annotation;

    /*
     * Save a local copy of m/z and intensity values, because accessing the scan
     * every time may cause reloading the data from HDD
     */
    private DataPoint dataPoints[];

    public ScanDataSet(Scan scan) {
	this("Scan #" + scan.getScanNumber(), scan);
    }

    public ScanDataSet(String label, Scan scan) {
	this.dataPoints = scan.getDataPoints();
	this.scan = scan;
	this.label = label;
    }

    @Override
    public int getSeriesCount() {
	return 1;
    }

    @Override
    public Comparable getSeriesKey(int series) {
	return label;
    }

    public int getItemCount(int series) {
	return dataPoints.length;
    }

    public Number getX(int series, int item) {
	return dataPoints[item].getMZ();
    }

    public Number getY(int series, int item) {
	return dataPoints[item].getIntensity();
    }

    public Number getEndX(int series, int item) {
	return getX(series, item);
    }

    public double getEndXValue(int series, int item) {
	return getXValue(series, item);
    }

    public Number getEndY(int series, int item) {
	return getY(series, item);
    }

    public double getEndYValue(int series, int item) {
	return getYValue(series, item);
    }

    public Number getStartX(int series, int item) {
	return getX(series, item);
    }

    public double getStartXValue(int series, int item) {
	return getXValue(series, item);
    }

    public Number getStartY(int series, int item) {
	return getY(series, item);
    }

    public double getStartYValue(int series, int item) {
	return getYValue(series, item);
    }

    /**
     * This function finds highest data point intensity in given m/z range. It
     * is important for normalizing isotope patterns.
     */
    public double getHighestIntensity(Range mzRange) {

	double maxIntensity = 0;
	for (DataPoint dp : dataPoints) {
	    if ((mzRange.contains(dp.getMZ()))
		    && (dp.getIntensity() > maxIntensity))
		maxIntensity = dp.getIntensity();
	}

	return maxIntensity;
    }

    public Scan getScan() {
	return scan;
    }

    public void addAnnotation(Map<DataPoint, String> annotation) {
	this.annotation = annotation;
    }

    public String getAnnotation(int item) {
	if (annotation == null)
	    return null;
	DataPoint itemDataPoint = dataPoints[item];
	for (DataPoint key : annotation.keySet()) {
	    if (Math.abs(key.getMZ() - itemDataPoint.getMZ()) < 0.001)
		return annotation.get(key);
	}
	return null;
    }

}
{'fraction_non_alphanumeric': 0.09226557152635181, 'fraction_numerical': 0.007939767282683094, 'mean_word_length': 3.650541056651814, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5453662', 'n_tokens_mistral': 2369, 'n_tokens_neox': 2202, 'n_words': 776}