Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions ms2/src/org/labkey/ms2/PepXmlImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ protected static String switchSuffix(String filename, String suffix)

protected void processSpectrumFile(PepXmlFraction fraction, Set<Integer> scans, MS2Progress progress, boolean shouldLoadSpectra, boolean shouldLoadRetentionTimes)
{
File mzXmlFile = getMzXMLFile(fraction);
FileLike mzXmlFileLike = null;
FileLike mzXmlFile = FileSystemLike.wrapFile(getMzXMLFile(fraction));
if ((_run.getType().equalsIgnoreCase(MS2RunType.Mascot.name())||_run.getType().equalsIgnoreCase(MS2RunType.Sequest.name())) // TODO: Move this check (perhaps all the code) into the appropriate run classes
&& null == mzXmlFile)
{
Expand All @@ -242,25 +241,19 @@ protected void processSpectrumFile(PepXmlFraction fraction, Set<Integer> scans,
String mzXmlFileName = engineProtocolMzXMLFile.getName();
FileLike engineProtocolDir = engineProtocolMzXMLFile.getParent();
FileLike engineDir = engineProtocolDir.getParent();
FileLike mzXMLFile = engineDir.getParent().resolveFile(Path.parse(mzXmlFileName));
mzXmlFileLike = mzXMLFile;
}
String gzFileName = _path + "/" + _gzFileName;
File gzFile = _context.findFile(gzFileName);
if (gzFile != null)
{
gzFileName = gzFile.toString();
mzXmlFile = engineDir.getParent().resolveFile(Path.parse(mzXmlFileName));
}
FileLike gzFile = FileSystemLike.wrapFile(_context.findFile(_path)).resolveChild(_gzFileName);
//sequest spectra are imported from the tgz but are deleted after they are imported.
if(_run.getType().equalsIgnoreCase("sequest") && mzXmlFile != null) // TODO: Move this check (perhaps all the code) into the appropriate run classes
if(_run.getType().equalsIgnoreCase(MS2RunType.Sequest.name()) && mzXmlFile != null) // TODO: Move this check (perhaps all the code) into the appropriate run classes
{
if (NetworkDrive.exists(mzXmlFile))
{
gzFileName = "";
gzFile = null;
}
}

SpectrumImporter sl = new SpectrumImporter(gzFileName, "", mzXmlFileLike, scans, progress, _fractionId, _log, shouldLoadSpectra, shouldLoadRetentionTimes);
SpectrumImporter sl = new SpectrumImporter(gzFile, "", mzXmlFile, scans, progress, _fractionId, _log, shouldLoadSpectra, shouldLoadRetentionTimes);
sl.upload();
updateFractionSpectrumFileName(sl.getFile() == null ? null : sl.getFile().toNioPathForRead().toFile());
}
Expand Down
25 changes: 12 additions & 13 deletions ms2/src/org/labkey/ms2/SpectrumImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@

package org.labkey.ms2;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.labkey.api.data.DbSchema;
import org.labkey.api.util.NetworkDrive;
import org.labkey.api.util.Pair;
import org.labkey.ms2.reader.*;
import org.labkey.ms2.reader.AbstractMzxmlIterator;
import org.labkey.ms2.reader.SimpleScan;
import org.labkey.ms2.reader.SimpleScanIterator;
import org.labkey.ms2.reader.TarIterator;
import org.labkey.vfs.FileLike;
import org.labkey.vfs.FileSystemLike;

import javax.xml.stream.XMLStreamException;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
Expand Down Expand Up @@ -55,7 +56,7 @@ public class SpectrumImporter
private final boolean _shouldImportRetentionTime;


protected SpectrumImporter(String gzFileName, String dtaFileNamePrefix, FileLike mzXmlFile, Set<Integer> scans, MS2Importer.MS2Progress progress, int fractionId, Logger log, boolean shouldImportSpectra, boolean shouldImportRetentionTime)
protected SpectrumImporter(FileLike gzFile, String dtaFileNamePrefix, FileLike mzXmlFile, Set<Integer> scans, MS2Importer.MS2Progress progress, int fractionId, Logger log, boolean shouldImportSpectra, boolean shouldImportRetentionTime)
{
_scans = scans;
_progress = progress;
Expand All @@ -70,22 +71,20 @@ protected SpectrumImporter(String gzFileName, String dtaFileNamePrefix, FileLike
try
{
// Try to access the gz file first... if that fails, try to open the mzXML file
File gz = new File(gzFileName);

if (NetworkDrive.exists(gz))
if (NetworkDrive.exists(gzFile))
{
_file = FileSystemLike.wrapFile(gz);
_scanIterator = new TarIterator(gz, dtaFileNamePrefix);
_file = gzFile;
_scanIterator = new TarIterator(gzFile, dtaFileNamePrefix);
}
else
{
if (null == mzXmlFile)
_log.warn("Spectra were not imported: " + gzFileName + " could not be opened and no mzXML file name was specified.");
_log.warn("Spectra were not imported: " + gzFile + " could not be opened and no mzXML file name was specified.");
else
{
_file = mzXmlFile;
// prefer ProteoWizard's RAMPAdapter interface
// (with JNI bindings via SWIG) as it's actively
// (with JNI bindings via SWIG) as it's actively
// maintained, handles mzML and mzXML, and gzipped
// files natively
_scanIterator = AbstractMzxmlIterator.createParser(_file, 2);
Expand All @@ -99,7 +98,7 @@ protected SpectrumImporter(String gzFileName, String dtaFileNamePrefix, FileLike
catch (XMLStreamException x)
{
throw new RuntimeException(x);
}
}
}

protected void upload()
Expand Down
9 changes: 4 additions & 5 deletions ms2/src/org/labkey/ms2/reader/TarIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.labkey.api.arrays.FloatArray;
import org.labkey.ms2.FloatParser;
import org.labkey.ms2.MS2Importer;
import org.labkey.vfs.FileLike;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.GZIPInputStream;
Expand Down Expand Up @@ -53,13 +52,13 @@ public class TarIterator implements SimpleScanIterator
private byte[] _spectrumData = new byte[BUFFER_SIZE];


public TarIterator(File gzFile, String dtaFileNamePrefix) throws java.io.IOException
public TarIterator(FileLike gzFile, String dtaFileNamePrefix) throws java.io.IOException
{
boolean success = false;
try
{
_dtaFileNamePrefix = dtaFileNamePrefix;
_is = new BufferedInputStream(new FileInputStream(gzFile), STREAM_BUFFER_SIZE);
_is = new BufferedInputStream(gzFile.openInputStream(), STREAM_BUFFER_SIZE);
_gzInputStream = new GZIPInputStream(_is);
_tis = new TarArchiveInputStream(_gzInputStream);
success = true;
Expand Down