AffyChipTypeExtractor { public static String extract( InputStream is ) { String chipType = null; try (DataInputStream str = new DataInputStream( is )) { BufferedReader reader; int magic = readByte( str ); switch ( magic ) { case 64: { int version = readIntLittleEndian( str ); if ( version != 4 ) { throw new IllegalStateException( "Affymetrix CEL format not recognized: " + version ); } AffyChipTypeExtractor.log.debug( readShort( str ) ); AffyChipTypeExtractor.log.debug( readShort( str ) ); AffyChipTypeExtractor.log.debug( readIntLittleEndian( str ) ); int headerLen = readShort( str ); if ( headerLen == 0 ) { headerLen = 800; } AffyChipTypeExtractor.log.debug( headerLen ); StringBuilder buf = new StringBuilder(); for ( int i = 0; i < headerLen; i++ ) { buf.append( new String( new byte[] { str.readByte() }, "US-ASCII" ) ); } String[] headerLines = StringUtils.split( buf.toString(), "\n" ); for ( String string : headerLines ) { if ( string.startsWith( "DatHeader" ) ) { chipType = parseStandardFormat( string ); break; } } break; } case 59: { int version = readUnsignedByte( str ); if ( version != 1 ) { throw new IllegalStateException( "Affymetrix CEL format not recognized: " + version ); } @SuppressWarnings("unused") int numDataGroups = readIntBigEndian( str ); @SuppressWarnings("unused") int filePosOfFirstGroup = readIntBigEndian( str ); chipType = parseGenericCCHeader( str ); if ( chipType == null ) { chipType = parseGenericCCHeader( str ); } break; } default: reader = new BufferedReader( new InputStreamReader( is ) ); String line; int count = 0; while ( ( line = reader.readLine() ) != null ) { if ( line.startsWith( "DatHeader" ) ) { chipType = parseStandardFormat( line ); } if ( chipType != null || ++count > 100 ) { reader.close(); break; } } break; } return chipType; } catch ( IOException e ) { throw new RuntimeException( e ); } }  static Map<BioAssay, String> getChipTypes( ExpressionExperiment ee, Collection<LocalFile> files ); static String extract( InputStream is );  }
@Test public void testExtractInputStreamGCOS() throws Exception { InputStream is = new GZIPInputStream( this.getClass().getResourceAsStream( "/data/loader/expression/geo/GSM506974.part.CEL.gz" ) ); AffyChipTypeExtractor extractor = new AffyChipTypeExtractor(); String actual = extractor.extract( is ); String expected = "Rat230_2"; assertEquals( expected, actual ); }
@Test public void testExtractInputStreamV3() throws Exception { InputStream is = new GZIPInputStream( this.getClass().getResourceAsStream( "/data/loader/expression/geo/GSM3448.part.CEL.txt.gz" ) ); AffyChipTypeExtractor extractor = new AffyChipTypeExtractor(); String actual = extractor.extract( is ); String expected = "RG_U34A"; assertEquals( expected, actual ); }
@Test public void testExtractInputStreamV4() throws Exception { InputStream is = new GZIPInputStream( this.getClass().getResourceAsStream( "/data/loader/expression/geo/GSM306831.part.CEL.gz" ) ); AffyChipTypeExtractor extractor = new AffyChipTypeExtractor(); String actual = extractor.extract( is ); String expected = "Zebrafish"; assertEquals( expected, actual ); }
@Test public void testExtractInputStreamVx() throws Exception { InputStream is = new GZIPInputStream( this.getClass().getResourceAsStream( "/data/loader/expression/geo/GSM239803.CEL.gz" ) ); AffyChipTypeExtractor extractor = new AffyChipTypeExtractor(); String actual = extractor.extract( is ); String expected = "RN_U34"; assertEquals( expected, actual ); }