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
8
9
10
11
12
13 public class FFWriterHelper {
14
15
16
17
18
19
20
21
22
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 }