affyfusion-109/src/affymetrix/calvin/parsers/DataGroupHeaderReader.java

Code
Comments
Other
Rev Date Author Line
11 13 Sep 07 nicklas 1 /////////////////////////////////////////////////////////////////
11 13 Sep 07 nicklas 2 //
11 13 Sep 07 nicklas 3 // Copyright (C) 2005 Affymetrix, Inc.
11 13 Sep 07 nicklas 4 //
11 13 Sep 07 nicklas 5 // This library is free software; you can redistribute it and/or modify
11 13 Sep 07 nicklas 6 // it under the terms of the GNU Lesser General Public License as published
11 13 Sep 07 nicklas 7 // by the Free Software Foundation; either version 2.1 of the License,
11 13 Sep 07 nicklas 8 // or (at your option) any later version.
11 13 Sep 07 nicklas 9 //
11 13 Sep 07 nicklas 10 // This library is distributed in the hope that it will be useful, but
11 13 Sep 07 nicklas 11 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 13 Sep 07 nicklas 12 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11 13 Sep 07 nicklas 13 // for more details.
11 13 Sep 07 nicklas 14 //
11 13 Sep 07 nicklas 15 // You should have received a copy of the GNU Lesser General Public License
11 13 Sep 07 nicklas 16 // along with this library; if not, write to the Free Software Foundation, Inc.,
11 13 Sep 07 nicklas 17 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
11 13 Sep 07 nicklas 18 //
11 13 Sep 07 nicklas 19 /////////////////////////////////////////////////////////////////
11 13 Sep 07 nicklas 20
11 13 Sep 07 nicklas 21 package affymetrix.calvin.parsers;
11 13 Sep 07 nicklas 22
11 13 Sep 07 nicklas 23 import java.io.*;
11 13 Sep 07 nicklas 24 import affymetrix.calvin.data.*;
11 13 Sep 07 nicklas 25
11 13 Sep 07 nicklas 26 /** This class reads the all the DataGroupHeader information from a file into a FileHeader object.*/
11 13 Sep 07 nicklas 27 public class DataGroupHeaderReader {
11 13 Sep 07 nicklas 28     
11 13 Sep 07 nicklas 29     /** Creates a new instance of DataGroupHeaderReader */
11 13 Sep 07 nicklas 30     public DataGroupHeaderReader() {
11 13 Sep 07 nicklas 31     }
11 13 Sep 07 nicklas 32     
11 13 Sep 07 nicklas 33     /** Reads all the DataGroupHeaders in a file and the minimum information for each DataSetHeader in every DataGroup.
11 13 Sep 07 nicklas 34      *  @param fileStream Open fstream positioned at the start of the first DataGroupHeader in the file.
11 13 Sep 07 nicklas 35      *  @param fh FileHeader object to fill.
11 13 Sep 07 nicklas 36      *  @param dataGroupCnt Number of DataGroup in the file.
11 13 Sep 07 nicklas 37      */
11 13 Sep 07 nicklas 38     public void readAllMinimumInfo(FileInputStream fileStream, FileHeader fh, int dataGroupCnt) {
11 13 Sep 07 nicklas 39   // Get the first data group offset
11 13 Sep 07 nicklas 40   int nextDataGroupFilePos = fh.getFirstDataGroupFilePos();
11 13 Sep 07 nicklas 41
11 13 Sep 07 nicklas 42   for (int i = 0; i < dataGroupCnt; ++i)
11 13 Sep 07 nicklas 43   {
11 13 Sep 07 nicklas 44     // Read the DataGroupHeader
11 13 Sep 07 nicklas 45     DataGroupHeader dch = new DataGroupHeader();
11 13 Sep 07 nicklas 46
11 13 Sep 07 nicklas 47     // Move to the indicated position in the file
11 13 Sep 07 nicklas 48                 try
11 13 Sep 07 nicklas 49                 {
11 13 Sep 07 nicklas 50                     fileStream.getChannel().position(nextDataGroupFilePos);
11 13 Sep 07 nicklas 51                 }
11 13 Sep 07 nicklas 52                 catch (Throwable t)
11 13 Sep 07 nicklas 53                 {
11 13 Sep 07 nicklas 54                 }
11 13 Sep 07 nicklas 55     nextDataGroupFilePos = readMinimumInfo(fileStream, dch);
11 13 Sep 07 nicklas 56     fh.addDataGroupHdr(dch);
11 13 Sep 07 nicklas 57   }
11 13 Sep 07 nicklas 58     }
11 13 Sep 07 nicklas 59
11 13 Sep 07 nicklas 60     /** Reads all the DataGroupHeaders in a file and all information for each DataSetHeader in every DataGroup.
11 13 Sep 07 nicklas 61      *  @param fileStream Open fstream positioned at the start of the first DataGroupHeader in the file.
11 13 Sep 07 nicklas 62      *  @param fh FileHeader object to fill.
11 13 Sep 07 nicklas 63      *  @param dataGroupCnt Number of DataGroup in the file.
11 13 Sep 07 nicklas 64      */
11 13 Sep 07 nicklas 65     public void readAll(FileInputStream fileStream, FileHeader fh, int dataGroupCnt) {
11 13 Sep 07 nicklas 66   // Get the first data group offset
11 13 Sep 07 nicklas 67   int nextDataGroupFilePos = fh.getFirstDataGroupFilePos();
11 13 Sep 07 nicklas 68
11 13 Sep 07 nicklas 69   for (int i = 0; i < dataGroupCnt; ++i)
11 13 Sep 07 nicklas 70   {
11 13 Sep 07 nicklas 71     // Read the DataGroupHeader
11 13 Sep 07 nicklas 72     DataGroupHeader dch = new DataGroupHeader();
11 13 Sep 07 nicklas 73
11 13 Sep 07 nicklas 74     // Move to the indicated position in the file
11 13 Sep 07 nicklas 75                 try
11 13 Sep 07 nicklas 76                 {
11 13 Sep 07 nicklas 77                     fileStream.getChannel().position(nextDataGroupFilePos);
11 13 Sep 07 nicklas 78                 }
11 13 Sep 07 nicklas 79                 catch (Throwable t)
11 13 Sep 07 nicklas 80                 {
11 13 Sep 07 nicklas 81                 }
11 13 Sep 07 nicklas 82     nextDataGroupFilePos = read(fileStream, dch);
11 13 Sep 07 nicklas 83     fh.addDataGroupHdr(dch);
11 13 Sep 07 nicklas 84   }
11 13 Sep 07 nicklas 85     }
11 13 Sep 07 nicklas 86
11 13 Sep 07 nicklas 87     /** Reads the DataGroupHeader and the minimum information for all DataSetHeaders associated with this DataGroupHeader
11 13 Sep 07 nicklas 88      *  from the file.
11 13 Sep 07 nicklas 89      *  @param fileStream Open fstream positioned at the start of the first DataGroupHeader in the file.
11 13 Sep 07 nicklas 90      *  @param dch DataGroupHeader object to fill.
11 13 Sep 07 nicklas 91      *  @return The file position of the next data group
11 13 Sep 07 nicklas 92      */
11 13 Sep 07 nicklas 93     public int readMinimumInfo(FileInputStream fileStream, DataGroupHeader dch) {
11 13 Sep 07 nicklas 94   int dataSetCnt = readHeader(fileStream, dch);
11 13 Sep 07 nicklas 95
11 13 Sep 07 nicklas 96   // Read the DataSets
11 13 Sep 07 nicklas 97   DataSetHeaderReader dphReader = new DataSetHeaderReader();
11 13 Sep 07 nicklas 98   dphReader.readAllMinimumInfo(fileStream, dch, dataSetCnt);
11 13 Sep 07 nicklas 99   return dch.getNextGroupPos();
11 13 Sep 07 nicklas 100     }
11 13 Sep 07 nicklas 101
11 13 Sep 07 nicklas 102     /** Read the DataGroupHeader and all DataSetHeaders associated with this DataGroupHeader
11 13 Sep 07 nicklas 103      *  from the file.
11 13 Sep 07 nicklas 104      *  @param fileStream Open fstream positioned at the start of the first DataGroupHeader in the file.
11 13 Sep 07 nicklas 105      *  @param dch DataGroupHeader object to fill.
11 13 Sep 07 nicklas 106      *  @return The file position of the next data group
11 13 Sep 07 nicklas 107      */
11 13 Sep 07 nicklas 108     public int read(FileInputStream fileStream, DataGroupHeader dch) {
11 13 Sep 07 nicklas 109   int dataSetCnt = readHeader(fileStream, dch);
11 13 Sep 07 nicklas 110
11 13 Sep 07 nicklas 111   // Read the DataSets
11 13 Sep 07 nicklas 112   DataSetHeaderReader dphReader = new DataSetHeaderReader();
11 13 Sep 07 nicklas 113   dphReader.readAll(fileStream, dch, dataSetCnt);
11 13 Sep 07 nicklas 114   return dch.getNextGroupPos();
11 13 Sep 07 nicklas 115     }
11 13 Sep 07 nicklas 116
11 13 Sep 07 nicklas 117     /** Reads the DataGroupHeader from the file.  Doesn't read all DataSetHeader information.
11 13 Sep 07 nicklas 118      *  @param fileStream Open fstream positioned at the start of a DataGroupHeader in the file.
11 13 Sep 07 nicklas 119      *  @param dch DataGroupHeader object to fill with the header information.
11 13 Sep 07 nicklas 120      *  @return The number of DataSetHeaders associated with the current DataGroupHeader.
11 13 Sep 07 nicklas 121      */
11 13 Sep 07 nicklas 122     public int readHeader(FileInputStream fileStream, DataGroupHeader dch) {
11 13 Sep 07 nicklas 123   readNextDataGroupFilePos(fileStream, dch);
11 13 Sep 07 nicklas 124   readFirstDataSetFilePos(fileStream, dch);
11 13 Sep 07 nicklas 125   int dataSetCnt = readDataSetCnt(fileStream, dch);
11 13 Sep 07 nicklas 126   readDataGroupName(fileStream, dch);
11 13 Sep 07 nicklas 127   return dataSetCnt;
11 13 Sep 07 nicklas 128     }
11 13 Sep 07 nicklas 129
11 13 Sep 07 nicklas 130     /** reads the file position of the next DataGroup.
11 13 Sep 07 nicklas 131      *  @param fileStream Open fstream positioned at the start of the file position of a DataGroupHeader.
11 13 Sep 07 nicklas 132      *  @param dch DataGroupHeader object in which to write the file position.
11 13 Sep 07 nicklas 133      */
11 13 Sep 07 nicklas 134     protected void readNextDataGroupFilePos(FileInputStream fileStream, DataGroupHeader dch) {
11 13 Sep 07 nicklas 135   dch.setNextGroupPos(FileInput.ReadUInt32(fileStream));
11 13 Sep 07 nicklas 136     }
11 13 Sep 07 nicklas 137
11 13 Sep 07 nicklas 138     /** Reads the file position of the first DataSet associated with the current DataGroup.
11 13 Sep 07 nicklas 139      *  @param fileStream Open fstream positioned at the start of the file position of the first DataSetHeader in the DataGroup.
11 13 Sep 07 nicklas 140      *  @param dch DataGroupHeader object to which to add the DataSetHeader information.
11 13 Sep 07 nicklas 141      */
11 13 Sep 07 nicklas 142     protected void readFirstDataSetFilePos(FileInputStream fileStream, DataGroupHeader dch) {
11 13 Sep 07 nicklas 143   dch.setDataSetPos(FileInput.ReadUInt32(fileStream));
11 13 Sep 07 nicklas 144     }
11 13 Sep 07 nicklas 145
11 13 Sep 07 nicklas 146     /** Reads the number of DataSets associated with the current DataGroup.
11 13 Sep 07 nicklas 147      *  @param fileStream Open fstream positioned at the start of the DataGroupHeader count.
11 13 Sep 07 nicklas 148      *  @param dch DataGroupHeader object in which to add the DataSet count.
11 13 Sep 07 nicklas 149      */
11 13 Sep 07 nicklas 150     protected int readDataSetCnt(FileInputStream fileStream, DataGroupHeader dch) {
11 13 Sep 07 nicklas 151   return FileInput.ReadUInt32(fileStream);
11 13 Sep 07 nicklas 152         
11 13 Sep 07 nicklas 153     }
11 13 Sep 07 nicklas 154
11 13 Sep 07 nicklas 155     /** Reads the number of DataGroup name.
11 13 Sep 07 nicklas 156      *  @param fileStream Open fstream positioned at the start of the DataGroupHeader name.
11 13 Sep 07 nicklas 157      *  @param dch DataGroupHeader object to which to add the DataGroup name.
11 13 Sep 07 nicklas 158      */
11 13 Sep 07 nicklas 159     protected void readDataGroupName(FileInputStream fileStream, DataGroupHeader dch) {
11 13 Sep 07 nicklas 160   dch.setName(FileInput.ReadString16(fileStream));
11 13 Sep 07 nicklas 161         
11 13 Sep 07 nicklas 162     }
11 13 Sep 07 nicklas 163
11 13 Sep 07 nicklas 164 }