Skip to content

Commit

Permalink
Merge pull request mzmine#10 from TDI-tenderholt/misc_fixes
Browse files Browse the repository at this point in the history
Misc fixes related to submitting jobs
  • Loading branch information
DavidARivkin committed Jan 19, 2016
2 parents 059ebc3 + 73b6fee commit 94d6885
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 63 deletions.
85 changes: 34 additions & 51 deletions src/main/java/com/veritomyx/PeakInvestigatorInitDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

//import net.sf.mzmine.main.MZmineCore;
import net.sf.mzmine.util.ExitCode;
Expand All @@ -47,8 +45,7 @@
* The first SLA and the highest version of PI are automatically selected to start.
*
*/
public class PeakInvestigatorInitDialog extends JDialog implements ActionListener,
DocumentListener {
public class PeakInvestigatorInitDialog extends JDialog implements ActionListener {

private static final long serialVersionUID = 1L;

Expand All @@ -66,22 +63,24 @@ public class PeakInvestigatorInitDialog extends JDialog implements ActionListene
*/
protected GridBagPanel mainPanel;

protected JComboBox<String> SLA_list;
protected JComboBox<String> PIV_list;
protected JComboBox<String> responseTimeObjectiveComboBox;
protected JComboBox<String> versionsComboBox;
protected JLabel estimatedCostLabel;

protected String SLA_key;
protected String PIV;
protected Map<String, Double> responseTimeObjectives;

/**
* Constructor
*/
public PeakInvestigatorInitDialog(Window parent, Double funds, Map<String, Double> SLAs, String[] PIversions) {
public PeakInvestigatorInitDialog(Window parent, Double funds, Map<String, Double> responseTimeObjectives, String[] PIversions) {

// Make dialog modal
super(parent, "Please set the parameters",
Dialog.ModalityType.DOCUMENT_MODAL);

addDialogComponents(funds, SLAs, PIversions);
this.responseTimeObjectives = responseTimeObjectives;

addDialogComponents(funds, responseTimeObjectives, PIversions);

updateMinimumSize();
pack();
Expand Down Expand Up @@ -122,25 +121,22 @@ protected void addDialogComponents(Double funds, Map<String, Double> SLAs, Strin
JLabel PIV_label = new JLabel("Use Peak Investigator Version:");
mainPanel.add(PIV_label, 0, 2);

// Create the 2 combo boxes, filled with the available selections.
String[] r = new String[SLAs.size()];
int s = 0;
for(String key : SLAs.keySet()) {
r[s] = "RTO: " + key + " Estimate Cost: $" + String.format( "%.2f", SLAs.get(key));
if(s == 0)
SLA_key = key;
s++;
}
SLA_list = new JComboBox<String>(r);
SLA_list.setEditable(false);
SLA_list.setSelectedIndex(0);
mainPanel.add(SLA_list, 1, 1);

PIV = PIversions[0];
PIV_list = new JComboBox<String>(PIversions);
PIV_list.setEditable(false);
PIV_list.setSelectedIndex(0);
mainPanel.add(PIV_list, 1, 2);
// Create the 2 combo boxes, filled with the available selections.
responseTimeObjectiveComboBox = new JComboBox<String>(SLAs.keySet().toArray(new String[SLAs.size()]));
responseTimeObjectiveComboBox.setEditable(false);
responseTimeObjectiveComboBox.setSelectedIndex(0);
responseTimeObjectiveComboBox.addActionListener(this);
mainPanel.add(responseTimeObjectiveComboBox, 1, 1);

versionsComboBox = new JComboBox<String>(PIversions);
versionsComboBox.setEditable(false);
versionsComboBox.setSelectedIndex(0);
mainPanel.add(versionsComboBox, 1, 2);

JLabel costLabel = new JLabel("Estimated cost:");
mainPanel.add(costLabel, 0, 3);
estimatedCostLabel = new JLabel(formatCost());
mainPanel.add(estimatedCostLabel, 1, 3);

// Add a single empty cell to the 4th row. This cell is expandable
// (weightY is 1), therefore the other components will be
Expand Down Expand Up @@ -192,8 +188,7 @@ public void actionPerformed(ActionEvent ae) {
}

if (src instanceof JComboBox) {
SLA_key = SLA_list.getSelectedItem().toString();
PIV = PIV_list.getSelectedItem().toString();
estimatedCostLabel.setText(formatCost());
}

}
Expand All @@ -218,30 +213,18 @@ public void closeDialog(ExitCode exitCode) {
dispose();

}

@Override
public void changedUpdate(DocumentEvent event) {
SLA_key = SLA_list.getSelectedItem().toString();
PIV = PIV_list.getSelectedItem().toString();
}

@Override
public void insertUpdate(DocumentEvent event) {

public String getSLA() {
return responseTimeObjectiveComboBox.getSelectedItem().toString();
}

@Override
public void removeUpdate(DocumentEvent event) {

}

public String getSLA()
{
return SLA_key;
public String getPIversion() {
return versionsComboBox.getSelectedItem().toString();
}

public String getPIversion()
{
return PIV;
// convenience method to use the selected SLA to return a cost
private String formatCost() {
String currentSelection = responseTimeObjectiveComboBox.getSelectedItem().toString();
return String.format("$%.2f", responseTimeObjectives.get(currentSelection));
}
}
7 changes: 4 additions & 3 deletions src/main/java/com/veritomyx/PeakInvestigatorSaaS.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,11 @@ private int getPage(String action, int count, int minMass, int maxMass)

RawDataFile[] files = MZmineCore.getProjectManager().getCurrentProject().getDataFiles();
for(RawDataFile file : files) {
int scanCount = file.getNumOfScans();
for(int scanNum = 1; scanNum <= scanCount; scanNum++) {
int[] scanNumbers = file.getScanNumbers();
for(int scanNum : scanNumbers) {
Scan scan = file.getScan(scanNum);
int dpCount = scan.getNumberOfDataPoints();
maxMasses = Integer.max(maxMasses.intValue(), dpCount);
maxMasses = Math.max(maxMasses.intValue(), dpCount);
}
}
if(maxMass > maxMasses) {
Expand Down Expand Up @@ -643,6 +643,7 @@ public boolean getFile(String fname)
web_str = "Cannot read file: " + fname;
return false;
}

closeSession(session);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ExitCode showSetupDialog(Window parent, boolean valueCheckRequired)
for(int scanNum = 1; scanNum <= scanCount; scanNum++) {
Scan scan = file.getScan(scanNum);
int dpCount = scan.getNumberOfDataPoints();
maxMasses = Integer.max(maxMasses.intValue(), dpCount);
maxMasses = Math.max(maxMasses.intValue(), dpCount);
}
}
minMass.setMinMax(0, maxMasses-1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,22 +354,22 @@ private void startRetrieve()
TarInputStream tis = null;
FileOutputStream outputStream = null;
try {
File f = new File(outputFilename);
tis = new TarInputStream(new GZIPInputStream(new FileInputStream(f.getName())));
File fullPath = new File(outputFilename); // outputfilename looks like /files/C-1022.1391/C-1022.1391.mass_list.tar
tis = new TarInputStream(new GZIPInputStream(new FileInputStream(fullPath.getName())));
TarEntry tf;
int bytesRead;
byte buf[] = new byte[1024];
while ((tf = tis.getNextEntry()) != null)
{
if (tf.isDirectory()) continue;
logger.info("Reading peaks data to " + tf.getName() + " - " + tf.getSize() + " bytes");
logger.info("Extracting peaks data to " + tf.getName() + " - " + tf.getSize() + " bytes");
outputStream = new FileOutputStream(tf.getName());
while ((bytesRead = tis.read(buf, 0, 1024)) > -1)
outputStream.write(buf, 0, bytesRead);
outputStream.close();
}
tis.close();
f.delete(); // remove the local copy of the results tar file
fullPath.delete(); // remove the local copy of the results tar file
} catch (Exception e1) {
logger.finest(e1.getMessage());
MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Error", "Cannot parse results file", logger);
Expand Down Expand Up @@ -399,14 +399,16 @@ private DataPoint[] processScanRetrieve(int scan_num)

// read in the peaks for this scan
// convert filename to expected peak file name
String pfilename = "scan_" + String.format("%04d", scan_num) + ".vcent.txt";
String pfilename = "scan_" + String.format("%04d", scan_num) + ".scan.mass_list.txt";
logger.info("Parsing peaks data from " + pfilename);
try
{
File centfile = new File(pfilename);
FileChecksum fchksum = new FileChecksum(centfile);
if (!fchksum.verify(false))
throw new IOException("Invalid checksum");
fchksum.verify(false);
// TODO: handle checksums
// if (!fchksum.verify(false))
// throw new IOException("Invalid checksum");

List<String> lines = fchksum.getFileStrings();
mzPeaks = new ArrayList<DataPoint>();
Expand All @@ -431,7 +433,7 @@ private DataPoint[] processScanRetrieve(int scan_num)
}

desc = "scan " + scan_num + " parsed";
return (mzPeaks == null) ? null : mzPeaks.toArray(new DataPoint[0]);
return (mzPeaks == null) ? null : mzPeaks.toArray(new DataPoint[mzPeaks.size()]);
}

/**
Expand Down

0 comments on commit 94d6885

Please sign in to comment.