use of net.sf.mzmine.datamodel.MassList in project mzmine2 by mzmine.
the class IsotopePeakScannerTask method checkParameters.
private boolean checkParameters() {
if (charge == 0) {
setErrorMessage("Error: charge may not be 0!");
setStatus(TaskStatus.ERROR);
return false;
}
if (!FormulaUtils.checkMolecularFormula(element)) {
setErrorMessage("Error: Invalid formula!");
setStatus(TaskStatus.ERROR);
return false;
}
if (accurateAvgIntensity || ratingType == RatingType.TEMPAVG) {
if (massListName.equals("") && ratingType == RatingType.TEMPAVG) {
setErrorMessage("Error: Rating Type = temporary average but no masslist was selected.\nYou can" + " select a mass list without checking accurate average.");
setStatus(TaskStatus.ERROR);
return false;
}
if (peakList.getNumberOfRawDataFiles() > 1) {
setErrorMessage("The number of raw data files of feature list \"" + peakList.getName() + "\" is greater than 1. This is not supported by this module.");
setStatus(TaskStatus.ERROR);
return false;
}
RawDataFile[] raws = peakList.getRawDataFiles();
boolean foundMassList = false;
for (RawDataFile raw : raws) {
int[] scanNumbers = raw.getScanNumbers();
for (int scan : scanNumbers) {
MassList[] massLists = raw.getScan(scan).getMassLists();
for (MassList list : massLists) {
if (list.getName().equals(massListName))
foundMassList = true;
}
}
}
if (foundMassList == false) {
setErrorMessage("Feature list \"" + peakList.getName() + "\" does not contain a mass list by the name of " + massListName + ".");
setStatus(TaskStatus.ERROR);
return false;
}
}
return true;
}
use of net.sf.mzmine.datamodel.MassList in project mzmine2 by mzmine.
the class ScanSelectPanel method getFilteredDataPoints.
/**
* Remaining data points after filtering
*
* @return
*/
@Nullable
public DataPoint[] getFilteredDataPoints() {
if (scans != null && !scans.isEmpty()) {
Scan scan = scans.get(selectedScanI);
MassList massList = ScanUtils.getMassListOrFirst(scan, massListName);
if (massList != null)
return ScanUtils.getFiltered(massList.getDataPoints(), noiseLevel);
}
return null;
}
use of net.sf.mzmine.datamodel.MassList in project mzmine2 by mzmine.
the class ScanSelectPanel method analyzeScan.
private void analyzeScan(Scan scan) {
MassList massList = ScanUtils.getMassListOrFirst(scan, massListName);
if (massList != null) {
DataPoint[] dp = massList.getDataPoints();
double tic = ScanUtils.getTIC(dp, noiseLevel);
int signals = ScanUtils.getNumberOfSignals(dp, noiseLevel);
lbTIC.setText(MZmineCore.getConfiguration().getIntensityFormat().format(tic));
lbSignals.setText("" + signals);
lbTIC.getParent().revalidate();
lbTIC.getParent().repaint();
}
}
use of net.sf.mzmine.datamodel.MassList in project mzmine2 by mzmine.
the class ExtractScansTask method exportScans.
private void exportScans(File dir, RawDataFile raw, int start, int scans, double pp) {
// Open file
DecimalFormat format = new DecimalFormat("00");
File fileDir = new File(dir, FileAndPathUtil.eraseFormat(raw.getName()));
FileAndPathUtil.createDirectory(fileDir);
int end = Math.min(scans + start, raw.getNumOfScans());
String linescans = "scan" + delimiter + raw.getScanNumbers()[start] + delimiter + "to" + delimiter + raw.getScanNumbers()[end - 1] + "\n";
String lineRT = "RT" + delimiter + raw.getScan(raw.getScanNumbers()[start]).getRetentionTime() + "to" + raw.getScan(raw.getScanNumbers()[end - 1]).getRetentionTime() + "\n";
String linePath = raw.getName() + "\n";
String lineOptions = "export of" + delimiter;
if (!useCenterTime) {
double st = raw.getScan(raw.getScanNumbers()[start]).getRetentionTime();
double et = raw.getScan(raw.getScanNumbers()[end]).getRetentionTime();
lineOptions += scans + delimiter + "scans from time " + delimiter + st + " to " + et + "\n";
} else if (autoMax) {
lineOptions += scans + delimiter + "scans around scan with maximum intensity:" + delimiter + raw.getScanNumbers()[scanMaxTIC] + "\n";
} else {
lineOptions += scans + delimiter + "scans around center time:" + delimiter + centerTime + "\n";
}
for (int i = start; i < end; i++) {
FileWriter writer;
File file = new File(fileDir, "scan" + format.format((i - start + 1)) + ".csv");
StringBuilder out = new StringBuilder();
try {
writer = new FileWriter(file);
} catch (Exception e) {
e.printStackTrace();
return;
}
// EXPORT
try {
Scan s = raw.getScan(raw.getScanNumbers()[i]);
// write header
if (exportHeader) {
out.append(linePath);
out.append(linescans);
out.append(lineRT);
out.append(lineOptions);
out.append("TIC" + delimiter + s.getTIC() + "\n");
out.append("scan number" + delimiter + raw.getScanNumbers()[i] + "\n");
out.append("retention time" + delimiter + s.getRetentionTime() + "\n\n");
out.append("mz" + delimiter + "intensity\n");
}
// write data
if (useMassList) {
MassList mass = s.getMassList(massList);
DataPoint[] dp = mass.getDataPoints();
for (int k = 0; k < dp.length; k++) {
out.append(dp[k].getMZ() + delimiter + dp[k].getIntensity() + "\n");
}
} else {
for (int k = 0; k < s.getNumberOfDataPoints(); k++) {
DataPoint dp = s.getDataPoints()[k];
out.append(dp.getMZ() + delimiter + dp.getIntensity() + "\n");
}
}
writeBuffered(writer, out.toString(), 8192);
} catch (IOException e1) {
e1.printStackTrace();
} finally {
// Close file
try {
writer.close();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
//
perc += pp / (double) scans;
}
}
use of net.sf.mzmine.datamodel.MassList in project mzmine2 by mzmine.
the class ExportScansTask method exportText.
/**
* Export the chromatogram - text formats
*
* @throws IOException if there are i/o problems.
*/
public void exportText() throws IOException {
// Open the writer - append data if file already exists
final BufferedWriter writer = new BufferedWriter(new FileWriter(exportFile, true));
try {
for (Scan scan : scans) {
LOG.info("Exporting scan #" + scan.getScanNumber() + " of raw file: " + scan.getDataFile().getName());
// Write Header row
switch(extension) {
case "txt":
writer.write("Name: Scan#: " + scan.getScanNumber() + ", RT: " + scan.getRetentionTime() + " min");
writer.newLine();
break;
case "mgf":
writer.write("BEGIN IONS");
writer.newLine();
writer.write("PEPMASS=" + scan.getPrecursorMZ());
writer.newLine();
writer.write("CHARGE=" + scan.getPrecursorCharge());
writer.newLine();
writer.write("MSLEVEL=" + scan.getMSLevel());
writer.newLine();
writer.write("Title: Scan#: " + scan.getScanNumber() + ", RT: " + scan.getRetentionTime() + " min");
writer.newLine();
break;
case "msp":
break;
}
// Write the data points
DataPoint[] dataPoints = null;
if (useMassList && massListName != null) {
MassList list = scan.getMassList(massListName);
if (list != null)
dataPoints = list.getDataPoints();
}
if (dataPoints == null)
dataPoints = scan.getDataPoints();
final int itemCount = dataPoints.length;
progressMax = itemCount;
for (int i = 0; i < itemCount; i++) {
// Write data point row
writer.write(dataPoints[i].getMZ() + " " + dataPoints[i].getIntensity());
writer.newLine();
progress = i + 1;
}
// Write footer row
if (extension.equals("mgf")) {
writer.write("END IONS");
writer.newLine();
}
writer.newLine();
}
} catch (Exception e) {
throw (new IOException(e));
} finally {
// Close
writer.close();
}
}
Aggregations