AgilentScanDateExtractor extends BaseScanDateExtractor { @Override public Date extract( InputStream is ) { BufferedReader reader = null; try { reader = new BufferedReader( new InputStreamReader( is ) ); String line = reader.readLine(); if ( line.startsWith( "ATF" ) ) { return this.extractGenePix( reader ); } else if ( line.startsWith( "TYPE" ) ) { line = reader.readLine(); if ( line.startsWith( "FEPARAMS" ) ) { int dateField = -1; String[] fields = StringUtils.split( line, '\t' ); for ( int i = 0; i < fields.length; i++ ) { if ( fields[i].equalsIgnoreCase( "Scan_date" ) ) { dateField = i; } } if ( dateField < 0 ) { throw new IllegalStateException( "Could not recognize the scan_date field" ); } line = reader.readLine(); if ( !line.startsWith( "DATA" ) ) { throw new IllegalStateException( "Could not understand Agilent scanner format" ); } fields = StringUtils.split( line, '\t' ); String date = fields[dateField]; Date d; DateFormat f = new SimpleDateFormat( "MM-dd-yyyy hh:mm:ss" ); f.setLenient( true ); d = f.parse( date ); return d; } } else { throw new UnsupportedRawdataFileFormatException( "Unknown agilent array file format." ); } } catch ( IOException | ParseException e ) { throw new RuntimeException( e ); } finally { try { if ( reader != null ) reader.close(); } catch ( IOException e ) { AgilentScanDateExtractor.log.error( "Failed to close open file handle: " + e.getMessage() ); } } return null; }  @Override Date extract( InputStream is );  }
@Test public void testExtractGPR() throws Exception { try (InputStream is = this.getClass() .getResourceAsStream( "/data/loader/expression/rawdata/GSM393974.gpr.txt" )) { AgilentScanDateExtractor extractor = new AgilentScanDateExtractor(); Date actual = extractor.extract( is ); DateFormat formatter = new SimpleDateFormat( "yyyy/MM/dd HH:mm:ss" ); Date expected = formatter.parse( "2005/11/09 11:36:27" ); assertEquals( expected, actual ); } }
@Test public void testExtractAgilent() throws Exception { try (InputStream is = this.getClass() .getResourceAsStream( "/data/loader/expression/rawdata/GSM361301.agilent.txt" )) { AgilentScanDateExtractor extractor = new AgilentScanDateExtractor(); Date actual = extractor.extract( is ); DateFormat formatter = new SimpleDateFormat( "MM-dd-yyyy HH:mm:ss" ); Date expected = formatter.parse( "10-18-2005 13:02:36" ); assertEquals( expected, actual ); } }
@Test public void testExtractAgilent2() throws Exception { try (InputStream is = this.getClass() .getResourceAsStream( "/data/loader/expression/rawdata/GSM1662306.agilent2.txt" )) { AgilentScanDateExtractor extractor = new AgilentScanDateExtractor(); Date actual = extractor.extract( is ); DateFormat formatter = new SimpleDateFormat( "MM-dd-yyyy HH:mm:ss" ); Date expected = formatter.parse( "02-27-2014 09:32:52" ); assertEquals( expected, actual ); } }