X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFeaturesFile.java;h=b3d434efe6565676531f46294a63014243f1d128;hb=4f24ef0848cf3c43ba0467f31fce1baa5c57aad5;hp=a83dff8665787cf6bd93546f4624f5068b48904b;hpb=9922c9eec14599f6b141a8db8a3859cab7227ce0;p=jalview.git diff --git a/src/jalview/io/FeaturesFile.java b/src/jalview/io/FeaturesFile.java index a83dff8..b3d434e 100755 --- a/src/jalview/io/FeaturesFile.java +++ b/src/jalview/io/FeaturesFile.java @@ -65,12 +65,29 @@ public class FeaturesFile extends AlignFile } /** - * DOCUMENT ME! + * The Application can render HTML, but the applet will + * remove HTML tags and replace links with %LINK% + * Both need to read links in HTML however + * + * @throws IOException DOCUMENT ME! + */ + public boolean parse(AlignmentI align, + Hashtable colours, + boolean removeHTML) + { + return parse(align, colours, null, removeHTML); + } + /** + * The Application can render HTML, but the applet will + * remove HTML tags and replace links with %LINK% + * Both need to read links in HTML however * * @throws IOException DOCUMENT ME! */ - public boolean parse(AlignmentI align, Hashtable colours) - throws IOException + public boolean parse(AlignmentI align, + Hashtable colours, + Hashtable featureLink, + boolean removeHTML) { String line = null; try @@ -82,7 +99,8 @@ public class FeaturesFile extends AlignFile float score; StringTokenizer st; SequenceFeature sf; - String featureGroup = null; + String featureGroup = null, groupLink = null; + Hashtable typeLink = new Hashtable(); boolean GFFFile = true; @@ -99,6 +117,11 @@ public class FeaturesFile extends AlignFile if (type.equalsIgnoreCase("startgroup")) { featureGroup = st.nextToken(); + if (st.hasMoreElements()) + { + groupLink = st.nextToken(); + featureLink.put(featureGroup, groupLink); + } } else if (type.equalsIgnoreCase("endgroup")) { @@ -106,11 +129,21 @@ public class FeaturesFile extends AlignFile //but at present theres no way of showing more than 1 group st.nextToken(); featureGroup = null; + groupLink = null; } else { UserColourScheme ucs = new UserColourScheme(st.nextToken()); colours.put(type, ucs.findColour("A")); + if (st.hasMoreElements()) + { + String link = st.nextToken(); + typeLink.put(type, link); + if(featureLink==null) + featureLink = new Hashtable(); + featureLink.put(type, link); + } + } continue; } @@ -132,7 +165,7 @@ public class FeaturesFile extends AlignFile end = Integer.parseInt(st.nextToken()); try { - score = Float.parseFloat(st.nextToken()); + score = new Float(st.nextToken()).floatValue(); } catch (NumberFormatException ex) { @@ -201,7 +234,20 @@ public class FeaturesFile extends AlignFile sf = new SequenceFeature(type, desc, "", start, end, featureGroup); - seq.getDatasetSequence().addSequenceFeature(sf); + seq.addSequenceFeature(sf); + + if(groupLink!=null && removeHTML) + { + sf.addLink(groupLink); + sf.description += "%LINK%"; + } + if(typeLink.containsKey(type) && removeHTML) + { + sf.addLink(typeLink.get(type).toString()); + sf.description += "%LINK%"; + } + + parseDescriptionHTML(sf, removeHTML); //If we got here, its not a GFFFile GFFFile = false; @@ -212,14 +258,40 @@ public class FeaturesFile extends AlignFile { System.out.println(line); ex.printStackTrace(); - System.out.println("Error parsing groups file: " + ex +"\n"+line); + System.out.println("Error parsing feature file: " + ex +"\n"+line); return false; } return true; - } + void parseDescriptionHTML(SequenceFeature sf, boolean removeHTML) + { + StringBuffer sb = new StringBuffer(); + StringTokenizer st = new StringTokenizer(sf.getDescription(), "<"); + String token, link; + while(st.hasMoreElements()) + { + token = st.nextToken("<>"); + if(token.equalsIgnoreCase("html") || token.startsWith("/")) + continue; + + if(token.startsWith("a href=")) + { + link = token.substring(token.indexOf("\"")+1, token.length()-1); + String label = st.nextToken("<>"); + sf.addLink(label+"|"+link); + sb.append(label+"%LINK%"); + } + else if(token.equalsIgnoreCase("br")) + sb.append("\n"); + else + sb.append(token); + } + + if(removeHTML) + sf.description = sb.toString(); + } /** * DOCUMENT ME! @@ -278,12 +350,15 @@ public class FeaturesFile extends AlignFile do { - if (groups.size() > 0) + + + if (groups.size() > 0 && groupIndex < groups.size()) { group = groups.elementAt(groupIndex).toString(); out.append("\nSTARTGROUP\t" + group + "\n"); } - + else + group = null; for (int i = 0; i < seqs.length; i++) { @@ -295,7 +370,13 @@ public class FeaturesFile extends AlignFile if (!visible.containsKey(next[j].type)) continue; - if (group != null && !next[j].featureGroup.equals(group)) + if (group != null + && (next[j].featureGroup==null + || !next[j].featureGroup.equals(group)) + ) + continue; + + if(group==null && next[j].featureGroup!=null) continue; if(next[j].description==null || next[j].description.equals("")) @@ -312,14 +393,16 @@ public class FeaturesFile extends AlignFile } } - if(groups.size()>0) + if(group!=null) { out.append("ENDGROUP\t"+group+"\n"); + groupIndex++; } + else + break; - groupIndex++; } - while(groupIndex < groups.size()); + while(groupIndex < groups.size()+1); return out.toString();