FileTypeDetectionAlgorithm { public static @Nullable FileType detectDataFileType(@Nonnull File fileName) throws IOException { Preconditions.checkNotNull(fileName); if (fileName.isDirectory()) { for (File f : fileName.listFiles()) { if (f.isFile() && f.getName().matches("_FUNC[0-9]{3}.DAT")) return FileType.WATERS_RAW; } return null; } 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 FileType.THERMO_RAW; } if (fileHeader.startsWith(CDF_HEADER)) { return FileType.NETCDF; } if (fileHeader.contains(MZML_HEADER)) return FileType.MZML; if (fileHeader.contains(MZDATA_HEADER)) return FileType.MZDATA; if (fileHeader.contains(MZXML_HEADER)) return FileType.MZXML; if (fileHeader.contains(MZTAB_HEADER)) return FileType.MZTAB; if (fileHeader.startsWith(MZDB_HEADER) && fileHeader.contains(MZDB_HEADER2)) return FileType.MZDB; return null; }  static @Nullable FileType detectDataFileType(@Nonnull File fileName);  }
@Test public void testMzData() throws MSDKException, IOException { File fileName = new File(TEST_DATA_PATH + "test.mzData"); FileType fileType = FileTypeDetectionAlgorithm.detectDataFileType(fileName); Assert.assertEquals(FileType.MZDATA, fileType); }
@Test public void testThermoRaw() throws MSDKException, IOException { File fileName = new File(TEST_DATA_PATH + "RP240K_01.raw"); FileType fileType = FileTypeDetectionAlgorithm.detectDataFileType(fileName); Assert.assertEquals(FileType.THERMO_RAW, fileType); }
@Test public void testWatersRaw() throws MSDKException, IOException { File fileName = new File(TEST_DATA_PATH + "20150813-63.raw"); FileType fileType = FileTypeDetectionAlgorithm.detectDataFileType(fileName); Assert.assertEquals(FileType.WATERS_RAW, fileType); }
@Test public void testMzTAB() throws MSDKException, IOException { File fileName = new File(TEST_DATA_PATH + "lipidomics-HFD-LD-study-PL-DG-SM.mzTab"); FileType fileType = FileTypeDetectionAlgorithm.detectDataFileType(fileName); Assert.assertEquals(FileType.MZTAB, fileType); }
@Test public void testMzDB() throws MSDKException, IOException { File fileName = new File(TEST_DATA_PATH + "OVEMB150205_12.raw.0.9.8_truncated.mzDB"); FileType fileType = FileTypeDetectionAlgorithm.detectDataFileType(fileName); Assert.assertEquals(FileType.MZDB, fileType); }
@Test public void testNetCDF() throws MSDKException, IOException { File fileName = new File(TEST_DATA_PATH + "wt15.CDF"); FileType fileType = FileTypeDetectionAlgorithm.detectDataFileType(fileName); Assert.assertEquals(FileType.NETCDF, fileType); }
@Test public void testMzXML() throws MSDKException, IOException { File fileName = new File(TEST_DATA_PATH + "A1-0_A2.mzXML"); FileType fileType = FileTypeDetectionAlgorithm.detectDataFileType(fileName); Assert.assertEquals(FileType.MZXML, fileType); }
@Test public void testMzML() throws MSDKException, IOException { File fileName = new File(TEST_DATA_PATH + "RawCentriodCidWithMsLevelInRefParamGroup.mzML"); FileType fileType = FileTypeDetectionAlgorithm.detectDataFileType(fileName); Assert.assertEquals(FileType.MZML, fileType); }