ISA-tools / BioInvIndex

The web application, model, database persistence, services package and web services for the BII. Led by Eamonn Maguire (Uni. of Oxford) & Philippe Rocca-Serra (Uni. of Oxford).
http://www.isa-tools.org
16 stars 13 forks source link

How to... #51

Closed pconesa closed 12 years ago

pconesa commented 12 years ago

Hi!

Having a sample name (String), and a study object......how can I find what factors values has this sample associated?

Cheers!

eamonnmag commented 12 years ago

Hey Pablo,

I'll need to write some sample code to do this since although I know the process one has to go through to get it, I don't know all of the intricacies off hand. I think we'd just need to get the material associated with the sample and then get the properties attached to it.

Eamonn

eamonnmag commented 12 years ago

From @pconesa

// Loop through the assay results
  for (AssayResult ar:study.getAssayResults()){
   
   //Get sample name
   String sampleName = ar.getAssays().iterator().next().getMaterial().getName();
   
   // If we do not have this sample name in the map
   if (sampleName != null && !sampleNameToUnitName.containsKey(sampleName)){

    String dimensionName="";
    
    // For each factor value in Data item
    for (FactorValue fv:ar.getData().getFactorValues()){
     
     
     String value="";
     
     // Add the new value
     if (!(fv.getUnit() == null)){
      value = fv.getValue() + " " + fv.getUnit().getValue();
     } else {
      value = fv.getValue();
     }
     
     // Concatenate the factor value
     dimensionName = dimensionName.concat(" - " + value);
     
    }
   
    // Clean first "-"
    dimensionName = dimensionName.replaceFirst(" - ", "");

    // Add an item to the samples map
    sampleNameToUnitName.put(sampleName, dimensionName);
    
    
    // If we don't have this dimension..
    if (!dimensions.containsKey(dimensionName)) {
     // Add a dimension
     ParallelCoordinatesDimension dim = new ParallelCoordinatesDimension("d" + dimensions.size()+1, dimensionName, "");
     dimensions.put(dimensionName, dim);
    }
    
    
   } // If sampleName
  } // For each assayr