Changeset 681


Ignore:
Timestamp:
Apr 29, 2008, 3:19:44 PM (13 years ago)
Author:
Jari Häkkinen
Message:

Addresses #110. Single sample Whole Genome BeadChips? detection P-value calculation implemented.

Location:
plugins/base2/net.sf.basedb.illumina/trunk
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • plugins/base2/net.sf.basedb.illumina/trunk/META-INF/base-plugins.xml

    r678 r681  
    2323    <hasconfigurations>yes</hasconfigurations>
    2424  </pluginclass>
     25  <pluginclass classname="net.sf.basedb.illumina.plugins.DetectionPValue">
     26    <minbaseversion>2.6</minbaseversion>
     27    <hasconfigurations/>
     28  </pluginclass>
    2529  <pluginclass classname="net.sf.basedb.illumina.plugins.SnpIntensityCalculator">
    2630    <minbaseversion>2.6</minbaseversion>
  • plugins/base2/net.sf.basedb.illumina/trunk/src/net/sf/basedb/illumina/install/Install.java

    r646 r681  
    2929import net.sf.basedb.core.DataFileType;
    3030import net.sf.basedb.core.DbControl;
     31import net.sf.basedb.core.ExtraValueType;
    3132import net.sf.basedb.core.FileType;
    3233import net.sf.basedb.core.Formula;
     
    5051import net.sf.basedb.core.StringParameterType;
    5152import net.sf.basedb.core.SystemItems;
     53import net.sf.basedb.core.Type;
    5254import net.sf.basedb.core.plugin.About;
    5355import net.sf.basedb.core.plugin.AboutImpl;
     
    9799  <li>Optionally, hardwares, softwares and other items, that in some way are associated with
    98100    one or more of the variants, will be created next.
     101
     102  <li>Create <code>IlluminaDetectionPValue</code> ExtraValueType
     103    required for the 'Illumina detection P-value calculation' plug-in.
    99104
    100105  <li>Create formulas for the 3 SNP channels:
     
    135140  private PluginParameter<String> installExp2VariantParameter;
    136141 
     142  private PluginParameter<String> installDetectionPValueParameter;
     143
    137144  private PluginParameter<String> installScannerParameter;
    138145  private PluginParameter<String> scannerNameParameter;
     
    151158    "Illumina platform variants",
    152159    "Variants available to be installed",
     160    null
     161  );
     162  private static final PluginParameter<String> extraValueTypeSection = new PluginParameter<String>
     163  (
     164    "extraValueTypeSection",
     165    "ExtraValueTypes",
     166    "Extra values required by some Illumina plug-ins",
    153167    null
    154168  );
     
    211225      permissions.add(new Permissions(Item.PLATFORMVARIANT, null, EnumSet.of(Permission.CREATE)));
    212226      permissions.add(new Permissions(Item.DATAFILETYPE, null, EnumSet.of(Permission.CREATE)));
     227      permissions.add(new Permissions(Item.EXTRAVALUETYPE, null, EnumSet.of(Permission.CREATE)));
    213228    }
    214229    return permissions;
     
    239254        boolean installExp2 = YES_OPTION.equals(job.getValue("installExp2"));
    240255        boolean installSnp = YES_OPTION.equals(job.getValue("installSnp"));
     256        boolean installDetectionPValue =
     257          YES_OPTION.equals(job.getValue("installDetectionPValue"));
    241258        boolean installScanner = YES_OPTION.equals(job.getValue("installScanner"));
    242259        boolean installSoftware = YES_OPTION.equals(job.getValue("installSoftware"));
    243         boolean ignoreExisingItems = SKIP_OPTION.equals(job.getValue("alreadyInstalledError"));
     260        boolean ignoreExistingItems = SKIP_OPTION.equals(job.getValue("alreadyInstalledError"));
    244261
    245262        Set<Integer> expressionTypes = new HashSet<Integer>();
     
    247264        if (installExp2) expressionTypes.add(2);
    248265
    249         installIlluminaItems(dc, installSnp, expressionTypes, ignoreExisingItems, progress);
     266        installIlluminaItems(dc, installSnp, expressionTypes, ignoreExistingItems, progress);
     267        if (installDetectionPValue)
     268        {
     269          createExtraValueType(dc,"IlluminaDetectionPValue",Type.FLOAT,"ExtraVallueType needed for Illumina detection P-value calculations",ignoreExistingItems);
     270        }
    250271        if (installScanner)
    251272        {
     
    360381      storeValue(job, request, installExp2VariantParameter);
    361382      storeValue(job, request, installSnpVariantParameter);
    362      
     383
     384      storeValue(job, request, installDetectionPValueParameter);
     385
    363386      storeValue(job, request, installScannerParameter);
    364387      storeValue(job, request, scannerNameParameter);
     
    552575      );
    553576     
     577      installDetectionPValueParameter = new PluginParameter<String>
     578      (
     579        "installDetectionPValue",
     580        "Create IlluminaDetectionPValue",
     581        "Select '" + YES_OPTION + "' to create an IlluminaDetectionPValue ExtraValueType.",
     582        installOptionType
     583      );
     584     
    554585      installScannerParameter = new PluginParameter<String>
    555586      (
     
    657688      parameters.add(installSnpVariantParameter);
    658689     
     690      parameters.add(extraValueTypeSection);
     691      parameters.add(installDetectionPValueParameter);
     692
    659693      parameters.add(hardwareSection);
    660694      parameters.add(installScannerParameter);
     
    760794  }
    761795 
     796
     797  public ExtraValueType createExtraValueType(DbControl dc, String externalId, Type type,
     798                                             String description, boolean ignoreExistingItem)
     799  {
     800    ExtraValueType extraValueType = null;
     801    try
     802    {
     803      extraValueType = extraValueType.getByExternalId(dc, externalId);
     804      if (!ignoreExistingItem)
     805      {
     806        throw new ItemAlreadyExistsException(extraValueType.getExternalId());
     807      }
     808    }
     809    catch (ItemNotFoundException infex)
     810    {
     811      extraValueType = ExtraValueType.getNew(dc, externalId, type);
     812      extraValueType.setName(externalId);
     813      extraValueType.setDescription(description);
     814      dc.saveItem(extraValueType);
     815    }
     816    return extraValueType;
     817  }
     818
     819
    762820  public Platform createPlatform(DbControl dc, String externalId, String name, boolean ignoreExistingItem)
    763821  {
  • plugins/base2/net.sf.basedb.illumina/trunk/src/net/sf/basedb/illumina/plugins/DetectionPValue.java

    r669 r681  
    3232import net.sf.basedb.core.DynamicSpotQuery;
    3333import net.sf.basedb.core.Experiment;
    34 import net.sf.basedb.core.InvalidDataException;
     34import net.sf.basedb.core.ExtraValueType;
    3535import net.sf.basedb.core.Item;
    3636import net.sf.basedb.core.Job;
     
    3939import net.sf.basedb.core.ProgressReporter;
    4040import net.sf.basedb.core.RequestInformation;
    41 import net.sf.basedb.core.SpotBatcher;
     41import net.sf.basedb.core.SpotExtraValueBatcher;
    4242import net.sf.basedb.core.StringParameterType;
    4343import net.sf.basedb.core.Transformation;
     
    5555import net.sf.basedb.core.query.Expression;
    5656import net.sf.basedb.core.query.Expressions;
     57import net.sf.basedb.core.query.JoinType;
    5758import net.sf.basedb.core.query.Orders;
    5859import net.sf.basedb.core.query.Restriction;
     
    8081  This plug-in is part of the Illumina plug-in package.
    8182
    82   This plug-in implements background correction methods for Illumina
     83  This plug-in implements detection P-value calculations for Illumina
    8384  expression data.
    8485
    8586  @author jari
    8687 */
    87 public class BackgroundCorrection
     88public class DetectionPValue
    8889  extends AbstractAnalysisPlugin
    8990  implements InteractivePlugin, SignalTarget
     
    9192
    9293  private static final About about = new AboutImpl
    93     ( "Illumina expression background correction",
    94       "This plug-in implements background correction methods for " +
     94    ( "Illumina detection P-value calculation",
     95      "This plug-in implements detection P-value calculations for " +
    9596      "Illumina expression data. Please send feedback to " +
    9697      Illumina.EMAIL,
     
    107108  private RequestInformation configureJob;
    108109
    109   private static final String defaultChildName="Background corrected";
     110  private static final String defaultChildName="Detection P-value";
    110111
    111112  private static final Set<Permissions> permissions = new HashSet<Permissions>();
    112113
    113114  /**
    114      List of background correction methods.
     115     List of selectable 1-channel array types. DASL (2-channel) type
     116     will be automatically select when support for 2-channel Illumina
     117     is added, or a corresponding list for 2-channel types must be
     118     added.
    115119
    116120     Note, changing the string in the list will affect the behaviour
    117121     of the plug-in and most certaintly unexpected results will be
    118      generated. As an example, changing 'Illumina BeadStudio median'
     122     generated. As an example, changing 'Whole Genome BeadChip'
    119123     will break the median method.
    120124  */
    121125  private static final
    122   PluginParameter<String> methodParameter = new PluginParameter<String>
     126  PluginParameter<String> arrayType1Parameter = new PluginParameter<String>
    123127    ( "method",
    124128      "Correction method",
    125129      "These methods are implemented:\n\n" +
    126       "Illumina BeadStudio inspired mean 'negative control'\n" +
    127       "Illumina BeadStudio inspired median 'negative control'",
    128       new StringParameterType(255, "Illumina BeadStudio median", true, 1, 0, 0,
     130      "Detection P-value calculation for Illumine Whole Genome BeadChips\n" +
     131      "Detection P-value calculation for Illumine Focused Arrays",
     132      new StringParameterType(255, "Whole Genome BeadChip", true, 1, 0, 0,
    129133                              Arrays.asList(
    130                                 new String[] { "Illumina BeadStudio mean" ,
    131                                                "Illumina BeadStudio median" }
     134                                new String[] { "Whole Genome BeadChip" ,
     135                                               "Focused Array (not yet implemented)" }
    132136                                )
    133137        )
     
    167171
    168172        // Plug-in options
    169         storeValue(job, request, methodParameter);
     173        storeValue(job, request, arrayType1Parameter);
    170174
    171175        // Estimate execution time
     
    222226
    223227        // background correction method
    224         parameters.add(methodParameter);
     228        parameters.add(arrayType1Parameter);
    225229 
    226230        configureJob = new RequestInformation(
    227           Request.COMMAND_CONFIGURE_JOB, "Illumina background correction",
    228           "Select background correction method", parameters );
     231          Request.COMMAND_CONFIGURE_JOB, "Detection P-value calculation",
     232          "Select array type", parameters );
    229233      }
    230234      finally
     
    245249    {
    246250      permissions.add(new Permissions(Item.EXPERIMENT, null,
     251                                      EnumSet.of(Permission.USE)));
     252      permissions.add(new Permissions(Item.EXTRAVALUETYPE, null,
    247253                                      EnumSet.of(Permission.USE)));
    248254      permissions.add(new Permissions(Item.JOB, null,
     
    305311
    306312
     313  float pvalue(float[] sortedArray, float intensity)
     314  {
     315    int arraysize=sortedArray.length;
     316    int i=arraysize-1;
     317    while (i>-1 && sortedArray[i]>intensity) --i;
     318    return (float)(1.0-(1.0+i)/arraysize);
     319  }
     320
     321
    307322  // From the Plugin interface
    308323  @Override
     
    310325  {
    311326    return false;
    312   }
    313 
    314 
    315   private float mean(DynamicResultIterator dri, int index) throws SQLException
    316   {
    317     float mean=0;
    318     int nofSpots=0;
    319     while (dri.hasNext())
    320     {
    321       mean+=dri.next().getFloat(index);
    322       ++nofSpots;
    323     }
    324     dri.close();
    325     return (nofSpots!=0 ? mean/nofSpots : 0);
    326   }
    327 
    328 
    329   private float median(DynamicResultIterator dri, int index) throws SQLException
    330   {
    331     long count=dri.getTotalCount();
    332     if (count == -1)
    333       throw new InvalidDataException("Failed to get query result count.");
    334     boolean even= (count%2 == 0);
    335     count=count/2;
    336 
    337     int nofSpots=0;
    338     SqlResult r = null;
    339     while (nofSpots++<count) r=dri.next();
    340 
    341     // odd number, next number is the median
    342     if (!even) return dri.next().getFloat(index);
    343     // even number, median averag of this and next number
    344     return (r.getFloat(index) + dri.next().getFloat(index))/2;
    345327  }
    346328
     
    354336    try
    355337    {
    356       String method = (String)job.getValue(methodParameter.getName());
     338      String arrayType = (String)job.getValue(arrayType1Parameter.getName());
    357339      if (progress != null)
    358         progress.display(0, ("Preparing background correction using method " +
    359                              method));
     340        progress.display(0, ("Preparing detection P-value calculation for " +
     341                             arrayType));
    360342      dc = sc.newDbControl();
    361343      BioAssaySet source = getSourceBioAssaySet(dc);
     
    372354
    373355      // Create the child bioassay set
    374       BioAssaySet child = t.newProduct(null, "new", true);
     356      BioAssaySet child = t.newProduct(null, null, true);
    375357      dc.saveItem(child);
    376358
    377       // Create restriction: negative control beads only (background
    378       // spots)
     359      // Create restriction: negative control beads only (background spots)
    379360      Expression control = Dynamic.reporter("controlGroupName");
    380361      Restriction controlRestriction = Restrictions.and(
     
    388369        );
    389370
    390       // Create query to retrieve spot data. We use a parameter to
     371      // Prepare query to retrieve spot data. We use a parameter to
    391372      // restrict the query to return data for one bioassay at a time
    392373      DynamicSpotQuery query = source.getSpotData();
     374      query.joinRawData(JoinType.INNER);
     375      query.selectPermanent(Dynamic.select(VirtualColumn.COLUMN));
    393376      query.selectPermanent(Dynamic.select(VirtualColumn.POSITION));
    394       Expression ch1=Dynamic.column(VirtualColumn.channel(1));
    395       query.selectPermanent(Selects.expression(ch1,null));
     377      Expression ch1=Dynamic.rawData("mean");
     378      query.selectPermanent(Selects.expression(ch1,"ch1"));
    396379      query.restrictPermanent(bioAssayRestriction);
    397       query.restrict(controlRestriction);
    398       if (method.equals("Illumina BeadStudio median"))
    399       {
    400         query.order(Orders.asc(ch1));
    401         query.setReturnTotalCount(true);
    402       }
     380      query.setReturnTotalCount(true);
    403381
    404382      try
    405383      {
    406         if (progress != null) progress.display(0, "Calculating background");
     384        // Batcher for inserting child data
     385        SpotExtraValueBatcher<Float> batcher=
     386          child.getSpotExtraValueBatcher(Float.class,
     387                                         ExtraValueType.getByExternalId(dc,"IlluminaDetectionPValue"),
     388                                         thisJob);
     389
    407390        // Caluclate one bioassay at a time
    408391        List<BioAssay> assays = source.getBioAssays().list(dc);
    409         float[] backgroundCh1=new float[assays.size()];
     392        int nofAssays = assays.size();
    410393        int assayNo=0;
    411         for (BioAssay assay : assays)
    412         {
    413           checkInterrupted();
    414           // calculate background correction for this bioassay
    415           short bioassayColumn = assay.getDataCubeColumnNo();
    416           query.setParameter("bioAssayColumn", (int)bioassayColumn, Type.INT);
    417           DynamicResultIterator dri = query.iterate(dc);
    418           int ch1Index = dri.getIndex(VirtualColumn.channel(1).getName());
    419           backgroundCh1[assayNo]=
    420             ( method.equals("Illumina BeadStudio median") ?
    421               median(dri,ch1Index) : mean(dri,ch1Index) );
    422           ++assayNo;
    423         }
    424         query.reset();
    425         int nofAssays=assayNo;
    426 
    427         // Batcher for inserting child data
    428         SpotBatcher batcher = child.getSpotBatcher();
    429         assayNo=0;
    430394        for (BioAssay assay : assays)
    431395        {
     
    437401          }
    438402
     403          // extract negative control intensities for this bioassay
    439404          short bioassayColumn = assay.getDataCubeColumnNo();
    440405          query.setParameter("bioAssayColumn", (int)bioassayColumn, Type.INT);
     406          query.restrict(controlRestriction);
     407          query.order(Orders.asc(ch1));
    441408          DynamicResultIterator dri = query.iterate(dc);
    442           int positionIndex = dri.getIndex(VirtualColumn.POSITION.getName());
    443409          int ch1Index = dri.getIndex(VirtualColumn.channel(1).getName());
    444           float background=backgroundCh1[assayNo++];
     410          float[] sortedControlIntensity=new float[(int)dri.getTotalCount()];
     411          int beadNo=0;
    445412          while (dri.hasNext())
    446413          {
    447414            SqlResult result = dri.next();
    448             batcher.insert(bioassayColumn,result.getInt(positionIndex),
    449                            result.getFloat(ch1Index)-background);
     415            sortedControlIntensity[beadNo++]=result.getFloat(ch1Index);
    450416          }
    451417          dri.close();
     418
     419          checkInterrupted();
     420
     421          // calculate detection P-value for all beadsets
     422          query.reset();  // remove controlRestriction and ordering
     423          query.setParameter("bioAssayColumn", (int)bioassayColumn, Type.INT);
     424          dri = query.iterate(dc);
     425          int positionIndex = dri.getIndex(VirtualColumn.POSITION.getName());
     426          int columnIndex = dri.getIndex(VirtualColumn.COLUMN.getName());
     427          ch1Index = dri.getIndex(VirtualColumn.channel(1).getName());
     428          while (dri.hasNext())
     429          {
     430            SqlResult result = dri.next();
     431            batcher.insert(result.getShort(columnIndex), result.getInt(positionIndex),
     432                           pvalue(sortedControlIntensity,result.getFloat(ch1Index)));
     433          }
     434          dri.close();
     435
     436          ++assayNo;
     437          batcher.flush();
    452438        }
    453         batcher.flush();
    454439        batcher.close();
    455440      }
     
    462447      child.setDescription(childDescription);
    463448      dc.commit();
    464       response.setDone("Background correction done with method '"+method+"'\n");
     449      response.setDone("Detection P-value calculation done with method '" + arrayType + "'\n");
    465450    }
    466451    catch (Throwable ex)
Note: See TracChangeset for help on using the changeset viewer.