Changeset 3444


Ignore:
Timestamp:
Oct 14, 2009, 2:58:09 PM (14 years ago)
Author:
Fredrik Levander
Message:

Merging trunk into branch

Location:
branches/testing
Files:
14 edited
7 copied

Legend:

Unmodified
Added
Removed
  • branches/testing/api/core/src/org/proteios/core/Application.java

    r3381 r3444  
    6565   * The minor version.
    6666   */
    67   private static final int MINOR_VERSION = 9;
     67  private static final int MINOR_VERSION = 10;
    6868  /**
    6969   * The micro version.
  • branches/testing/api/waf/src/se/lu/thep/waf/dom/html/Img.java

    r1916 r3444  
    4040    return this;
    4141  }
     42
     43
     44  public Img setUsemap(String usemap)
     45  {
     46    this.setAttribute(new Attribute("usemap", usemap));
     47    return this;
     48  }
    4249}
  • branches/testing/client/servlet/src/org/proteios/Service.java

    r3419 r3444  
    4949import org.proteios.core.Directory;
    5050import org.proteios.core.File;
     51import org.proteios.core.Identifiable;
    5152import org.proteios.core.ItemAlreadyExistsException;
    5253import org.proteios.core.ItemFactory;
     
    5455import org.proteios.core.ItemQuery;
    5556import org.proteios.core.ItemResultIterator;
     57import org.proteios.core.Nameable;
    5658import org.proteios.core.Operator;
    5759import org.proteios.core.Project;
     
    8991
    9092/**
    91  * Web service that enables clients to fetch and upload data in a tab separated
     93 * Web service that enables clients to read and write data through a tab separated
    9294 * format. Exposing items to the service is done in your web.xml. NOTE!!! This
    9395 * service is still under heavy development. Use this feature only in
     
    128130  {
    129131   RequestData data = startRequest(request, response);
    130 
    131     // Define
    132     Removable itemToRemove;
    133 
    134     // Use
    135     if (data.item != null)
    136 
    137     {
    138       if (data.item instanceof Removable)
    139       {
    140         itemToRemove = (Removable) data.item;
    141         itemToRemove.setRemoved(true);
    142         data.dc.commit();
    143       }
    144       else
    145       {
    146         response.setStatus(HttpServletResponse.SC_FORBIDDEN);
    147       }
    148     }
    149     else
    150     {
    151       response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    152     }
    153 
     132  RequestHandler remover = new RemoveRequestHandler();
     133  remover.handle(data);
    154134    endRequest(data);
    155135  }
     
    317297 private void applyWhereToQuery(ItemQuery<?> query, List<AttributeDefinition> show, HttpServletRequest request)
    318298 {
    319   String paramName,filterString,opStr, valueStr;
     299  String subParamName, paramName,filterString,opStr, valueStr, name, key;
    320300    Filter filter;
    321301  Operator operator;
     
    324304  Class<?> type;
    325305  typeUtil = new TypeUtil();
     306  Enumeration en;
     307  Map<String,Boolean> whereParams;
     308
     309  whereParams = new HashMap<String,Boolean>();
     310
     311  /*
     312   Find all where* parameters
     313  */
     314  en = request.getParameterNames();
     315  while (en.hasMoreElements())
     316  {
     317   name = (String) en.nextElement();
     318   if(name.startsWith("where"))
     319   {
     320     whereParams.put(name, new Boolean(true));
     321   }
     322  }
    326323
    327324    for (AttributeDefinition ad : show)
     
    329326      paramName = "where" + ad.getKey();
    330327      // The filterString is what the user entered
    331       filterString = request.getParameter(paramName);
    332       log.debug(paramName + "=" + filterString);
    333       if (filterString != null && filterString.length() > 1)
    334       {
    335         // Parse the string for operator
    336         filter = null;
    337         opStr = filterString.substring(0, 2);
    338         valueStr = filterString.substring(2);
    339         if (operatorMap.get(opStr) == null)
    340         {
    341           opStr = filterString.substring(0, 1);
    342           valueStr = filterString.substring(1);
    343         }
    344         if (operatorMap.get(opStr) != null)
    345         {
    346           if (valueStr != null && valueStr.length() > 0)
    347           {
    348             // The filter string must be at least
    349             // one character long Now convert the string
    350             // to the proper type
    351             type = ad.getAttributeType();
    352             Object value = null;
    353             try
    354             {
    355               value = typeUtil.parse(type, valueStr);
    356               log
    357                 .debug("Value " + valueStr + " is of type " + type + " and typeUtil returned " + value);
    358             }
    359             catch (Exception e)
    360             {
    361               log.debug(e.getMessage(), e);
    362             }
    363             if (value != null)
    364             {
    365               operator = operatorMap.get(opStr);
    366               coreType = typeUtil.getType(type);
    367               if (operator.equals(EQ) && typeUtil
    368                 .isString(type))
    369               {
    370                 // LIKE matching
    371                 if (((String) value).contains("%"))
    372                   operator = LIKE;
    373               }
    374               filter = new Filter(operator, value,
    375                 coreType);
    376               applyFilter(query, filter, ad);
    377             }
    378           }
    379         }
    380       }
    381     }
     328      filter = createFilter(request, ad.getAttributeType(), paramName);
     329   if(filter != null)
     330   {
     331        applyFilter(query, filter, ad.getKey());
     332    }
     333    }
     334 }
     335
     336 private Filter createFilter(HttpServletRequest request, Class<?> type, String paramName)
     337 {
     338
     339  Object value = null;
     340  Operator operator;
     341    Type coreType;
     342    TypeUtil typeUtil;
     343  String filterString, opStr, valueStr;
     344  boolean createFilter;
     345  createFilter = false;
     346  opStr = null;
     347  valueStr = null;
     348 
     349  filterString = request.getParameter(paramName);
     350    log.debug(paramName + "=" + filterString);
     351    if (filterString != null && filterString.length() > 1)
     352    {
     353      // Parse the string for operator
     354      opStr = filterString.substring(0, 2);
     355      valueStr = filterString.substring(2);
     356      if (operatorMap.get(opStr) == null)
     357      {
     358        opStr = filterString.substring(0, 1);
     359        valueStr = filterString.substring(1);
     360      }
     361      if (operatorMap.get(opStr) != null && valueStr != null && valueStr.length() > 0)
     362      {
     363    createFilter = true;
     364      }
     365    }
     366  if(createFilter)
     367  {
     368   typeUtil = new TypeUtil();
     369   try
     370    {
     371      value = typeUtil.parse(type, valueStr);
     372      log.debug("Value " + valueStr + " is of type " + type + " and typeUtil returned " + value);
     373     }
     374     catch (Exception e)
     375     {
     376      log.debug(e.getMessage(), e);
     377     }
     378     if (value != null)
     379     {
     380      operator = operatorMap.get(opStr);
     381      coreType = typeUtil.getType(type);
     382      if (operator.equals(EQ) && typeUtil.isString(type))
     383      {
     384        // LIKE matching
     385        if (((String) value).contains("%"))
     386        {
     387      operator = LIKE;
     388     }
     389      }
     390      return new Filter(operator, value,  coreType);
     391   }
     392  }
     393   return null;
    382394 }
    383395
     
    642654    logHeaders(request);
    643655    logParameters(request);
    644     data =  new RequestData(request);
     656    data =  new RequestData(request, response);
    645657    parsePath(data);
    646658    data.sc = authenticate(request);
     
    823835
    824836  private void applyFilter(ItemQuery<?> query, Filter filter,
    825       AttributeDefinition attributeDefinition)
    826   {
    827     String key = attributeDefinition.getKey();
     837      String key)
     838  {
    828839    String property = key.substring(0, 1).toLowerCase() + key.substring(1);
    829840    Operator operator = filter.getOperator();
     
    987998
    988999
    989   /**
    990    * @author gregory
    991    */
    992   private class RequestData
    993   {
    994     Class<BasicItem> itemClass = null;
    995    BasicItem<?> item = null;
    996     int itemId = 0;
    997     int projectContextId = 0;
    998     String context = null;
    999     String resource = null;
    1000     Boolean isValidResource = false;
    1001    User user = null;
    1002    SessionControl sc = null;
    1003    DbControl dc = null;
    1004    ItemFactory factory = null;
    1005    ClassDescriptor cd = null;
    1006    Project activeProject = null;
    1007   Directory home = null;
    1008     HttpServletRequest request;
    1009     BufferedReader reader = null;
    1010     InputStream stream = null;
    1011     InputStreamReader streamReader = null;
    1012 
    1013     public RequestData(HttpServletRequest request)
    1014     {
    1015       this.request = request;
    1016    }
    1017 
    1018 
    1019 
    1020     @Override
    1021     public String toString()
    1022     {
    1023       StringBuilder sb = new StringBuilder();
    1024       append(sb, "itemClass", itemClass);
    1025       append(sb, "itemId", itemId);
    1026       append(sb, "projectContextId", projectContextId);
    1027       append(sb, "resource", resource);
    1028       append(sb, "context", context);
    1029       return sb.toString();
    1030     }
    1031 
    1032 
    1033     private void append(StringBuilder sb, String name, Object value)
    1034     {
    1035       sb.append(name);
    1036       sb.append("=");
    1037       sb.append(value == null ? null : value.toString());
    1038       sb.append(",");
    1039     }
    1040 
    1041   }
     1000
    10421001}
  • branches/testing/client/servlet/src/org/proteios/action/file/InspectActiveSpectrumFile.java

    r3428 r3444  
    2727import org.proteios.action.ProteiosAction;
    2828import org.proteios.action.peakList.PlotFileSpectrum;
     29import org.proteios.action.read.ScrollTo;
    2930import org.proteios.core.DbControl;
    3031import org.proteios.core.File;
     
    3233import org.proteios.gui.ColumnContainer;
    3334import org.proteios.gui.Image;
     35import org.proteios.gui.ImageMap;
     36import org.proteios.gui.ImageMapArea;
    3437import org.proteios.gui.RowContainer;
     38import org.proteios.gui.Scroller;
    3539import org.proteios.gui.Title;
    3640import org.proteios.gui.Toolbar;
     
    3842import org.proteios.gui.form.Form;
    3943import org.proteios.gui.form.FormFactory;
     44import org.proteios.gui.form.TextField;
    4045import org.proteios.gui.layout.RowLayout;
    4146import org.proteios.gui.table.Cell;
     
    7782    "keepOriginalSpectrum", false);
    7883
     84  private int maxResults = 20;
     85  private int itemsFrom = 0;
     86  private boolean pageSelectedFromScroller = false;
     87
     88
     89  /**
     90   * Get the max number of results to show in list.
     91   *
     92   * @return int The max number of results to show in list.
     93   */
     94  public int getMaxResults()
     95  {
     96    return this.maxResults;
     97  }
     98
     99
     100  /**
     101   * Set the max number of results to show in list.
     102   *
     103   * @param maxResults int The value to set for the max number of results to show in list.
     104   */
     105  public void setMaxResults(int maxResults)
     106  {
     107    this.maxResults = maxResults;
     108  }
     109
     110
     111  /**
     112   * Get the item number to start from in the list.
     113   *
     114   * @return int The item number to start from in the list.
     115   */
     116  public int getItemsFrom()
     117  {
     118    return this.itemsFrom;
     119  }
     120
     121
     122  /**
     123   * Set the item number to start from in the list.
     124   *
     125   * @param itemsFrom int The value to set for the item number to start from in the list.
     126   */
     127  public void setItemsFrom(int itemsFrom)
     128  {
     129    this.itemsFrom = itemsFrom;
     130  }
     131
     132
     133  /**
     134   * Get flag indicating that page is selected from scroller.
     135   *
     136   * @return boolean The flag indicating that page is selected from scroller.
     137   */
     138  public boolean isPageSelectedFromScroller()
     139  {
     140    return this.pageSelectedFromScroller;
     141  }
     142
     143
     144  /**
     145   * Set flag indicating that page is selected from scroller.
     146   *
     147   * @param pageSelectedFromScroller boolean The value to set for flag indicating that page is selected from scroller.
     148   */
     149  public void setPageSelectedFromScroller(boolean pageSelectedFromScroller)
     150  {
     151    this.pageSelectedFromScroller = pageSelectedFromScroller;
     152  }
     153
     154
    79155  @Override
    80156  protected void runMe()
     
    90166    // Check alternative input
    91167    if (files == null)
    92     {
    93      
     168    {     
    94169      Integer fileIdFromSessionAttribute = getSessionAttribute(VSPECTRUMFILEID);
    95170      log.debug("fileIdFromSessionAttribute = " + fileIdFromSessionAttribute );
     
    165240     */
    166241    Table peakListTable = new Table("peaklists");
     242    // Add tool-bar to table to make GUIConverter set
     243    // form id for action in hidden field.
     244    Toolbar peakListTableToolbar = new Toolbar();
     245    peakListTable.setToolbar(peakListTableToolbar);
    167246    if (spectrumIdReader != null)
    168247    {
     
    179258    {
    180259      log.debug("spectrumIds.size() = " + spectrumIds.size());
    181       for (int i = 0; i < spectrumIds.size(); i++)
     260      // Fetch scroller page selected
     261      restoreScrollerState();
     262      log.debug("getItemsFrom() = " + getItemsFrom() + " isPageSelectedFromScroller() = " + isPageSelectedFromScroller());
     263      if (!isPageSelectedFromScroller())
     264      {
     265        // Adjust scroller page to include selected spectrum
     266        if (spectrumId != null && !spectrumId.equals(""))
     267        {
     268          // find start of scroller page including selected spectrum
     269          Integer currentIndex = fetchStringListItemIndex(spectrumId, spectrumIds);
     270          log.debug("currentIndex = " + currentIndex);
     271          if (currentIndex != null && currentIndex >= 0)
     272          {
     273            int pageNo = currentIndex/getMaxResults();
     274            int tempStart = pageNo*getMaxResults();
     275            log.debug("currentIndex = " + currentIndex + " pageNo = " + pageNo + " tempStart = " + tempStart);
     276            // Set start index for displayed list
     277            setItemsFrom(tempStart);
     278          }
     279        }
     280      }
     281      // Add scroller
     282      int count = spectrumIds.size();
     283      if (count > getMaxResults())
     284      {
     285        Scroller scroller = new Scroller();
     286        scroller.setFrom(getItemsFrom());
     287        scroller.setMax(getMaxResults());
     288        scroller.setTotalCount(count);
     289        scroller.setScrollActionId(getActionFactory().getId(ScrollTo.class));
     290        scroller.setTableConfActionId(getActionFactory().getId(InspectActiveSpectrumFile.class));
     291        scroller.setDisplayActionId(getActionFactory().getId(InspectActiveSpectrumFile.class));
     292        //scroller.put(FormFactory.VCLASSNAME, itemClass.getName());
     293        log.debug("scroller ScrollActionId = \"" + getActionFactory().getId(ScrollTo.class) + "\"");
     294        log.debug("scroller TableConfActionId = \"" + getActionFactory().getId(InspectActiveSpectrumFile.class) + "\"");
     295        log.debug("scroller.getDisplayActionId() = \"" + scroller.getDisplayActionId() + "\"");
     296        // Add scroller to table
     297        peakListTable.setScroller(scroller);
     298      }
     299      // Add scroller data
     300      log.debug("getItemsFrom() = " + getItemsFrom());
     301      log.debug("getMaxResults() = " + getMaxResults());
     302      int scrollFrom = getItemsFrom();
     303      int scrollMaxResults = getMaxResults();
     304      TextField<Integer> scrollFromField = new TextField<Integer>(
     305        Scroller.VFROM);
     306      TextField<Integer> scrollMaxResultsField = new TextField<Integer>(
     307        Scroller.VMAXRESULT);
     308      scrollFromField.setValue(scrollFrom);
     309      scrollMaxResultsField.setValue(scrollMaxResults);
     310      peakListTable.add(scrollFromField);
     311      peakListTable.add(scrollMaxResultsField);
     312      //
     313      // Add spectrum id field
     314      TextField<String> spectrumIdField = new TextField<String>(
     315          PlotFileSpectrum.VSPECTRUMID);
     316      spectrumIdField.setHidden(true);
     317      spectrumIdField.setValue(spectrumId);
     318      peakListTable.add(spectrumIdField);
     319      //
     320      // Add mass cut-off low string field
     321      TextField<String> massCutOffLowStrField = new TextField<String>(
     322          PlotFileSpectrum.VMASSCUTOFFLOWSTR);
     323      massCutOffLowStrField.setHidden(true);
     324      massCutOffLowStrField.setValue(massCutoffLowStr);
     325      peakListTable.add(massCutOffLowStrField);
     326      //
     327      // Add mass cut-off high string field
     328      TextField<String> massCutOffHighStrField = new TextField<String>(
     329          PlotFileSpectrum.VMASSCUTOFFHIGHSTR);
     330      massCutOffHighStrField.setHidden(true);
     331      massCutOffHighStrField.setValue(massCutoffHighStr);
     332      peakListTable.add(massCutOffHighStrField);
     333      //
     334      // Add keep original spectrum flag field
     335      TextField<Boolean> keepOriginalSpectrumField = new TextField<Boolean>(
     336          VKEEPORIGINALSPECTRUM);
     337      keepOriginalSpectrumField.setHidden(true);
     338      keepOriginalSpectrumField.setValue(keepOriginalSpectrum);
     339      peakListTable.add(keepOriginalSpectrumField);
     340      //
     341      // Create spectrum list to display
     342      int itemStart = getItemsFrom();
     343      int itemStop = getItemsFrom() + getMaxResults();
     344      for (int i = itemStart; (i < spectrumIds.size() && i < itemStop); i++)
    182345      {
    183346        //log.debug("spectrumIds.get(" + i + ") = \"" + spectrumIds.get(i) + "\"");
     
    206369     * Spectrum plot
    207370     */
     371    PlotFileSpectrum plotFileSpectrum = new PlotFileSpectrum();
     372    ImageMap imageMap;
    208373    Image plotOriginal = null;
    209374    if (keepOriginalSpectrum)
     
    217382      plotOriginal.setHeight(PlotFileSpectrum.HEIGHT);
    218383      plotOriginal.setWidth(PlotFileSpectrum.WIDTH);
     384      // Add mass annotation image map
     385      imageMap = plotFileSpectrum.fetchMassPeakAnnotationToolTips(dc, fileId, spectrumId,
     386        (String) null, (String) null);
     387      plotOriginal.setImageMap(imageMap);
     388      log.debug("plotOriginal imagMap = " + imageMap);
    219389    }
    220390    Image plot = new Image();
     
    228398    plot.setHeight(PlotFileSpectrum.HEIGHT);
    229399    plot.setWidth(PlotFileSpectrum.WIDTH);
     400    // Add mass annotation image map
     401    imageMap = plotFileSpectrum.fetchMassPeakAnnotationToolTips(dc, fileId, spectrumId,
     402      massCutoffLowStr, massCutoffHighStr);
     403    plot.setImageMap(imageMap);
     404    log.debug("plot imagMap = " + imageMap);
    230405    /***********************************************************************
    231406     * Spectrum iteration buttons
     
    367542    //
    368543    setLayout(layout);
    369   }
    370 
    371 
    372   /**
    373    * Fetch previous list item from string  list.
     544    log.debug("End");
     545  }
     546
     547
     548  /**
     549   * Fetch index for item from from string  list.
    374550   *
    375551   * @param currentItem String The current item.
    376552   * @param inList List<String> The string list to use.
    377    * @return String The previous item, or null if none.
    378    */
    379   public String fetchPreviousListItem(String currentItem, List<String> inList)
     553   * @return Integer The index for the item, or null if none.
     554   */
     555  public Integer fetchStringListItemIndex(String currentItem, List<String> inList)
    380556  {
    381557    log.debug("currentItem = \"" + currentItem + "\"");
     
    386562    log.debug("inList.size() = " + inList.size());
    387563    // Find current index
    388     int currentIndex = -1;
     564    Integer currentIndex = null;
    389565    for (int i = 0; i < inList.size(); i++)
    390566    {
     
    400576    }
    401577    log.debug("currentIndex = " + currentIndex);
    402     // Find previous item
    403     String previousItem = null;
    404     if (currentIndex > 0)
    405     {
    406       previousItem = (String) inList.get(currentIndex - 1);
    407     }
    408     log.debug("previousItem = \"" + previousItem + "\"");
    409     return previousItem;
     578    return currentIndex;
    410579  }
    411580
    412581 
    413582  /**
    414    * Fetch next list item from string  list.
     583   * Fetch previous list item from string  list.
    415584   *
    416585   * @param currentItem String The current item.
    417586   * @param inList List<String> The string list to use.
    418    * @return String The next item, or null if none.
    419    */
    420   public String fetchNextListItem(String currentItem, List<String> inList)
     587   * @return String The previous item, or null if none.
     588   */
     589  public String fetchPreviousListItem(String currentItem, List<String> inList)
    421590  {
    422591    log.debug("currentItem = \"" + currentItem + "\"");
     
    441610    }
    442611    log.debug("currentIndex = " + currentIndex);
     612    // Find previous item
     613    String previousItem = null;
     614    if (currentIndex > 0)
     615    {
     616      previousItem = (String) inList.get(currentIndex - 1);
     617    }
     618    log.debug("previousItem = \"" + previousItem + "\"");
     619    return previousItem;
     620  }
     621
     622 
     623  /**
     624   * Fetch next list item from string  list.
     625   *
     626   * @param currentItem String The current item.
     627   * @param inList List<String> The string list to use.
     628   * @return String The next item, or null if none.
     629   */
     630  public String fetchNextListItem(String currentItem, List<String> inList)
     631  {
     632    log.debug("currentItem = \"" + currentItem + "\"");
     633    if (currentItem == null || inList == null)
     634    {
     635      return null;
     636    }
     637    log.debug("inList.size() = " + inList.size());
     638    // Find current index
     639    int currentIndex = -1;
     640    for (int i = 0; i < inList.size(); i++)
     641    {
     642      String item = (String) inList.get(i);
     643      if (item != null)
     644      {
     645        if (item.equals(currentItem))
     646        {
     647          currentIndex = i;
     648          break;
     649        }
     650      }
     651    }
     652    log.debug("currentIndex = " + currentIndex);
    443653    // Find next item
    444654    String nextItem = null;
     
    450660    return nextItem;
    451661  }
     662
     663
     664  /**
     665   * Restores table scroller settings (stored as valid parameters).
     666   */
     667  private void restoreScrollerState()
     668      throws InvalidParameterValue
     669  {
     670    // Get scroller data from valid parameters set to table
     671    Integer scrollFrom = getValidInteger(Scroller.VFROM);
     672    Integer scrollMaxResults = getValidInteger(Scroller.VMAXRESULT);
     673    // Update scroller settings
     674    if (scrollFrom != null)
     675    {
     676      setItemsFrom(scrollFrom);
     677      setPageSelectedFromScroller(true);
     678    }
     679    if (scrollMaxResults != null)
     680    {
     681      setMaxResults(scrollMaxResults);
     682    }
     683    log.debug("scrollFrom = " + scrollFrom + " isPageSelectedFromScroller() = " + isPageSelectedFromScroller());
     684    log.debug("scrollMaxResults = " + scrollMaxResults);
     685  }
    452686}
  • branches/testing/client/servlet/src/org/proteios/action/hit/ViewActiveHitPDBFile.java

    r3375 r3444  
    281281    }
    282282    log.debug("gene3DUrl = \"" + gene3DUrl + "\"");
     283    // ... Gene3D; <a href=http://cathwww.biochem.ucl.ac.uk/cgi-bin/cath/GotoCath.pl?cath=G3DSA:3.40.605.10>G3DSA:3.40.605.10</a>;
     284    // gene3DUrl = "http://cathwww.biochem.ucl.ac.uk/cgi-bin/cath/GotoCath.pl?cath=G3DSA:3.40.605.10"
     285    //
     286    // Update 2009-10-07
     287    // ... Gene3D; <a href=http://www.cathdb.info/cathnode/G3DSA:3.40.605.10>G3DSA:3.40.605.10</a>; Aldehyde_dehydrogenase_N; 1.
     288    // gene3DUrl = "http://www.cathdb.info/cathnode/G3DSA:3.40.605.10"
     289    //
    283290    // Get Gene3D server URL string (URL part before /cgi-bin
    284291    String gene3DServerUrlStr = null;
     
    290297      {
    291298        gene3DServerUrlStr = gene3DUrlStr.substring(0, cgibinIndex);
     299      }
     300      else
     301      {
     302        int serverSearchIndex = gene3DUrlStr.indexOf("cathnode/");
     303        if (serverSearchIndex > -1)
     304        {
     305          gene3DServerUrlStr = gene3DUrlStr.substring(0, serverSearchIndex);
     306        }
    292307      }
    293308      // Get Gene3D URL title
     
    297312      {
    298313        gene3DUrlTitleStr = gene3DUrlStr.substring(titleIndex + titlePrecursor.length());
     314      }
     315      else
     316      {
     317        titlePrecursor = new String("cathnode/");
     318        titleIndex = gene3DUrlStr.indexOf(titlePrecursor);
     319        if (titleIndex > -1)
     320        {
     321          gene3DUrlTitleStr = gene3DUrlStr.substring(titleIndex + titlePrecursor.length());
     322        }
    299323      }
    300324    }
     
    503527  {
    504528    // ... Gene3D; <a href=http://cathwww.biochem.ucl.ac.uk/cgi-bin/cath/GotoCath.pl?cath=G3DSA:3.40.605.10>G3DSA:3.40.605.10</a>;
     529    // gene3DUrl = "http://cathwww.biochem.ucl.ac.uk/cgi-bin/cath/GotoCath.pl?cath=G3DSA:3.40.605.10"
     530    //
     531    // Update 2009-10-07
     532    // ... Gene3D; <a href=http://www.cathdb.info/cathnode/G3DSA:3.40.605.10>G3DSA:3.40.605.10</a>; Aldehyde_dehydrogenase_N; 1.
     533    // gene3DUrl = "http://www.cathdb.info/cathnode/G3DSA:3.40.605.10"
     534    //
    505535    String linePattern = new String(".*[Gg][Ee][Nn][Ee]3[Dd];.*");
    506536    // Delimiters for URL string
  • branches/testing/client/servlet/src/org/proteios/action/peakList/PeakAnnotationUtil.java

    r3428 r3444  
    2828package org.proteios.action.peakList;
    2929
     30import org.proteios.gui.ImageMap;
     31import org.proteios.gui.ImageMapArea;
    3032import org.proteios.io.SpectrumInterface;
    3133
     
    199201    int ySpectrumOffsetBottom = yInnerAreaOffsetBottom + yInnerAreaPeakBottomOffset;
    200202    int ySpectrumOffsetTop = yInnerAreaOffsetTop + yInnerAreaPeakTopOffset;
    201     int spectrumAreaWidth = width- xSpectrumOffsetLeft - xSpectrumOffsetRight;
     203    int spectrumAreaWidth = width - xSpectrumOffsetLeft - xSpectrumOffsetRight;
    202204    int spectrumAreaHeight = height - ySpectrumOffsetBottom - ySpectrumOffsetTop;
    203205    log.debug("width = " + width + " height = " + height);
     
    220222    graphics.drawString("x", (width - xSpectrumOffsetRight), (height - ySpectrumOffsetBottom));
    221223    */
    222     // Annotate peaks
     224    // Annotate selected peaks
    223225    for (int i = 0; i < topPeaks.size(); i++)
    224226    {
     
    256258        yCoord = height;
    257259      }
    258       log.debug("mass = " + mass + " spectrum offset = " + (xCoord - xSpectrumOffsetLeft) + " xCoord = " + xCoord);
     260      log.debug("mass = " + mass + " spectrum offset = " + (xCoord - xSpectrumOffsetLeft) + " xCoord = " + xCoord + " yCoord = " + yCoord);
    259261      // Draw mass value over peak
    260262      graphics.drawString(massStr, xCoord, (height - yCoord));
     
    402404    return topPeakIndex;
    403405  }
     406
     407
     408  /**
     409   * Create mass peak annotation tool-tips for HTML.
     410   * Note that y-coordinates for drawing purposes
     411   * increases upwards, while tool-tip y-coordinates
     412   * in HTML increases downwards.
     413   *
     414   * @param spectrum SpectrumInterface Input mass spectrum data.
     415   * @param imageWidth int Image width in pixels.
     416   * @param imageHeight int Image height in pixels.
     417   * @return ImageMap An HTML image map with mass value annotations for mass peaks as tool-tips.
     418   */
     419  public ImageMap fetchMassPeakAnnotationToolTips(SpectrumInterface spectrum, int imageWidth, int imageHeight)
     420  {
     421    log.debug("spectrum = " + spectrum);
     422    log.debug("imageWidth = " + imageWidth);
     423    log.debug("imageHeight = " + imageHeight);
     424    // If no spectrum, return directly
     425    if (spectrum == null)
     426    {
     427      return null;
     428    }
     429    //
     430    double[] massArray = spectrum.listMass();
     431    double[] intensityArray = spectrum.listIntensities();
     432    if (massArray == null)
     433    {
     434      return null;
     435    }
     436    int size = massArray.length;
     437    if (size == 0)
     438    {
     439      return null;
     440    }
     441    // Analyze spectrum
     442    double massMin = massArray[0];
     443    double massMax = massArray[massArray.length - 1];
     444    double massRange = 1.0;
     445    if (massMin < massMax)
     446    {
     447      massRange = massMax - massMin;
     448    }
     449    log.debug("size = " + size + " massMin = " + massMin + " massMax = " + massMax + " massRange = " + massRange);
     450    /*
     451     * The positioning of mass value markers above (or near)
     452     * the top of a mass spectrum peak is determined by
     453     * a type of dead reckoning, as use of the JFreeChart
     454     * package to draw the mass spectra itself does not
     455     * give any feedback for the position of the top of
     456     * a mass peak, which depends on the offsets of the
     457     * spectrum drawing area in the image, when space for
     458     * scales and labels have been allocated. The available
     459     * input are the width and height of the image, plus
     460     * the mass and intensity values of the spectra.
     461     * Based on the graphical output for typical standard
     462     * choices of spectra, the needed offsets have been
     463     * determined by trial and error to a degree that
     464     * hopefully is sufficient for an adequate placement
     465     * of the markers.
     466     */
     467    /*
     468     * The following offsets are based on the following input:
     469     * width = 400
     470     * height = 300
     471     * min mass = 110
     472     * max mass = 1022
     473     * max intensity = 3361
     474     */
     475    int maxPeakIndex = findMaxValueIndex(intensityArray);
     476    double maxIntensity = intensityArray[maxPeakIndex];
     477    log.debug("maxPeakIndex = " + maxPeakIndex + " mass = " + massArray[maxPeakIndex] + " intensity = " + maxIntensity);
     478    // Use coordinate system with origin at lower left corner
     479    // Offsets in pixels for inner drawing area without scales and labels
     480    int xInnerAreaOffsetLeft = 58;
     481    int xInnerAreaOffsetRight = 12;
     482    int yInnerAreaOffsetBottom = 36;
     483    int yInnerAreaOffsetTop = 30;
     484    // Corrections for intensity scale numbers outside range [1000, 9999]
     485    int offsetLeftCorrStep = 7;
     486    if (maxIntensity < 1000)
     487    {
     488      xInnerAreaOffsetLeft -= offsetLeftCorrStep;
     489    }
     490    if (maxIntensity > 10000)
     491    {
     492      xInnerAreaOffsetLeft += offsetLeftCorrStep;
     493    }
     494    if (maxIntensity > 100000)
     495    {
     496      xInnerAreaOffsetLeft += offsetLeftCorrStep;
     497    }
     498    if (maxIntensity > 1000000)
     499    {
     500      xInnerAreaOffsetLeft += offsetLeftCorrStep;
     501    }
     502    // Offsets in pixels for mass spectrum area relative to inner drawing area
     503    int xInnerAreaFirstPeakOffset = 18;
     504    int xInnerAreaLastPeakOffset = 13;
     505    int yInnerAreaPeakBottomOffset = 0;
     506    int yInnerAreaPeakTopOffset = 10;
     507    // Offsets in pixels for mass spectrum area relative to full drawing area
     508    int xSpectrumOffsetLeft = xInnerAreaOffsetLeft + xInnerAreaFirstPeakOffset;
     509    int xSpectrumOffsetRight = xInnerAreaOffsetRight + xInnerAreaLastPeakOffset;
     510    int ySpectrumOffsetBottom = yInnerAreaOffsetBottom + yInnerAreaPeakBottomOffset;
     511    int ySpectrumOffsetTop = yInnerAreaOffsetTop + yInnerAreaPeakTopOffset;
     512    int spectrumAreaWidth = imageWidth - xSpectrumOffsetLeft - xSpectrumOffsetRight;
     513    int spectrumAreaHeight = imageHeight - ySpectrumOffsetBottom - ySpectrumOffsetTop;
     514    log.debug("imageWidth = " + imageWidth + " imageHeight = " + imageHeight);
     515    log.debug("spectrumAreaWidth = " + spectrumAreaWidth + " spectrumAreaHeight = " + spectrumAreaHeight);
     516    //
     517    // Create mass value annotation tool-tips for all peaks
     518    int numberOfDecimalsForTooltips = 4;
     519    ImageMap imageMap = fetchMassPeakAnnotationToolTips(massArray, intensityArray,
     520      imageWidth, imageHeight, spectrumAreaWidth, spectrumAreaHeight,
     521      xSpectrumOffsetLeft, ySpectrumOffsetBottom, yInnerAreaOffsetBottom,
     522      massMin, massRange, maxIntensity, numberOfDecimalsForTooltips);
     523    return imageMap;
     524  }
     525
     526
     527  /**
     528   * Create mass peak annotation tool-tips for HTML.
     529   * Note that y-coordinates for drawing purposes
     530   * increases upwards, while tool-tip y-coordinates
     531   * in HTML increases downwards. Input y-coordinates
     532   * are expected to to be increasing upwards.
     533   *
     534   * @param massArray double[] Array with mass values.
     535   * @param intensityArray double[] Array with intensities.
     536   * @param width int Width of image area in pixels.
     537   * @param height int Height of image area in pixels.
     538   * @param spectrumAreaWidth int Width of spectrum area in pixels.
     539   * @param spectrumAreaHeight int Height of spectrum area in pixels.
     540   * @param xSpectrumOffsetLeft int Left offset in x of spectrum area in pixels.
     541   * @param ySpectrumOffsetBottom int Bottom offset in y of spectrum area in pixels.
     542   * @param yInnerAreaOffsetBottom int Bottom offset in y of inner area in pixels.
     543   * @param massMin double Minimum mass value.
     544   * @param massRange double The range of mass values, i.e. maximum - minimum mass value.
     545   * @param maxIntensity double Maximum intensity value.
     546   * @param numberOfDecimals int The number of decimals to use for mass values in tool-tips.
     547   * @return ImageMap An HTML image map with mass value annotations for mass peaks as tool-tips.
     548   */
     549  public ImageMap fetchMassPeakAnnotationToolTips(double[] massArray, double[] intensityArray,
     550      int width, int height, int spectrumAreaWidth, int spectrumAreaHeight,
     551      int xSpectrumOffsetLeft, int ySpectrumOffsetBottom, int yInnerAreaOffsetBottom,
     552      double massMin, double massRange, double maxIntensity, int numberOfDecimals)
     553  {
     554    ImageMap imageMap = new ImageMap();
     555    ImageMapArea imageMapArea;
     556    // Annotate peaks
     557    if (numberOfDecimals < 0)
     558    {
     559      numberOfDecimals = 4;
     560    }
     561    //
     562    // Select peaks for annotation
     563    int tempXCoord = -1;
     564    double tempMaxIntensity = 0;
     565    int tempMaxIntensityIndex = -1;
     566    List<Integer> annotationIndexList = new ArrayList<Integer>();
     567    int size = massArray.length;
     568    for (int i = 0; i < size; i++)
     569    {
     570      double mass = massArray[i];
     571      double intensity = intensityArray[i];
     572      int xCoord = xSpectrumOffsetLeft + (int) (spectrumAreaWidth*((mass - massMin)/massRange));
     573      // Check if peak has same x-coordinate in pixels as previous peaks
     574      if (xCoord == tempXCoord)
     575      {
     576        // Check if peak is larger than previous peaks with same x-coordinate in pixels
     577        if (intensity > tempMaxIntensity)
     578        {
     579          // Set current peak as annotation candidate for x-coordinate in pixels
     580          tempMaxIntensity = intensity;
     581          tempMaxIntensityIndex = i;         
     582        }
     583      }
     584      else
     585      {
     586        if (tempXCoord >= 0)
     587        {
     588          // Add stored peak for previous x-coordinate in pixels to annotation list
     589          annotationIndexList.add(tempMaxIntensityIndex);
     590        }
     591        // Reset stored peak data to new peak
     592        tempXCoord = xCoord;
     593        tempMaxIntensity = intensity;
     594        tempMaxIntensityIndex = i;
     595      }
     596    }
     597    // Add last stored index to list
     598    if (tempXCoord >= 0)
     599    {
     600      // Add stored peak for previous x-coordinate in pixels to annotation list
     601      annotationIndexList.add(tempMaxIntensityIndex);
     602    }
     603    log.debug("mass array size = " + size + " annotationIndexList.size() = " + annotationIndexList.size());
     604    //
     605    // Annotate selected mass peaks
     606    for (int j = 0; j < annotationIndexList.size(); j++)
     607    {
     608      int i = (Integer) annotationIndexList.get(j);
     609      double mass = massArray[i];
     610      double intensity = intensityArray[i];
     611      int xCoord = xSpectrumOffsetLeft + (int) (spectrumAreaWidth*((mass - massMin)/massRange));
     612      int yCoord = ySpectrumOffsetBottom + (int) (spectrumAreaHeight*(intensity/maxIntensity));
     613      // Get mass value marker with desired number of decimals
     614      //String massStr = Integer.toString((int) mass);
     615      //NumberFormat fixedNumberOfDecimals = NumberFormat.getInstance();
     616      NumberFormat fixedNumberOfDecimals = new DecimalFormat("#########.######");
     617      fixedNumberOfDecimals.setMinimumFractionDigits(numberOfDecimals);
     618      fixedNumberOfDecimals.setMaximumFractionDigits(numberOfDecimals);
     619      String massStr = fixedNumberOfDecimals.format(mass).toString();
     620      String hrefStr = null;
     621      //
     622      // Log output for test of tool-tip creation
     623      int yCoordFromImageBottom = height - yCoord;
     624      int ySpectrumImageBottom = height - yInnerAreaOffsetBottom - 1;
     625      // Create image map area with mass annotation tool-tip
     626      //log.debug("   <AREA SHAPE=\"RECT\" COORDS=\"" + xCoord + ", " + yCoordFromImageBottom + ", " + (xCoord + 1) + ", " + ySpectrumImageBottom + "\" HREF=\"http://www.proteios.org\" onMouseover=\"showtip(this,event,'" + massStr + "')\" onMouseout=\"hidetip()\">");
     627      //log.debug("   <AREA SHAPE=\"RECT\" COORDS=\"" + xCoord + ", " + yCoordFromImageBottom + ", " + (xCoord + 1) + ", " + ySpectrumImageBottom + "\" onMouseover=\"showtip(this,event,'" + massStr + "')\" onMouseout=\"hidetip()\">");
     628      imageMapArea = new ImageMapArea(xCoord, yCoordFromImageBottom, (xCoord + 1), ySpectrumImageBottom, hrefStr, massStr);
     629      imageMap.addImageMapArea(imageMapArea);     
     630    }
     631    return imageMap;
     632  }
    404633}
  • branches/testing/client/servlet/src/org/proteios/action/peakList/PlotFileSpectrum.java

    r3428 r3444  
    3737import org.proteios.core.File;
    3838import org.proteios.core.ItemFactory;
     39import org.proteios.gui.ImageMap;
    3940import org.proteios.gui.form.FormFactory;
    4041import org.proteios.io.PeakListFileInterface;
     
    250251      {
    251252        // Trim plot header to fit on one line
    252         int maxNumChars = 40;
     253        int maxNumChars = 35;
    253254        if (plotHeader.length() > maxNumChars)
    254255        {
     
    286287      throw new ActionException(e);
    287288    }
     289  }
     290
     291
     292  /**
     293   * Create mass peak annotation tool-tips for HTML.
     294   * Note that y-coordinates for drawing purposes
     295   * increases upwards, while tool-tip y-coordinates
     296   * in HTML increases downwards.
     297   *
     298   * @param dc DbControl The DbControl to use.
     299   * @param spectrumFileId Integer The spectrum file id.
     300   * @param spectrumId String The spectrum id.
     301   * @param massCutoffLowStr String The lower cutoff mass value string.
     302   * @param massCutoffHighStr String The upper cutoff mass value string.
     303   * @return ImageMap An HTML image map with mass value annotations for mass peaks as tool-tips.
     304   */
     305  public ImageMap fetchMassPeakAnnotationToolTips(DbControl dc, Integer spectrumFileId, String spectrumId,
     306      String massCutoffLowStr, String massCutoffHighStr)
     307  {
     308    Float massCutoffLow = null;
     309    if (massCutoffLowStr != null)
     310    {
     311      try
     312      {
     313        massCutoffLow = Float.parseFloat(massCutoffLowStr);
     314      }
     315      catch (Exception e)
     316      {
     317        log.debug("Exception when parsing string \"" + massCutoffLowStr + "\" to Float: " + e);
     318      }
     319    }
     320    Float massCutoffHigh = null;
     321    if (massCutoffHighStr != null)
     322    {
     323      try
     324      {
     325        massCutoffHigh = Float.parseFloat(massCutoffHighStr);
     326      }
     327      catch (Exception e)
     328      {
     329        log.debug("Exception when parsing string \"" + massCutoffHighStr + "\" to Float: " + e);
     330      }
     331    }
     332    log.debug("spectrumFileId = " + spectrumFileId);
     333    log.debug("spectrumId = \"" + spectrumId + "\"");
     334    log.debug("massCutoffLowStr = \"" + massCutoffLowStr + "\"");
     335    log.debug("massCutoffHighStr = \"" + massCutoffHighStr + "\"");
     336    log.debug("massCutoffLow = " + massCutoffLow);
     337    log.debug("massCutoffHigh = " + massCutoffHigh);
     338    //
     339    SpectrumInterface spectrum = fetchSpectrum(dc, spectrumFileId, spectrumId, massCutoffLow, massCutoffHigh);
     340    PeakAnnotationUtil peakAnnotationUtil = new PeakAnnotationUtil();
     341    ImageMap imageMap = peakAnnotationUtil.fetchMassPeakAnnotationToolTips(spectrum, WIDTH, HEIGHT);
     342    return imageMap;
     343  }
     344
     345
     346  /**
     347   * Create mass peak annotation tool-tips for HTML.
     348   * Note that y-coordinates for drawing purposes
     349   * increases upwards, while tool-tip y-coordinates
     350   * in HTML increases downwards.
     351   *
     352   * @param dc DbControl The DbControl to use.
     353   * @param spectrumFileId Integer The spectrum file id.
     354   * @param spectrumId String The spectrum id.
     355   * @param massCutoffLow Float The lower cutoff mass value.
     356   * @param massCutoffHigh Float The upper cutoff mass value.
     357   * @return ImageMap An HTML image map with mass value annotations for mass peaks as tool-tips.
     358   */
     359  public ImageMap fetchMassPeakAnnotationToolTips(DbControl dc, Integer spectrumFileId, String spectrumId,
     360      Float massCutoffLow, Float massCutoffHigh)
     361  {
     362    log.debug("spectrumFileId = " + spectrumFileId);
     363    log.debug("spectrumId = \"" + spectrumId + "\"");
     364    log.debug("massCutoffLow = " + massCutoffLow);
     365    log.debug("massCutoffHigh = " + massCutoffHigh);
     366    SpectrumInterface spectrum = fetchSpectrum(dc, spectrumFileId, spectrumId, massCutoffLow, massCutoffHigh);
     367    PeakAnnotationUtil peakAnnotationUtil = new PeakAnnotationUtil();
     368    ImageMap imageMap = peakAnnotationUtil.fetchMassPeakAnnotationToolTips(spectrum, WIDTH, HEIGHT);
     369    return imageMap;
     370  }
     371
     372
     373  /**
     374   * Create mass peak annotation tool-tips for HTML.
     375   * Note that y-coordinates for drawing purposes
     376   * increases upwards, while tool-tip y-coordinates
     377   * in HTML increases downwards.
     378   *
     379   * @param dc DbControl The DbControl to use.
     380   * @param spectrumFileId Integer The spectrum file id.
     381   * @param spectrumId String The spectrum id.
     382   * @param massCutoffLow Float The lower cutoff mass value.
     383   * @param massCutoffHigh Float The upper cutoff mass value.
     384   * @param imageWidth int Image width in pixels.
     385   * @param imageHeight int Image height in pixels.
     386   * @return ImageMap An HTML image map with mass value annotations for mass peaks as tool-tips.
     387   */
     388  public ImageMap fetchMassPeakAnnotationToolTips(DbControl dc, Integer spectrumFileId, String spectrumId,
     389      Float massCutoffLow, Float massCutoffHigh, int imageWidth, int imageHeight)
     390  {
     391    SpectrumInterface spectrum = fetchSpectrum(dc, spectrumFileId, spectrumId, massCutoffLow, massCutoffHigh);
     392    PeakAnnotationUtil peakAnnotationUtil = new PeakAnnotationUtil();
     393    ImageMap imageMap = peakAnnotationUtil.fetchMassPeakAnnotationToolTips(spectrum, imageWidth, imageHeight);
     394    return imageMap;
     395  }
     396
     397
     398  /**
     399   * Fetches spectrum given spectrum file id, spectrum id,
     400   * and zoom limit parameters.
     401   *
     402   * @param dc DbControl The DbControl to use.
     403   * @param spectrumFileId Integer The spectrum file id.
     404   * @param spectrumId String The spectrum id.
     405   * @param massCutoffLow Float The lower cutoff mass value.
     406   * @param massCutoffHigh Float The upper cutoff mass value.
     407   * @return SpectrumInterface The possibly pruned spectrum.
     408   */
     409  public SpectrumInterface fetchSpectrum(DbControl dc, Integer spectrumFileId, String spectrumId, Float massCutoffLow, Float massCutoffHigh)
     410  {
     411    log.debug("spectrumFileId = " + spectrumFileId);
     412    log.debug("spectrumId = \"" + spectrumId + "\"");
     413    log.debug("massCutoffLow = " + massCutoffLow);
     414    log.debug("massCutoffHigh = " + massCutoffHigh);
     415    /***********************************************************************
     416     * Get peakListFile data
     417     */
     418    ItemFactory factory = new ItemFactory(dc);
     419    // Get peak list file
     420    File spectrumFile = null;
     421    if (spectrumFileId != null && spectrumFileId > 0)
     422    {
     423      spectrumFile = factory.getById(File.class, spectrumFileId);
     424    }
     425    // Get peak list file reader
     426    boolean useTitle = true;
     427    // Use string id if it exists
     428    if (spectrumId != null)
     429    {
     430      // If the stringId is just a number, it could have been parsed,
     431      // so use the int instead...
     432      try
     433      {
     434        Integer titleNumber = Integer.parseInt(spectrumId);
     435        if (titleNumber != null)
     436        {
     437          useTitle = false;
     438          log.debug("spectrumId is a number, useTitle = " + useTitle);
     439        }
     440      }
     441      catch (NumberFormatException e)
     442      {}
     443      // Special case: A spectrum id starting with a number should be treated as a number
     444      String stringId = null;
     445      int strIndex = spectrumId.indexOf(" ");
     446      if (strIndex >= 0)
     447      {
     448        // Remove part beginning with first blank
     449        stringId = spectrumId.substring(0, strIndex);
     450      }
     451      if (stringId != null)
     452      {
     453        try
     454        {
     455          Integer titleNumber = Integer.parseInt(stringId);
     456          if (titleNumber != null)
     457          {
     458            useTitle = false;
     459            log.debug("spectrumId begins with a number, useTitle = " + useTitle);
     460          }
     461        }
     462        catch (NumberFormatException e)
     463        {}       
     464      }
     465    }
     466    SpectrumFileReaderFactory spectrumFileReaderFactory = new SpectrumFileReaderFactory();
     467    PeakListFileInterface peakListFileReader = spectrumFileReaderFactory.fetchPeakListFileReader(spectrumFile, useTitle);
     468    SpectrumInterface spectrum = null;
     469    if (peakListFileReader != null && spectrumId != null)
     470    {
     471      // Get spectrum
     472      int size = 0;
     473      log.debug("useTitle = " + useTitle + " spectrumId = \"" + spectrumId + "\"");
     474      spectrum = peakListFileReader.getSpectrum(spectrumId);
     475      // Restrict spectrum to specified mass range, if defined
     476      spectrum = zoomSpectrum(spectrum, massCutoffLow, massCutoffHigh);
     477    }
     478    else
     479    {
     480      log.warn("Couldn't find peak list (Peaklist file: " + spectrumFile + " Spectrum Id: " + spectrumId + ")");
     481    }
     482    return spectrum;
    288483  }
    289484
  • branches/testing/client/servlet/src/org/proteios/action/peakList/PlotSpectrum.java

    r3428 r3444  
    3939import org.proteios.core.Peak;
    4040import org.proteios.core.PeakList;
     41import org.proteios.gui.ImageMap;
    4142import org.proteios.io.SpectrumImpl;
    4243import org.proteios.io.SpectrumInterface;
     
    245246      throw new ActionException(e);
    246247    }
     248  }
     249
     250
     251  /**
     252   * Create mass peak annotation tool-tips for HTML.
     253   * Note that y-coordinates for drawing purposes
     254   * increases upwards, while tool-tip y-coordinates
     255   * in HTML increases downwards.
     256   *
     257   * @param dc DbControl The DbControl to use.
     258   * @param peakListId Integer The peak list id.
     259   * @param massCutoffLowStr String The lower cutoff mass value string.
     260   * @param massCutoffHighStr String The upper cutoff mass value string.
     261   * @return ImageMap An HTML image map with mass value annotations for mass peaks as tool-tips.
     262   */
     263  public ImageMap fetchMassPeakAnnotationToolTips(DbControl dc, Integer peakListId,
     264      String massCutoffLowStr, String massCutoffHighStr)
     265  {
     266    Float massCutoffLow = null;
     267    if (massCutoffLowStr != null)
     268    {
     269      try
     270      {
     271        massCutoffLow = Float.parseFloat(massCutoffLowStr);
     272      }
     273      catch (Exception e)
     274      {
     275        log.debug("Exception when parsing string \"" + massCutoffLowStr + "\" to Float: " + e);
     276      }
     277    }
     278    Float massCutoffHigh = null;
     279    if (massCutoffHighStr != null)
     280    {
     281      try
     282      {
     283        massCutoffHigh = Float.parseFloat(massCutoffHighStr);
     284      }
     285      catch (Exception e)
     286      {
     287        log.debug("Exception when parsing string \"" + massCutoffHighStr + "\" to Float: " + e);
     288      }
     289    }
     290    log.debug("peakListId = " + peakListId);
     291    log.debug("massCutoffLowStr = \"" + massCutoffLowStr + "\"");
     292    log.debug("massCutoffHighStr = \"" + massCutoffHighStr + "\"");
     293    log.debug("massCutoffLow = " + massCutoffLow);
     294    log.debug("massCutoffHigh = " + massCutoffHigh);
     295    //
     296    SpectrumInterface spectrum = fetchSpectrum(dc, peakListId, massCutoffLow, massCutoffHigh);
     297    PeakAnnotationUtil peakAnnotationUtil = new PeakAnnotationUtil();
     298    ImageMap imageMap = peakAnnotationUtil.fetchMassPeakAnnotationToolTips(spectrum, WIDTH, HEIGHT);
     299    return imageMap;
     300  }
     301
     302
     303  /**
     304   * Create mass peak annotation tool-tips for HTML.
     305   * Note that y-coordinates for drawing purposes
     306   * increases upwards, while tool-tip y-coordinates
     307   * in HTML increases downwards.
     308   *
     309   * @param dc DbControl The DbControl to use.
     310   * @param peakListId Integer The peak list id.
     311   * @param massCutoffLow Float The lower cutoff mass value.
     312   * @param massCutoffHigh Float The upper cutoff mass value.
     313   * @return ImageMap An HTML image map with mass value annotations for mass peaks as tool-tips.
     314   */
     315  public ImageMap fetchMassPeakAnnotationToolTips(DbControl dc, Integer peakListId,
     316      Float massCutoffLow, Float massCutoffHigh)
     317  {
     318    log.debug("peakListId = " + peakListId);
     319    log.debug("massCutoffLow = " + massCutoffLow);
     320    log.debug("massCutoffHigh = " + massCutoffHigh);
     321    SpectrumInterface spectrum = fetchSpectrum(dc, peakListId, massCutoffLow, massCutoffHigh);
     322    PeakAnnotationUtil peakAnnotationUtil = new PeakAnnotationUtil();
     323    ImageMap imageMap = peakAnnotationUtil.fetchMassPeakAnnotationToolTips(spectrum, WIDTH, HEIGHT);
     324    return imageMap;
     325  }
     326
     327
     328  /**
     329   * Create mass peak annotation tool-tips for HTML.
     330   * Note that y-coordinates for drawing purposes
     331   * increases upwards, while tool-tip y-coordinates
     332   * in HTML increases downwards.
     333   *
     334   * @param dc DbControl The DbControl to use.
     335   * @param peakListId Integer The peak list id.
     336   * @param massCutoffLow Float The lower cutoff mass value.
     337   * @param massCutoffHigh Float The upper cutoff mass value.
     338   * @param imageWidth int Image width in pixels.
     339   * @param imageHeight int Image height in pixels.
     340   * @return ImageMap An HTML image map with mass value annotations for mass peaks as tool-tips.
     341   */
     342  public ImageMap fetchMassPeakAnnotationToolTips(DbControl dc, Integer peakListId,
     343      Float massCutoffLow, Float massCutoffHigh, int imageWidth, int imageHeight)
     344  {
     345    SpectrumInterface spectrum = fetchSpectrum(dc, peakListId, massCutoffLow, massCutoffHigh);
     346    PeakAnnotationUtil peakAnnotationUtil = new PeakAnnotationUtil();
     347    ImageMap imageMap = peakAnnotationUtil.fetchMassPeakAnnotationToolTips(spectrum, imageWidth, imageHeight);
     348    return imageMap;
     349  }
     350
     351
     352  /**
     353   * Fetches spectrum given peak list id,
     354   * and zoom limit parameters.
     355   *
     356   * @param dc DbControl The DbControl to use.
     357   * @param peakListId Integer The peak list id.
     358   * @param massCutoffLow Float The lower cutoff mass value.
     359   * @param massCutoffHigh Float The upper cutoff mass value.
     360   * @return SpectrumInterface The possibly pruned spectrum.
     361   */
     362  public SpectrumInterface fetchSpectrum(DbControl dc, Integer peakListId, Float massCutoffLow, Float massCutoffHigh)
     363  {
     364    log.debug("peakListId = " + peakListId);
     365    log.debug("massCutoffLow = " + massCutoffLow);
     366    log.debug("massCutoffHigh = " + massCutoffHigh);
     367    /***********************************************************************
     368     * Get peakList data
     369     */
     370    PeakList pl = PeakList.getById(dc, peakListId);
     371    ItemQuery<Peak> query = pl.getPeaksQuery();
     372    // query.include(Include.MINE);
     373    ItemResultList<Peak> peaksList = query.list(dc);
     374    int size = 0;
     375    if (!peaksList.isEmpty())
     376    {
     377      size = peaksList.size();
     378    }
     379    // Store mass and intensity values in arrays for peak annotation
     380    double[] massArray = null;
     381    double[] intensityArray = null;
     382    if (size > 0)
     383    {
     384      massArray = new double[size];
     385      intensityArray = new double[size];
     386    }
     387    // Load peak values
     388    for (int i = 0; i < size; i++)
     389    {
     390      Peak p = peaksList.get(i);
     391      double x = p.getMassToChargeRatio();
     392      double y = p.getIntensity();
     393      massArray[i] = x;
     394      intensityArray[i] = y;
     395    }
     396    SpectrumImpl spectrumOrig = null;
     397    if (size > 0)
     398    {
     399      spectrumOrig = new SpectrumImpl();
     400      spectrumOrig.setMass(massArray);
     401      spectrumOrig.setIntensities(intensityArray);
     402    }
     403    // Restrict spectrum to specified mass range, if defined
     404    SpectrumInterface spectrum = zoomSpectrum(spectrumOrig, massCutoffLow, massCutoffHigh);
     405    return spectrum;
    247406  }
    248407
  • branches/testing/client/servlet/src/org/proteios/action/peakList/ViewActivePeakList.java

    r3370 r3444  
    3838import org.proteios.gui.ColumnContainer;
    3939import org.proteios.gui.Image;
     40import org.proteios.gui.ImageMap;
     41import org.proteios.gui.ImageMapArea;
    4042import org.proteios.gui.RowContainer;
    4143import org.proteios.gui.Toolbar;
     
    120122     * Spectrum plot
    121123     */
     124    PlotSpectrum plotSpectrum = new PlotSpectrum();
     125    ImageMap imageMap;
    122126    Image plotOriginal = null;
    123127    if (keepOriginalSpectrum)
     
    130134      plotOriginal.setHeight(PlotSpectrum.HEIGHT);
    131135      plotOriginal.setWidth(PlotSpectrum.WIDTH);
     136      // Add mass annotation image map
     137      imageMap = plotSpectrum.fetchMassPeakAnnotationToolTips(dc, peakListId,
     138        (String) null, (String) null);
     139      plotOriginal.setImageMap(imageMap);
     140      log.debug("plotOriginal imagMap = " + imageMap);
    132141    }
    133142    Image plot = new Image();
     
    140149    plot.setHeight(PlotSpectrum.HEIGHT);
    141150    plot.setWidth(PlotSpectrum.WIDTH);
     151    // Add mass annotation image map
     152    imageMap = plotSpectrum.fetchMassPeakAnnotationToolTips(dc, peakListId,
     153      massCutoffLowStr, massCutoffHighStr);
     154    plot.setImageMap(imageMap);
     155    log.debug("plot imagMap = " + imageMap);
    142156    /***********************************************************************
    143157     * Spectrum mass range selection form
  • branches/testing/client/servlet/src/org/proteios/gui/Image.java

    r2651 r3444  
    3939  private Integer width = 0;
    4040  private Integer height = 0;
     41  private ImageMap imageMap = null;
    4142  /**
    4243   * If true draw a kind of frame around this image
     
    107108    this.framed = framed;
    108109  }
     110
     111
     112  public ImageMap getImageMap()
     113  {
     114    return this.imageMap;
     115  }
     116
     117
     118  public void setImageMap(ImageMap imageMap)
     119  {
     120    this.imageMap = imageMap;
     121  }
    109122}
  • branches/testing/client/servlet/src/org/proteios/gui/web/GUIConverter.java

    r3217 r3444  
    4545import org.proteios.gui.IFrame;
    4646import org.proteios.gui.Image;
     47import org.proteios.gui.ImageMap;
     48import org.proteios.gui.ImageMapArea;
    4749import org.proteios.gui.ListItem;
    4850import org.proteios.gui.Listing;
     
    7274
    7375import se.lu.thep.waf.dom.html.A;
     76import se.lu.thep.waf.dom.html.Area;
    7477import se.lu.thep.waf.dom.html.Attribute;
    7578import se.lu.thep.waf.dom.html.CData;
     
    8386import se.lu.thep.waf.dom.html.Input;
    8487import se.lu.thep.waf.dom.html.Li;
     88import se.lu.thep.waf.dom.html.Map;
    8589import se.lu.thep.waf.dom.html.Option;
    8690import se.lu.thep.waf.dom.html.Select;
     
    187191    // First we show the loading img
    188192    imgT.setSrc(loadingImgSrc);
     193    //
     194    if (img.getImageMap() != null && img.getImageMap().getImageMapAreaList() != null)
     195    {
     196      String imageMapStr = "ImageMap" + imgId;
     197      imgT.setUsemap("#" + imageMapStr);
     198      // Create image map
     199      Map map = new Map();
     200      map.setParent(div);
     201      div.add(map);
     202      map.setName(imageMapStr);
     203      List<ImageMapArea> imageMapAreaList = img.getImageMap().getImageMapAreaList();
     204      for (int i = 0; i < imageMapAreaList.size(); i++)
     205      {
     206        // Get image map area data from image object
     207        ImageMapArea imageMapArea = (ImageMapArea) imageMapAreaList .get(i);
     208        int xTopLeft = imageMapArea.getXTopLeft();
     209        int yTopLeft = imageMapArea.getYTopLeft();
     210        int xBottomRight = imageMapArea.getXBottomRight();
     211        int yBottomRight = imageMapArea.getYBottomRight();
     212        String hrefStr = imageMapArea.getHrefStr();
     213        String toolTipStr = imageMapArea.getToolTipStr();
     214        String onMouseoverStr = null;
     215        String onMouseoutStr = null;
     216        if (toolTipStr != null && !toolTipStr.equals(""))
     217        {
     218          onMouseoverStr = new String("showtip(this,event,'" + toolTipStr + "')");
     219          onMouseoutStr = new String("hidetip()");
     220        }
     221        // Create new image map area
     222        Area area = new Area();
     223        area.setParent(map);
     224        map.add(area);
     225        area.setShape("RECT");
     226        area.setCoords(xTopLeft, yTopLeft, xBottomRight, yBottomRight);
     227        if (hrefStr != null && !hrefStr.equals(""))
     228        {
     229          area.setHref(hrefStr);
     230        }
     231        if (onMouseoverStr != null && !onMouseoverStr.equals(""))
     232        {
     233          area.setOnMousover(onMouseoverStr);
     234        }
     235        if (onMouseoutStr != null && !onMouseoutStr.equals(""))
     236        {
     237          area.setOnMousout(onMouseoutStr);
     238        }
     239      }
     240    }
    189241    script = div.newScript();
    190242    script.newCData("var " + imgId + " = new Image();");
  • branches/testing/client/servlet/test/test_webservice.sh

    r3416 r3444  
    4949}
    5050
     51DELETE()
     52{
     53  url=$1
     54  curlit "-X DELETE" $url
     55}
     56
     57 
    5158PUT()
    5259{
     
    7178fail()
    7279{
    73     echo "Failed[$test_no]: $1"
    74     echo "Message: $2"
     80  date >> /dev/stderr
     81    echo "Failed[$test_no]: $1" >> /dev/stderr
     82    echo "Message: $2" >> /dev/stderr
     83  echo "" >> /dev/stderr
    7584  exit
    7685}
     
    8493case $1 in
    8594  9)
    86     test "Cross table search"
    87     GET "$A" "$resource/extracts?$auth"
     95    test "Mark file for deletion"
     96    generate_name
     97    echo -e "Name\tDescription" > $A
     98    echo -e "${i}_$name\tThis is the ${i}:th file" >> $A
     99    PUT "$A" "$resource/files?$auth"
     100    GET "$B" "$resource/files?$auth&select=Id&whereName==${i}_$name"
     101    lastid=`tail -n 1 $B | perl -ane '/(\d+)/; print \$1;'`
     102    DELETE "$resource/files/$lastid?$auth"
     103    GET "$C" "$resource/files?$auth&select=Name,Removed&whereName==${i}_$name"
     104    removed=`grep $name $C`
     105    if [ "$removed" != "" ]; then
     106      fail "$test" "File should have been marked as removed, but was not."
     107    fi
    88108    ;;
    89109  8)
  • branches/testing/client/servlet/www/static/js/script.js

    r3409 r3444  
    378378}
    379379
     380/* http://www.dynamicdrive.com/dynamicindex5/texttool.htm */
     381function showtip(current,e,text)
     382{
     383   if (document.all || document.getElementById)
     384   {
     385      thetitle = text.split('<br>');
     386      if (thetitle.length > 1)
     387      {
     388         thetitles = '';
     389         for (i=0; i < thetitle.length; i++)
     390         {
     391            thetitles += thetitle[i];
     392         }
     393         current.title = thetitles;
     394      }
     395      else
     396      {
     397         current.title = text;
     398      }
     399   }
     400   else if (document.layers)
     401   {
     402      document.tooltip.document.write('<layer bgColor="white" style="border:1px solid black;font-size:12px;">'+text+'</layer>');
     403      document.tooltip.document.close();
     404      document.tooltip.left = e.pageX + 5;
     405      document.tooltip.top = e.pageY + 5;
     406      document.tooltip.visibility = "show";
     407   }
     408}
     409
     410function hidetip()
     411{
     412   if (document.layers)
     413   {
     414      document.tooltip.visibility = "hidden";
     415   }
     416}
     417
    380418// this will resize all iframes every
    381419// time you change the size of the window.
  • branches/testing/recipe

    r3263 r3444  
    99# Run 'bake web' to generate and copy web related files
    1010WEB_PATH=/home/tom/wwwroot/proteios
    11 VERSION=2.7.0
     11VERSION=2.9.0
    1212MD5_GZ=`cat /home/tom/trac/proteios/htdocs/downloads/$VERSION/ProteiosSE-$VERSION.tar.gz.MD5`
    1313MD5_ZIP=`cat /home/tom/trac/proteios/htdocs/downloads/$VERSION/ProteiosSE-$VERSION.zip.MD5`
Note: See TracChangeset for help on using the changeset viewer.