Changeset 3554


Ignore:
Timestamp:
Jul 12, 2007, 4:28:12 PM (16 years ago)
Author:
Johan Enell
Message:

Fixes #671, References #590

Test for BioAssaySetExporter? added which highlighted some bug in the BASEfile export. Additional tests for the BASEfile should be added and for the other formats.

Location:
trunk/src
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/core/net/sf/basedb/plugins/Base1PluginExecuter.java

    r3545 r3554  
    11541154    ffp.setHeaderRegexp(Pattern.compile("(.*?)\\t(.*)"));
    11551155    ffp.setDataHeaderRegexp(Pattern.compile("%"));
     1156    ffp.setDataFooterRegexp(Pattern.compile("^$"));
    11561157    ffp.setDataSplitterRegexp(Pattern.compile("\\t"));
     1158    ffp.setUseNullIfEmpty(false);
    11571159
    11581160    ffp.setInputStream(stream, Config.getCharset());
  • trunk/src/plugins/core/net/sf/basedb/plugins/BioAssaySetExporter.java

    r3545 r3554  
    312312    }
    313313    out.println("columns\tid\tname" + annotationString);
    314     out.println("annotationColumns" + annotationString);
     314    out.println("annotationColumns" + (annotationString.length() == 0 ? "\t" : annotationString));
    315315    out.println("%");
    316316    for (BioAssay ba : bas.getBioAssays().list(dc))
     
    339339        out.println("section\t"+parameters.get("section"));
    340340        keys = keys.subList(1, keys.size());
     341      }
     342      else
     343      {
     344        out.println("section\tsettings");
    341345      }
    342346      if (keys.contains("section"))
     
    451455    }
    452456    out.println();
    453     out.println("count\t" + bas.getNumReporters()); //TODO: count number of column/position
     457    out.println("count\t" + query.count(dc)); //TODO: count number of column/position
    454458    out.println("%");
    455459   
     
    481485    Integer prevPos = null;
    482486    HashMap<Short, String> spotValues = new HashMap<Short, String>();
    483     String reporter = null;
    484487    while (iterator.hasNext())
    485488    {
     
    487490      Integer currentPos = r.getInt(posIndex);
    488491     
    489       if (prevPos != null && !currentPos.equals(prevPos))
    490       {
     492      if (!currentPos.equals(prevPos))
     493      {
     494        // Print spot fields
     495        if (!spotValues.isEmpty())
     496        {
     497          String separator = "";
     498          for (Short col : columnNo)
     499          {
     500            String spot = spotValues.get(col);
     501            if (spot != null)
     502            {
     503              out.print(separator);
     504              out.print(spot);
     505            }
     506            else
     507            {
     508              out.print(tabs);
     509            }
     510            separator = "\t";
     511          }
     512          out.println();
     513          spotValues.clear();
     514        }
     515       
    491516        //Print reporter fields
    492         out.print(reporter);
    493        
    494         //Print spot fields
    495         String separator = "";
    496         for (Short col : columnNo)
    497         {
    498           String spot = spotValues.get(col);
    499           if (spot != null)
    500           {
    501             out.print(separator);
    502             out.print(spot);
    503           }
    504           else
    505           {
    506             out.print(tabs);
    507           }
    508           separator = "\t";
    509         }
    510         out.println();
    511        
    512         reporter = null;
    513         spotValues = new HashMap<Short, String>();
    514       }
    515 
    516       if (reporter == null)
    517       {
    518         reporter = "";
    519517        for (int i = 0; i < reporterIndex.size(); ++i)
    520518        {
    521519          String field = r.getString(reporterIndex.get(i));
    522           reporter += field == null ? "" : field;
    523           reporter += "\t";
     520          out.print((field == null ? "" : field) + "\t");
    524521        }
    525522      }
     
    533530      }
    534531      spotValues.put(r.getShort(colIndex), spot);
    535       prevPos = r.getInt(posIndex);
     532      prevPos = currentPos;
     533    }
     534   
     535    // Print the last spot fields
     536    if (!spotValues.isEmpty())
     537    {
     538      String separator = "";
     539      for (Short col : columnNo)
     540      {
     541        String spot = spotValues.get(col);
     542        if (spot != null)
     543        {
     544          out.print(separator);
     545          out.print(spot);
     546        }
     547        else
     548        {
     549          out.print(tabs);
     550        }
     551        separator = "\t";
     552      }
     553      out.println();
     554      spotValues.clear();
    536555    }
    537556  }
     
    842861    List<QueryItem> items = new ArrayList<QueryItem>();
    843862    items.add(new QueryItem("rep.id", "Reporter (internal id)", "reporter", "rep('id')"));
     863    items.add(new QueryItem("rep.position", "Position", "position", "pos()"));
    844864    items.add(new QueryItem("rep.name", "Reporter Name", "name", "rep('name')"));
    845865    items.add(new QueryItem("rep.externalId", "Reporter ID", "externalId", "rep('externalId')"));
     
    859879  {
    860880    List<QueryItem> items = new ArrayList<QueryItem>();
    861     items.add(new QueryItem("position", "Position", "position", "pos()"));
    862881    int channels = bas.getRawDataType().getChannels();
    863882    for (int channel = 1; channel <= channels; ++channel)
  • trunk/src/test/TestFlatFileParser.java

    r2992 r3554  
    88import net.sf.basedb.util.parser.FlatFileParser;
    99import net.sf.basedb.util.parser.Mapper;
     10import net.sf.basedb.util.parser.FlatFileParser.Line;
    1011
    1112/*
     
    197198    }
    198199  }
     200
     201  public static void testHeaderLine(Line line, String name, String value) throws Exception
     202  {
     203    if (!line.type().equals(FlatFileParser.LineType.HEADER))
     204      throw new Exception("Line is no header: "+line.toString());
     205    if (!line.name().equals(name))
     206      throw new Exception("Cant find name '"+name+"' in line '"+line.line()+"'");
     207    if (!line.value().equals(value))
     208      throw new Exception("Cant find value '"+value+"' in line '"+line.line()+"'");
     209  }
     210
     211  public static void testLine(Line line, String name) throws Exception
     212  {
     213    if (!line.line().equals(name))
     214      throw new Exception("Line '"+line.line()+"' doesnt match '"+name+"'");
     215  }
     216
     217  public static void testSection(Line line, String name) throws Exception
     218  {
     219    if (!line.type().equals(FlatFileParser.LineType.SECTION))
     220      throw new Exception("Line is no section: "+line.toString());
     221    if (!line.name().equals(name))
     222      throw new Exception("Cant find sectionname '"+name+"' in line '"+line.line()+"'");
     223  }
    199224}
Note: See TracChangeset for help on using the changeset viewer.