/*
 *                      Nividic development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the microarray platform
 * of the �cole Normale Sup�rieure and the individual authors.
 * These should be listed in @author doc comments.
 *
 * For more information on the Nividic project and its aims,
 * or to join the Nividic mailing list, visit the home page
 * at:
 *
 *      http://www.transcriptome.ens.fr/nividic
 *
 */

package fr.ens.transcriptome.nividic.om.translators;

import java.io.Serializable;

/**
 * This class define a translator that add commons links information.
 * @author Laurent Jourdren
 */
public class CommonLinksInfoTranslator extends BasicTranslator implements
    Serializable {

  static final long serialVersionUID = -6974613812819684107L;

  private Translator translator;

  /**
   * Get an ordered list of the translator fields
   * @return an ordered list of the translator fields.
   */
  public String[] getFields() {

    return this.translator.getFields();
  }

  /**
   * Get a translation for a feature
   * @param id Identifier of the feature
   * @param field the field to get
   * @return An array with the annotation of the Feature
   */
  public String translateField(final String id, final String field) {

    return this.translator.translateField(id, field);
  }

  /**
   * Test if the link information is available for the field
   * @param field Field to test
   * @return true if link information is available
   */
  public boolean isLinkInfo(final String field) {

    if (field == null)
      return false;

    return field.equals("TranscriptID")
        || field.equals("MGIID") || field.equals("EntrezID")
        || field.equals("SGDID") || field.equals("Phatr2 Protein HyperLink");
  }

  /**
   * Get link information.
   * @param translatedId Translated id
   * @param field field of the id
   * @return a link for the translated id
   */
  public String getLinkInfo(final String translatedId, final String field) {

    if (translatedId == null || field == null)
      return null;

    if (field.equals("TranscriptID"))
      return "http://www.ensembl.org/Homo_sapiens/searchview?species=;idx=;q="
          + translatedId;

    if (field.equals("MGIID") && translatedId.startsWith("MGI:")) {

      final String id = translatedId.substring(4, translatedId.length());

      return "http://www.informatics.jax.org/searches/accession_report.cgi?id=MGI%3A"
          + id;
    }

    if (field.equals("EntrezID"))
      return "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?"
          + "db=gene&cmd=Retrieve&dopt=Graphics&list_uids=" + translatedId;

    if (field.equals("SGDID"))
      return "http://db.yeastgenome.org/cgi-bin/locus.pl?dbid=" + translatedId;

    if (field.equals("Phatr2 Protein HyperLink"))
      return "http://genome.jgi-psf.org/cgi-bin/dispGeneModel?db=Phatr2&tid="
          + translatedId;

    return null;
  }

  /**
   * Get the available identfiers by the translator if possible.
   * @return a array of string with the identifiers
   */
  public String[] getIds() {

    return this.translator.getIds();
  }

  //
  // Constructor
  //

  /**
   * Public constructor.
   * @param translator Translator to use
   */
  public CommonLinksInfoTranslator(final Translator translator) {

    if (translator == null)
      throw new NullPointerException("Translator can't be null");

    this.translator = translator;
  }
}

@@ -1831,34 +1831,35 @@
 eld.equals(%22
-Transcript
+EnsemblGene
 ID%22)%0A       
@@ -1872,27 +1872,34 @@
 eld.equals(%22
-MGI
+EntrezGene
 ID%22) %7C%7C fiel
@@ -1904,30 +1904,27 @@
 eld.equals(%22
-Entrez
+MGI
 ID%22)%0A       
@@ -2324,18 +2324,19 @@
 ls(%22
-Transcript
+EnsemblGene
 ID%22)
@@ -2391,18 +2391,22 @@
 ens/
-s
+S
 earch
-view
+/Summary
 ?spe
@@ -2414,15 +2414,175 @@
 ies=
-;idx=;q
+all;q=%22%0A          + translatedId;%0A%0A    if (field.equals(%22EntrezGeneID%22))%0A      return %22http://www.ncbi.nlm.nih.gov/sites/entrez?Db=gene&Cmd=ShowDetailView&TermToSearch
 =%22%0A 
@@ -2859,24 +2859,27 @@
 ;%0A    %7D%0A%0A   
+ //
  if (field.e
@@ -2893,33 +2893,34 @@
 EntrezID%22))%0A    
- 
+//
  return %22http://
@@ -2964,21 +2964,18 @@
 i?%22%0A    
-     
+//
  + %22db=g

Update common links translator