Search in sources :

Example 1 with ShrimpDataFileInterface

use of org.cirdles.squid.shrimp.ShrimpDataFileInterface in project Squid by CIRDLES.

the class OPFileHandler method convertOPFilesToPrawnFile.

private ShrimpDataFileInterface convertOPFilesToPrawnFile(List<OPFraction> opFractions) {
    ShrimpDataFileInterface prawnFile = new PrawnFile();
    prawnFile.setSoftwareVersion("Squid3 v" + Squid.VERSION + "-processed OP File");
    for (OPFraction opFraction : opFractions) {
        PrawnFile.Run run = new PrawnFile.Run();
        // run
        // run parameters
        PrawnFile.Run.Par title = new PrawnFile.Run.Par();
        title.setName(RunParameterNames.TITLE);
        title.setValue(opFraction.getName());
        run.getPar().add(title);
        PrawnFile.Run.Par sets = new PrawnFile.Run.Par();
        sets.setName(RunParameterNames.SETS);
        sets.setValue("" + opFraction.getSets());
        run.getPar().add(sets);
        PrawnFile.Run.Par measurements = new PrawnFile.Run.Par();
        measurements.setName(RunParameterNames.MEASUREMENTS);
        measurements.setValue("" + opFraction.getMeasurements());
        run.getPar().add(measurements);
        PrawnFile.Run.Par scans = new PrawnFile.Run.Par();
        scans.setName(RunParameterNames.SCANS);
        scans.setValue("" + opFraction.getScans());
        run.getPar().add(scans);
        PrawnFile.Run.Par deadTimeNS = new PrawnFile.Run.Par();
        deadTimeNS.setName(RunParameterNames.DEAD_TIME_NS);
        deadTimeNS.setValue("0");
        // placeholder in Par list
        run.getPar().add(deadTimeNS);
        PrawnFile.Run.Par sbmZeroCps = new PrawnFile.Run.Par();
        sbmZeroCps.setName(RunParameterNames.SBM_ZERO_CPS);
        sbmZeroCps.setValue("" + opFraction.getSbmZeroCPS());
        run.getPar().add(sbmZeroCps);
        // need placeholders
        /*
            <par name="autocentering" value="yes" />
            <par name="qt1y_mode" value="qt1y_scan" /><!-- can be "focus_stage" "qt1y_scan" "constant" -->
            <par name="deflect_beam_between_peaks" value="yes" />
            <par name="autocenter_method" value="50_percent_pk_height" /><!-- can be "polynomial_fit" "50_percent_pk_height" "sliding_integral" -->
            <par name="stage_x" value="4927" />
            <par name="stage_y" value="14867" />
            <par name="stage_z" value="7415" />
             */
        // placeholder in Par list
        run.getPar().add(deadTimeNS);
        // placeholder in Par list
        run.getPar().add(deadTimeNS);
        // placeholder in Par list
        run.getPar().add(deadTimeNS);
        // placeholder in Par list
        run.getPar().add(deadTimeNS);
        // placeholder in Par list
        run.getPar().add(deadTimeNS);
        // placeholder in Par list
        run.getPar().add(deadTimeNS);
        // placeholder in Par list
        run.getPar().add(deadTimeNS);
        // run.runtable
        // run.runtable entries
        // run.runtable entry parameters
        run.setRunTable(new PrawnFile.Run.RunTable());
        for (int i = 0; i < opFraction.getCountTimeSec().length; i++) {
            PrawnFile.Run.RunTable.Entry entry = new PrawnFile.Run.RunTable.Entry();
            // the first two are faked for now
            PrawnFile.Run.RunTable.Entry.Par label = new PrawnFile.Run.RunTable.Entry.Par();
            label.setName(RunTableEntryParameterNames.LABEL);
            int measCount = opFraction.getMeasurements();
            label.setValue((measCount == 9) ? massStationLabelsNINE[i] : (measCount == 10) ? massStationLabelsTEN[i] : massStationLabelsELEVEN[i]);
            entry.getPar().add(label);
            PrawnFile.Run.RunTable.Entry.Par amu = new PrawnFile.Run.RunTable.Entry.Par();
            amu.setName(RunTableEntryParameterNames.AMU);
            amu.setValue((measCount == 9) ? massStationAMUsNINE[i] : (measCount == 10) ? massStationAMUsTEN[i] : massStationAMUsELEVEN[i]);
            entry.getPar().add(amu);
            // need placeholder parameters for
            /*
                <par name="trim_amu" value="0.000" />
                <par name="autocenter_offset_amu" value="0.000000" /><!-- 0=do not use -->
                 */
            PrawnFile.Run.RunTable.Entry.Par placeHolderPar = new PrawnFile.Run.RunTable.Entry.Par();
            entry.getPar().add(placeHolderPar);
            entry.getPar().add(placeHolderPar);
            PrawnFile.Run.RunTable.Entry.Par countTimeSec = new PrawnFile.Run.RunTable.Entry.Par();
            countTimeSec.setName(RunTableEntryParameterNames.COUNT_TIME_SEC);
            countTimeSec.setValue("" + opFraction.getCountTimeSec()[i]);
            entry.getPar().add(countTimeSec);
            // need placeholder parameters for
            /*
                <par name="delay_sec" value="5.000" />
                <par name="collector_focus" value="18.000" />
                 */
            entry.getPar().add(placeHolderPar);
            entry.getPar().add(placeHolderPar);
            PrawnFile.Run.RunTable.Entry.Par centeringTimeSec = new PrawnFile.Run.RunTable.Entry.Par();
            centeringTimeSec.setName(RunTableEntryParameterNames.CENTERING_TIME_SEC);
            centeringTimeSec.setValue("0");
            entry.getPar().add(centeringTimeSec);
            run.getRunTable().getEntry().add(entry);
        }
        // run.set
        // run.set parameters
        // run.set.scan
        // run.set.scan.measurement
        // run.set.scan.measurement.parameters
        // run.set.scan.measurement.data
        run.setSet(new PrawnFile.Run.Set());
        PrawnFile.Run.Set.Par date = new PrawnFile.Run.Set.Par();
        date.setName(SetParameterNames.DATE);
        date.setValue(new Date(opFraction.getDateTimeMilliseconds()).toString());
        run.getSet().getPar().add(date);
        PrawnFile.Run.Set.Par time = new PrawnFile.Run.Set.Par();
        time.setName(SetParameterNames.TIME);
        time.setValue(new Time(opFraction.getDateTimeMilliseconds()).toString());
        run.getSet().getPar().add(time);
        for (int j = 0; j < opFraction.getScans(); j++) {
            PrawnFile.Run.Set.Scan scan = new PrawnFile.Run.Set.Scan();
            for (int i = 0; i < opFraction.getMeasurements(); i++) {
                PrawnFile.Run.Set.Scan.Measurement measurement = new PrawnFile.Run.Set.Scan.Measurement();
                // need placeholder
                /*
                    <par name="detectors" value="12" />
                     */
                PrawnFile.Run.Set.Scan.Measurement.Par placeHolderPar = new PrawnFile.Run.Set.Scan.Measurement.Par();
                measurement.getPar().add(placeHolderPar);
                PrawnFile.Run.Set.Scan.Measurement.Par trimMass = new PrawnFile.Run.Set.Scan.Measurement.Par();
                trimMass.setName("trim_mass");
                trimMass.setValue("0");
                measurement.getPar().add(trimMass);
                PrawnFile.Run.Set.Scan.Measurement.Par timeStampSec = new PrawnFile.Run.Set.Scan.Measurement.Par();
                timeStampSec.setName("time_stamp_sec");
                timeStampSec.setValue("" + opFraction.getTimeStampSec()[i][j]);
                measurement.getPar().add(timeStampSec);
                PrawnFile.Run.Set.Scan.Measurement.Data totalCounts = new PrawnFile.Run.Set.Scan.Measurement.Data();
                // TODO: make robust
                if (opFraction.getMeasurements() == 10) {
                    totalCounts.setName(massStationLabelsTEN[i]);
                } else {
                    totalCounts.setName(massStationLabelsELEVEN[i]);
                }
                // place negative total in the measurements slot as a signal flag "OP FILE" to PrawnFileRunParser
                totalCounts.setValue("-" + opFraction.getTotalCounts()[i][j]);
                measurement.getData().add(totalCounts);
                PrawnFile.Run.Set.Scan.Measurement.Data totalSBM = new PrawnFile.Run.Set.Scan.Measurement.Data();
                totalSBM.setName("SBM");
                totalSBM.setValue("" + opFraction.getTotalSBM()[i][j]);
                measurement.getData().add(totalSBM);
                scan.getMeasurement().add(measurement);
            }
            run.getSet().getScan().add(scan);
        }
        prawnFile.getRun().add(run);
    }
    prawnFile.setRuns((short) opFractions.size());
    return prawnFile;
}
Also used : Time(java.sql.Time) PrawnFile(org.cirdles.squid.prawn.PrawnFile) ShrimpDataFileInterface(org.cirdles.squid.shrimp.ShrimpDataFileInterface) Date(java.sql.Date)

Example 2 with ShrimpDataFileInterface

use of org.cirdles.squid.shrimp.ShrimpDataFileInterface in project Squid by CIRDLES.

the class OPFileHandler method convertOPFileToPrawnFile.

public ShrimpDataFileInterface convertOPFileToPrawnFile(File opFile) {
    List<OPFraction> opFractions = OPFileRunFractionParser.parseOPFile(opFile);
    ShrimpDataFileInterface prawnFile = convertOPFilesToPrawnFile(opFractions);
    return prawnFile;
}
Also used : ShrimpDataFileInterface(org.cirdles.squid.shrimp.ShrimpDataFileInterface)

Example 3 with ShrimpDataFileInterface

use of org.cirdles.squid.shrimp.ShrimpDataFileInterface in project Squid by CIRDLES.

the class PrawnLegacyFileHandler method convertPrawnLegacyFileToPrawnFile.

public static ShrimpDataFileInterface convertPrawnLegacyFileToPrawnFile(ShrimpDataLegacyFileInterface prawnLegacyFile) {
    ShrimpDataFileInterface prawnFile = new PrawnFile();
    prawnFile.setSoftwareVersion("Squid3 v" + Squid.VERSION + " - translated from SHRIMP II v2 SW");
    prawnFile.setRuns((short) prawnLegacyFile.getRun().size());
    for (PrawnLegacyFile.Run legacyRun : prawnLegacyFile.getRun()) {
        PrawnFile.Run run = new PrawnFile.Run();
        // run
        // run parameters
        PrawnFile.Run.Par title = new PrawnFile.Run.Par();
        title.setName(RunParameterNames.TITLE);
        title.setValue(legacyRun.getTitle());
        run.getPar().add(title);
        PrawnFile.Run.Par sets = new PrawnFile.Run.Par();
        sets.setName(RunParameterNames.SETS);
        sets.setValue("" + legacyRun.getSets());
        run.getPar().add(sets);
        PrawnFile.Run.Par measurements = new PrawnFile.Run.Par();
        measurements.setName(RunParameterNames.MEASUREMENTS);
        measurements.setValue("" + legacyRun.getPeaks());
        run.getPar().add(measurements);
        PrawnFile.Run.Par scans = new PrawnFile.Run.Par();
        scans.setName(RunParameterNames.SCANS);
        scans.setValue("" + legacyRun.getScans());
        run.getPar().add(scans);
        PrawnFile.Run.Par deadTimeNS = new PrawnFile.Run.Par();
        deadTimeNS.setName(RunParameterNames.DEAD_TIME_NS);
        deadTimeNS.setValue("" + legacyRun.getDeadTimeNs());
        run.getPar().add(deadTimeNS);
        PrawnFile.Run.Par sbmZeroCps = new PrawnFile.Run.Par();
        sbmZeroCps.setName(RunParameterNames.SBM_ZERO_CPS);
        sbmZeroCps.setValue("" + legacyRun.getSbmZeroCps());
        run.getPar().add(sbmZeroCps);
        PrawnFile.Run.Par autocentering = new PrawnFile.Run.Par();
        autocentering.setName(RunParameterNames.AUTOCENTERING);
        autocentering.setValue("" + legacyRun.getAutocentering());
        run.getPar().add(autocentering);
        PrawnFile.Run.Par qt1y_mode = new PrawnFile.Run.Par();
        qt1y_mode.setName(RunParameterNames.QT_1_Y_MODE);
        qt1y_mode.setValue("" + legacyRun.getQt1YMode());
        run.getPar().add(qt1y_mode);
        PrawnFile.Run.Par deflect_beam_between_peaks = new PrawnFile.Run.Par();
        deflect_beam_between_peaks.setName(RunParameterNames.DEFLECT_BEAM_BETWEEN_PEAKS);
        deflect_beam_between_peaks.setValue("" + legacyRun.getDeflectBeamBetweenPeaks());
        run.getPar().add(deflect_beam_between_peaks);
        PrawnFile.Run.Par autocenter_method = new PrawnFile.Run.Par();
        autocenter_method.setName(RunParameterNames.AUTOCENTER_METHOD);
        autocenter_method.setValue("" + legacyRun.getAutocenterMethod());
        run.getPar().add(autocenter_method);
        // need placeholders for stage x,y,z
        PrawnFile.Run.Par stage_x = new PrawnFile.Run.Par();
        stage_x.setName(RunParameterNames.STAGE_X);
        stage_x.setValue("0");
        run.getPar().add(stage_x);
        PrawnFile.Run.Par stage_y = new PrawnFile.Run.Par();
        stage_y.setName(RunParameterNames.STAGE_Y);
        stage_y.setValue("0");
        run.getPar().add(stage_y);
        PrawnFile.Run.Par stage_z = new PrawnFile.Run.Par();
        stage_z.setName(RunParameterNames.STAGE_Z);
        stage_z.setValue("0");
        run.getPar().add(stage_z);
        // run.runtable
        // run.runtable entries
        // run.runtable entry parameters
        run.setRunTable(new PrawnFile.Run.RunTable());
        for (int i = 0; i < legacyRun.getRunTable().getName().size(); i++) {
            PrawnFile.Run.RunTable.Entry entry = new PrawnFile.Run.RunTable.Entry();
            PrawnLegacyFile.Run.RunTable legacyRunTable = legacyRun.getRunTable();
            PrawnFile.Run.RunTable.Entry.Par label = new PrawnFile.Run.RunTable.Entry.Par();
            label.setName(RunTableEntryParameterNames.LABEL);
            label.setValue("" + legacyRunTable.getName().get(i));
            entry.getPar().add(label);
            PrawnFile.Run.RunTable.Entry.Par amu = new PrawnFile.Run.RunTable.Entry.Par();
            amu.setName(RunTableEntryParameterNames.AMU);
            amu.setValue("" + legacyRunTable.getTrimMass().get(i));
            entry.getPar().add(amu);
            PrawnFile.Run.RunTable.Entry.Par trim_amu = new PrawnFile.Run.RunTable.Entry.Par();
            trim_amu.setName(RunTableEntryParameterNames.TRIM_AMU);
            trim_amu.setValue("0.0");
            entry.getPar().add(trim_amu);
            PrawnFile.Run.RunTable.Entry.Par autocenter_offset_amu = new PrawnFile.Run.RunTable.Entry.Par();
            autocenter_offset_amu.setName(RunTableEntryParameterNames.AUTOCENTER_OFFSET_AMU);
            autocenter_offset_amu.setValue("0.0");
            entry.getPar().add(autocenter_offset_amu);
            PrawnFile.Run.RunTable.Entry.Par countTimeSec = new PrawnFile.Run.RunTable.Entry.Par();
            countTimeSec.setName(RunTableEntryParameterNames.COUNT_TIME_SEC);
            countTimeSec.setValue("" + legacyRunTable.getCountTimeSec().get(i));
            entry.getPar().add(countTimeSec);
            PrawnFile.Run.RunTable.Entry.Par delay_sec = new PrawnFile.Run.RunTable.Entry.Par();
            delay_sec.setName(RunTableEntryParameterNames.DELAY_SEC);
            delay_sec.setValue("" + legacyRunTable.getDelaySec().get(i));
            entry.getPar().add(delay_sec);
            PrawnFile.Run.RunTable.Entry.Par collector_focus = new PrawnFile.Run.RunTable.Entry.Par();
            collector_focus.setName(RunTableEntryParameterNames.COLLECTOR_FOCUS);
            collector_focus.setValue("" + legacyRunTable.getCollectorFocus().get(i));
            entry.getPar().add(collector_focus);
            PrawnFile.Run.RunTable.Entry.Par centeringTimeSec = new PrawnFile.Run.RunTable.Entry.Par();
            centeringTimeSec.setName(RunTableEntryParameterNames.CENTERING_TIME_SEC);
            centeringTimeSec.setValue("" + legacyRunTable.getCenteringTimeSec().get(i));
            entry.getPar().add(centeringTimeSec);
            PrawnFile.Run.RunTable.Entry.Par centering_frequency = new PrawnFile.Run.RunTable.Entry.Par();
            centering_frequency.setName(RunTableEntryParameterNames.CENTERING_FREQUENCY);
            centering_frequency.setValue("" + legacyRunTable.getCenteringFrequency().get(i));
            entry.getPar().add(centering_frequency);
            PrawnFile.Run.RunTable.Entry.Par detector_selection = new PrawnFile.Run.RunTable.Entry.Par();
            detector_selection.setName(RunTableEntryParameterNames.DETECTOR_SELECTION);
            detector_selection.setValue("0.0");
            entry.getPar().add(detector_selection);
            PrawnFile.Run.RunTable.Entry.Par mc_lm_pos = new PrawnFile.Run.RunTable.Entry.Par();
            mc_lm_pos.setName(RunTableEntryParameterNames.MC_LM_POS);
            mc_lm_pos.setValue("-1.000");
            entry.getPar().add(mc_lm_pos);
            PrawnFile.Run.RunTable.Entry.Par mc_hm_pos = new PrawnFile.Run.RunTable.Entry.Par();
            mc_hm_pos.setName(RunTableEntryParameterNames.MC_HM_POS);
            mc_hm_pos.setValue("-1.000");
            entry.getPar().add(mc_hm_pos);
            PrawnFile.Run.RunTable.Entry.Par sc_reference = new PrawnFile.Run.RunTable.Entry.Par();
            sc_reference.setName(RunTableEntryParameterNames.SC_REFERENCE);
            sc_reference.setValue("" + legacyRunTable.getReference().get(i));
            entry.getPar().add(sc_reference);
            PrawnFile.Run.RunTable.Entry.Par sc_detector = new PrawnFile.Run.RunTable.Entry.Par();
            sc_detector.setName(RunTableEntryParameterNames.SC_DETECTOR);
            sc_detector.setValue("" + legacyRunTable.getDetector().get(i));
            entry.getPar().add(sc_detector);
            run.getRunTable().getEntry().add(entry);
        }
        // run.set
        // run.set parameters
        // run.set.scan
        // run.set.scan.measurement
        // run.set.scan.measurement.parameters
        // run.set.scan.measurement.data
        run.setSet(new PrawnFile.Run.Set());
        PrawnFile.Run.Set.Par date = new PrawnFile.Run.Set.Par();
        date.setName(SetParameterNames.DATE);
        date.setValue(legacyRun.getSet().getDate());
        run.getSet().getPar().add(date);
        PrawnFile.Run.Set.Par time = new PrawnFile.Run.Set.Par();
        time.setName(SetParameterNames.TIME);
        time.setValue(legacyRun.getSet().getTime());
        run.getSet().getPar().add(time);
        PrawnFile.Run.Set.Par qt1y = new PrawnFile.Run.Set.Par();
        qt1y.setName(SetParameterNames.QT_1_Y);
        qt1y.setValue("" + legacyRun.getSet().getQt1Y());
        run.getSet().getPar().add(qt1y);
        PrawnFile.Run.Set.Par qt1y_volts = new PrawnFile.Run.Set.Par();
        qt1y_volts.setName(SetParameterNames.QT_1_Y_VOLTS);
        qt1y_volts.setValue("0.0");
        run.getSet().getPar().add(qt1y_volts);
        PrawnFile.Run.Set.Par qt1z = new PrawnFile.Run.Set.Par();
        qt1z.setName(SetParameterNames.QT_1_Z);
        qt1z.setValue("0");
        run.getSet().getPar().add(qt1z);
        PrawnFile.Run.Set.Par pbm = new PrawnFile.Run.Set.Par();
        pbm.setName(SetParameterNames.PBM);
        pbm.setValue("" + legacyRun.getSet().getPbm());
        run.getSet().getPar().add(pbm);
        // the issue is that the legacy prawn file lists all the scans for a peak together
        // while the newer prawn file lists the scans for every peak together
        // so set up the Prawn data structure to populate
        List<PrawnFile.Run.Set.Scan> scanSet = run.getSet().getScan();
        scanSet.clear();
        for (int i = 0; i < legacyRun.getScans(); i++) {
            PrawnFile.Run.Set.Scan scan = new PrawnFile.Run.Set.Scan();
            scan.setNumber((short) (i + 1));
            scanSet.add(scan);
        }
        for (PrawnLegacyFile.Run.Set.Data.Peak legacyPeak : legacyRun.getSet().getData().getPeak()) {
            for (int i = 0; i < legacyPeak.getScan().size(); i++) {
                PrawnFile.Run.Set.Scan.Measurement measurement = makeMeasurement(legacyPeak.getScan().get(i), legacyPeak.getPeakName());
                scanSet.get(i).getMeasurement().add(measurement);
            }
        }
        prawnFile.getRun().add(run);
    }
    return prawnFile;
}
Also used : ShrimpDataFileInterface(org.cirdles.squid.shrimp.ShrimpDataFileInterface) PrawnFile(org.cirdles.squid.prawn.PrawnFile)

Example 4 with ShrimpDataFileInterface

use of org.cirdles.squid.shrimp.ShrimpDataFileInterface in project Squid by CIRDLES.

the class SquidProject method splitPrawnFileAtRun.

/**
 * Splits the current PrawnFile into two sets of runs based on the index of
 * the run supplied and writes out two prawn xml files in the same folder as
 * the original.
 *
 * @param run
 * @param useOriginalData, when true, the original unedited file is used,
 *                         otherwise the edited file is used.
 * @return String [2] containing the file names of the two Prawn XML files
 * written as a result of the split.
 */
public String[] splitPrawnFileAtRun(Run run, boolean useOriginalData) throws SquidException {
    String[] retVal = new String[2];
    retVal[0] = prawnFileHandler.getCurrentPrawnSourceFileLocation().replace(".xml", "-PART-A.xml").replace(".XML", "-PART-A.xml");
    retVal[1] = prawnFileHandler.getCurrentPrawnSourceFileLocation().replace(".xml", "-PART-B.xml").replace(".XML", "-PART-B.xml");
    // get index from original prawnFile
    int indexOfRun = prawnFile.getRun().indexOf(run);
    List<Run> runs = prawnFile.getRun();
    List<Run> runsCopy;
    if (useOriginalData) {
        ShrimpDataFileInterface prawnFileOriginal = null;
        try {
            prawnFileOriginal = deserializePrawnData();
            runsCopy = new CopyOnWriteArrayList<>(prawnFileOriginal.getRun());
        } catch (IOException | JAXBException | SAXException | SquidException iOException) {
            throw new SquidException(iOException.getMessage());
        }
    } else {
        runsCopy = new CopyOnWriteArrayList<>(runs);
    }
    List<Run> first = runsCopy.subList(0, indexOfRun);
    List<Run> second = runsCopy.subList(indexOfRun, runs.size());
    // keep first
    runs.clear();
    // preserve order
    for (Run runF : first) {
        runs.add(runF);
    }
    prawnFile.setRuns((short) runs.size());
    try {
        prawnFileHandler.writeRawDataFileAsXML(prawnFile, retVal[0]);
    } catch (IOException | JAXBException Exception) {
    }
    runs.clear();
    // preserve order
    for (Run runS : second) {
        runs.add(runS);
    }
    prawnFile.setRuns((short) runs.size());
    try {
        prawnFileHandler.writeRawDataFileAsXML(prawnFile, retVal[1]);
    } catch (IOException | JAXBException Exception) {
    }
    // restore list
    runs.clear();
    // preserve order
    for (Run runF : first) {
        runs.add(runF);
    }
    for (Run runS : second) {
        runs.add(runS);
    }
    prawnFile.setRuns((short) runs.size());
    return retVal;
}
Also used : JAXBException(javax.xml.bind.JAXBException) ShrimpDataFileInterface(org.cirdles.squid.shrimp.ShrimpDataFileInterface) Run(org.cirdles.squid.prawn.PrawnFile.Run) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) SquidException(org.cirdles.squid.exceptions.SquidException)

Example 5 with ShrimpDataFileInterface

use of org.cirdles.squid.shrimp.ShrimpDataFileInterface in project Squid by CIRDLES.

the class SquidProject method setupPrawnXMLFileByJoin.

public boolean setupPrawnXMLFileByJoin(List<File> prawnXMLFilesNew) throws IOException, JAXBException, SAXException, SquidException {
    if (prawnXMLFilesNew.size() == 2) {
        ShrimpDataFileInterface prawnFile1 = prawnFileHandler.unmarshallPrawnFileXML(prawnXMLFilesNew.get(0).getCanonicalPath(), false);
        ShrimpDataFileInterface prawnFile2 = prawnFileHandler.unmarshallPrawnFileXML(prawnXMLFilesNew.get(1).getCanonicalPath(), false);
        if ((prawnFile1 != null) && (prawnFile2 != null)) {
            long start1 = PrawnFileUtilities.timeInMillisecondsOfRun(prawnFile1.getRun().get(0));
            long start2 = PrawnFileUtilities.timeInMillisecondsOfRun(prawnFile2.getRun().get(0));
            if (start1 > start2) {
                prawnFile2.getRun().addAll(prawnFile1.getRun());
                prawnFile2.setRuns((short) prawnFile2.getRun().size());
                prawnSourceFile = new File(prawnXMLFilesNew.get(1).getName().replace(".xml", "").replace(".XML", "") + "-JOIN-" + prawnXMLFilesNew.get(0).getName().replace(".xml", "").replace(".XML", "") + ".xml");
                prawnFile = prawnFile2;
            } else {
                prawnFile1.getRun().addAll(prawnFile2.getRun());
                prawnFile1.setRuns((short) prawnFile1.getRun().size());
                prawnSourceFile = new File(prawnXMLFilesNew.get(0).getName().replace(".xml", "").replace(".XML", "") + "-JOIN-" + prawnXMLFilesNew.get(1).getName().replace(".xml", "").replace(".XML", "") + ".xml");
                prawnFile = prawnFile1;
            }
            updatePrawnFileHandlerWithFileLocation();
            // write and read merged file to confirm conforms to schema
            serializePrawnData(prawnFileHandler.getCurrentPrawnSourceFileLocation());
            prawnFile = prawnFileHandler.unmarshallCurrentPrawnFileXML();
            removedRuns = new ArrayList<>();
            if (prawnFileExists()) {
                task.setPrawnFile(prawnFile);
                ((Task) task).setupSquidSessionSkeleton();
            }
        } else {
            prawnFile = null;
        }
    } else {
        throw new IOException("Two files not present");
    }
    return prawnFileExists();
}
Also used : Task(org.cirdles.squid.tasks.Task) ShrimpDataFileInterface(org.cirdles.squid.shrimp.ShrimpDataFileInterface) IOException(java.io.IOException) PrawnFile(org.cirdles.squid.prawn.PrawnFile) File(java.io.File)

Aggregations

ShrimpDataFileInterface (org.cirdles.squid.shrimp.ShrimpDataFileInterface)7 IOException (java.io.IOException)4 PrawnFile (org.cirdles.squid.prawn.PrawnFile)4 File (java.io.File)3 SquidException (org.cirdles.squid.exceptions.SquidException)3 Path (java.nio.file.Path)2 JAXBException (javax.xml.bind.JAXBException)2 Task (org.cirdles.squid.tasks.Task)2 SAXException (org.xml.sax.SAXException)2 BufferedWriter (java.io.BufferedWriter)1 FileOutputStream (java.io.FileOutputStream)1 URL (java.net.URL)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)1 Date (java.sql.Date)1 Time (java.sql.Time)1 Schema (javax.xml.validation.Schema)1 SchemaFactory (javax.xml.validation.SchemaFactory)1 ResourceExtractor (org.cirdles.commons.util.ResourceExtractor)1 IndexIsoptopesEnum (org.cirdles.squid.constants.Squid3Constants.IndexIsoptopesEnum)1