View Javadoc

1   package uk.ac.ebi.intenz.tools.sib.helper;
2   
3   import java.util.regex.Matcher;
4   import java.util.regex.Pattern;
5   
6   /**
7    * This class currently contains only one method to create hyperlinks for all cross-references (xrefs) in a flat file.
8    *
9    * @author Michael Darsow
10   * @version $Revision: 1.4 $ $Date: 2009/04/15 09:09:34 $
11   * @deprecated this is a view-tier task, use the IntEnzUtilities class instead (public webapp)
12   */
13  public class FFWriterHelper {
14  
15  //  private static final Logger LOGGER = Logger.getLogger(FFWriterHelper.class);
16  
17    /**
18     * Create hyperlinks for all cross-references (xrefs) in a flat file.
19     *
20     * @param flatFile The flat file string.
21     * @return the hyperlinked flat file string.
22     * @throws NullPointerException if <code>flatFile</code> is <code>null</code>.
23     */
24    public static String createXrefHyperlinks(String flatFile) {
25      if (flatFile == null) throw new NullPointerException("Parameter 'flatFile' must not be null.");
26      String linkedFlatFile = flatFile.replaceAll("PR   PROSITE\\; (.+?)\\;",
27                                                  "PR   PROSITE; <a class=\"pre_anchor\" href=\"http://www.expasy.org/prosite/$1\" target=\"_blank\">$1</a>;");
28      linkedFlatFile = linkedFlatFile.replaceAll("DI   (.+?)MIM\\:(\\d+)\\.",
29                                                 "DI   $1<a class=\"pre_anchor\" href=\"http://www.ncbi.nlm.nih.gov/entrez/dispomim.cgi?id=$2\" target=\"_blank\">MIM:$2</a>.");
30  
31      Pattern DRLinePattern = Pattern.compile("DR   (.+?)\n");
32      Matcher DRLinePatternMatcher = DRLinePattern.matcher(linkedFlatFile);
33      StringBuffer newLinkedFlatFile = new StringBuffer();
34      while (DRLinePatternMatcher.find()) {
35        String DRLineContents = DRLinePatternMatcher.group(1);
36        DRLineContents = DRLineContents.replaceAll("(\\w+?)\\,(\\s+?)(.+?)\\;",
37                                                   "<a class=\"pre_anchor\" href=\"http://www.uniprot.org/uniprot/$1\" target=\"_blank\">$1</a>,$2$3;");
38        DRLinePatternMatcher.appendReplacement(newLinkedFlatFile, "DR   " + DRLineContents + "\n");
39      }
40      newLinkedFlatFile = DRLinePatternMatcher.appendTail(newLinkedFlatFile);
41  
42      return newLinkedFlatFile.toString();
43    }
44  
45  }