Changeset 248


Ignore:
Timestamp:
Mar 28, 2007, 6:29:17 PM (15 years ago)
Author:
Johan Enell
Message:

major changes to basefile
some methods are deprecated and will be removed

Location:
trunk/se/lu/onk/BaseFile/src/basefile
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/se/lu/onk/BaseFile/src/basefile/BASEFileAssaySection.java

    r247 r248  
    2828import java.util.List;
    2929
    30 public class BASEFileAssaySection extends BASEFileSection
     30public class BASEFileAssaySection extends BASEFileDataSection
    3131{
    3232  private final ArrayList<String> data;
    33 
    34   private final int height;
    35  
    36   private final int width;
    3733 
    3834  private final HashMap<Integer, Integer> idIndex = new HashMap<Integer, Integer>();
     
    4036  public BASEFileAssaySection(BASEFileSection bfs) throws BASEFileException
    4137  {
    42     if (!bfs.getType().equals("assays"))
     38    super(bfs);
     39    if (!bfs.isType("assays"))
    4340    {
    4441      throw new BASEFileException("Section must be of type 'assays' to create an assay section.");
     
    4946    this.width = width;
    5047    this.data = new ArrayList<String>(height*width);
    51   }
    52  
    53   public final int getHeight()
    54   {
    55     return height;
    56   }
    57 
    58   public final int getWidth()
    59   {
    60     return width;
    6148  }
    6249 
     
    9582    return this.findIntOpt("count");
    9683  }
     84
     85  @Override
     86  public int getDataLineLength()
     87  {
     88    return getColumns().size();
     89  }
    9790 
    9891}
  • trunk/se/lu/onk/BaseFile/src/basefile/BASEFileReader.java

    r247 r248  
    6060   * @throws FileNotFoundException If the infile cant be found
    6161   */
     62  @Deprecated
    6263  public BASEFileReader(File in) throws FileNotFoundException
    6364  {
     
    136137   */
    137138  public <R, S> BASEFileSpotSection<R, S> readSpotSection()
    138     throws BadFormatException, IOException
     139    throws BASEFileException, IOException
    139140  {
    140141    while (section != null && !section.isType("spots"))
     
    150151   * @param <S>
    151152   * @return
    152    * @throws BadFormatException
    153153   * @throws IOException
    154154   * @throws BadSectionException
     
    157157    throws BASEFileException, IOException
    158158  {
     159    section = readSection(false);
    159160    while (section != null && !section.isType("assays"))
    160161    {
    161162      section = readSection(false);
     163    }
     164    if (section == null)
     165    {
     166      throw new BASEFileException("Couldn't find assays section in file "+this.inFile.getAbsolutePath());
    162167    }
    163168    return new BASEFileAssaySection(section);
  • trunk/se/lu/onk/BaseFile/src/basefile/BASEFileSection.java

    r185 r248  
    2323import java.util.ArrayList;
    2424import java.util.Arrays;
     25import java.util.Collections;
    2526import java.util.HashMap;
    2627import java.util.List;
     28import java.util.Map;
    2729
    2830/**
     
    5658
    5759  /**
     60   * The type of this section.
     61   */
     62  private String type;
     63
     64  private long pointer;
     65
     66  /**
    5867   * Creates a new BASEFileSection.
    5968   */
     
    6170  {
    6271    startLine = -1;
     72    pointer = -1;
    6373    dataStartLine = -1;
    64     setHeader("section", "");
     74    type = "";
     75  }
     76
     77  public BASEFileSection(BASEFileSection bfs) throws BASEFileException
     78  {
     79    if (bfs == null)
     80    {
     81      throw new BASEFileException("Can't initiate an assay section with a null section.");
     82    }
     83    startLine = bfs.getStartLine();
     84    pointer = bfs.getStartPointer();
     85    dataStartLine = bfs.getDataStartLine();
     86    type = bfs.getType();
     87    setHeaders(bfs.getHeaders());
    6588  }
    6689
     
    224247  public final String setHeader(Object key, Object value)
    225248  {
    226     return headers.put(key.toString(), value.toString());
     249    String ret = "";
     250    if ("section".equals(key))
     251    {
     252      ret = this.getType();
     253      this.setType(value.toString());
     254    }
     255    else
     256    {
     257      ret = headers.put(key.toString(), value.toString());
     258    }
     259    return ret;
    227260  }
    228261
     
    281314    return this.headers.get(key.toString());
    282315  }
     316 
     317  public final Map<String, String> getHeaders()
     318  {
     319    return Collections.unmodifiableMap(this.headers);
     320  }
    283321
    284322  public final String removeHeader(Object key)
     
    291329  }
    292330
    293   final boolean setHeaders(HashMap<String, String> headers)
     331  final boolean setHeaders(Map<String, String> headers)
    294332  {
    295333    if (headers == null)
     
    300338    for (String key : headers.keySet())
    301339    {
    302       this.headers.put(key, headers.get(key));
     340      this.setHeader(key, headers.get(key));
    303341    }
    304342    return true;
    305343  }
     344 
     345  public int getColIndex(String header, String col) throws BASEFileException
     346  {
     347    List<String> l = this.findFieldList(header);
     348    if (l == null) throw new BASEFileException("Can't find header "+header);
     349    int index = l.indexOf(col);
     350    if (index == -1) throw new BASEFileException("Can't find column "+col+" in header "+header);
     351    return index;
     352  }
    306353
    307354  /**
     
    312359  public final String getType()
    313360  {
    314     return headers.get("section");
    315   }
    316 
    317   /**
    318    * @param string
    319    * @return
     361    return type;
     362  }
     363
     364  /**
     365   * Checks the type of this section.
     366   *
     367   * @param string the type to test
     368   * @return true if type matches string
    320369   */
    321370  public final boolean isType(String string)
     
    323372    return getType().equals(string);
    324373  }
     374 
     375  /**
     376   * Sets the type of this section.
     377   *
     378   * @return the new type
     379   */
     380  public final void setType(String type)
     381  {
     382    this.type = type;
     383  }
    325384
    326385  public final int getDataStartLine()
     
    329388  }
    330389
     390  @Deprecated
    331391  public final void setDataStartLine(int dataStartLine)
    332392  {
     
    334394  }
    335395
     396  public final void setStartPointer(long pointer)
     397  {
     398    this.pointer = pointer;
     399  }
     400
    336401  public final int getStartLine()
    337402  {
    338403    return startLine;
    339404  }
     405 
     406  public final long getStartPointer()
     407  {
     408    return pointer;
     409  }
    340410
    341411  public final void setStartLine(int startLine)
     
    347417  {
    348418    this.headers.clear();
    349     setHeader("section", "");
    350419    startLine = -1;
    351420    dataStartLine = -1;
     
    359428    for (String key : headers.keySet())
    360429    {
    361       if (!key.equals("section"))
    362       {
    363         ret += key + "\t" + headers.get(key) + "\n";
    364       }
     430      ret += key + "\t" + headers.get(key) + "\n";
    365431    }
    366432    ret += "%";
  • trunk/se/lu/onk/BaseFile/src/basefile/BASEFileSpotSection.java

    r247 r248  
    2626import java.util.List;
    2727
    28 public class BASEFileSpotSection<R, S> extends BASEFileSection
     28public class BASEFileSpotSection<R, S> extends BASEFileDataSection
    2929{
    3030
    31   private final int height;
    32   private final int width;
    3331  private final ArrayList<S> spotData;
    3432  private final ArrayList<R> reporterData;
    35  
    36   public BASEFileSpotSection(BASEFileSection bfs)
     33   
     34  public BASEFileSpotSection(BASEFileSection bfs) throws BASEFileException
    3735  {
    38     this.height = bfs.findIntOpt("count");
    39     this.width = bfs.findStringOpts("assayFields").length * bfs.findStringOpts("assays").length + bfs.findStringOpts("columns").length - 1;
     36    super(bfs);
     37    if (!bfs.isType("spots"))
     38    {
     39      throw new BASEFileException("Section must be of type 'spots' to create an assay section.");
     40    }
     41    this.setHeight(bfs.findIntOpt("count"));
     42    this.setWidth(bfs.findStringOpts("assayFields").length * bfs.findStringOpts("assays").length + bfs.findStringOpts("columns").length - 1);
    4043    this.spotData = new ArrayList<S>(height*width);
    4144    this.reporterData = new ArrayList<R>(height);
     
    4548  public BASEFileSpotSection(int height, int width)
    4649  {
     50    this.setType("spots");
    4751    this.height = height;
    4852    this.width = width;
     
    5458  public final void setDataMatrix(int height, int width)
    5559  {
    56    
     60    this.height = height;
     61    this.width = width;
     62    this.spotData.ensureCapacity(height*width);
     63    this.reporterData.ensureCapacity(height);
    5764  }
    5865 
     
    97104    i = reporterData.indexOf(reporter) + i;
    98105    return spotData.set(i, spot);
    99    
    100106  }
    101107 
     
    111117  }
    112118
     119  public int getColumnsColIndex(String col) throws BASEFileException
     120  {
     121    return this.getColIndex("columns", col);
     122  }
     123
    113124  public List<Integer> getAssaysHeader()
    114125  {
     
    116127  }
    117128
     129  public int getAssaysColIndex(String col) throws BASEFileException
     130  {
     131    return this.getColIndex("assays", col);
     132  }
     133
    118134  public List<String> getAssayFieldsHeader()
    119135  {
    120136    return this.findFieldList("assayFields");
     137  }
     138
     139  public int getAssayFieldsColIndex(String col) throws BASEFileException
     140  {
     141    return this.getColIndex("assayFields", col);
    121142  }
    122143 
     
    128149  public boolean isValid()
    129150  {
    130     if (!isType("spots")) return false;
    131151    if (getColumnHeader() == null) return false;
    132152    if (getAssayFieldsHeader() == null) return false;
    133153    if (getAssaysHeader() == null) return false;
    134154    return true;
    135   }
    136 
    137   public final int getHeight()
    138   {
    139     return height;
    140   }
    141 
    142   public final int getWidth()
    143   {
    144     return width;
    145155  }
    146156
     
    174184    return reporterData.size();
    175185  }
     186
     187  @Override
     188  public int getDataLineLength()
     189  {
     190    int length = this.getColumnHeader().size() -1;
     191    length += this.getAssayFieldsHeader().size() * this.getAssaysHeader().size();
     192    return length;
     193  }
    176194}
Note: See TracChangeset for help on using the changeset viewer.