Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #115 from tomas-pluskal/waters_import
Browse files Browse the repository at this point in the history
Fixed a file type detection bug
  • Loading branch information
dyrlund committed Sep 3, 2015
2 parents 7d2e211 + 8a3b0ac commit 607c53f
Showing 1 changed file with 50 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public class RawDataFileTypeDetector {
private static final String MZDATA_HEADER = "<mzData";

// See "https://code.google.com/p/unfinnigan/wiki/FileHeader"
private static final String THERMO_HEADER = String.valueOf(new char[] {
0x01, 0xA1, 'F', 0, 'i', 0, 'n', 0, 'n', 0, 'i', 0, 'g', 0, 'a', 0,
'n', 0 });
private static final String THERMO_HEADER = String
.valueOf(new char[] { 0x01, 0xA1, 'F', 0, 'i', 0, 'n', 0, 'n', 0,
'i', 0, 'g', 0, 'a', 0, 'n', 0 });

/**
*
Expand All @@ -63,52 +63,53 @@ public class RawDataFileTypeDetector {
*/
public static RawDataFileType detectDataFileType(File fileName) {

if (fileName.isDirectory()) {
// To check for Waters .raw directory, we look for _FUNC[0-9]{3}.DAT
for (File f : fileName.listFiles()) {
if (f.isFile() && f.getName().matches("_FUNC[0-9]{3}.DAT"))
return RawDataFileType.WATERS_RAW;
}
// We don't recognize any other directory type than Waters
return null;
}

if (fileName.getName().toLowerCase().endsWith(".csv")) {
return RawDataFileType.AGILENT_CSV;
}

try {

// Read the first 1kB of the file into a String
InputStreamReader reader = new InputStreamReader(
new FileInputStream(fileName), "ISO-8859-1");
char buffer[] = new char[1024];
reader.read(buffer);
reader.close();
String fileHeader = new String(buffer);

if (fileHeader.startsWith(THERMO_HEADER)) {
return RawDataFileType.THERMO_RAW;
}

if (fileHeader.startsWith(CDF_HEADER)) {
return RawDataFileType.NETCDF;
}

if (fileHeader.contains(MZML_HEADER))
return RawDataFileType.MZML;

if (fileHeader.contains(MZDATA_HEADER))
return RawDataFileType.MZDATA;

if (fileHeader.contains(MZXML_HEADER))
return RawDataFileType.MZXML;

} catch (Exception e) {
e.printStackTrace();
}

return null;
if (fileName.isDirectory()) {
// To check for Waters .raw directory, we look for _FUNC[0-9]{3}.DAT
for (File f : fileName.listFiles()) {
if (f.isFile() && f.getName().toUpperCase()
.matches("_FUNC[0-9]{3}.DAT"))
return RawDataFileType.WATERS_RAW;
}
// We don't recognize any other directory type than Waters
return null;
}

if (fileName.getName().toLowerCase().endsWith(".csv")) {
return RawDataFileType.AGILENT_CSV;
}

try {

// Read the first 1kB of the file into a String
InputStreamReader reader = new InputStreamReader(
new FileInputStream(fileName), "ISO-8859-1");
char buffer[] = new char[1024];
reader.read(buffer);
reader.close();
String fileHeader = new String(buffer);

if (fileHeader.startsWith(THERMO_HEADER)) {
return RawDataFileType.THERMO_RAW;
}

if (fileHeader.startsWith(CDF_HEADER)) {
return RawDataFileType.NETCDF;
}

if (fileHeader.contains(MZML_HEADER))
return RawDataFileType.MZML;

if (fileHeader.contains(MZDATA_HEADER))
return RawDataFileType.MZDATA;

if (fileHeader.contains(MZXML_HEADER))
return RawDataFileType.MZXML;

} catch (Exception e) {
e.printStackTrace();
}

return null;

}

Expand Down

0 comments on commit 607c53f

Please sign in to comment.