X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFeaturesFile.java;h=42b032d361d930acc942e4f7e753fa07ef70e90c;hb=38c2f5336bb602570ab698985810b870fa7390de;hp=a83dff8665787cf6bd93546f4624f5068b48904b;hpb=9922c9eec14599f6b141a8db8a3859cab7227ce0;p=jalview.git diff --git a/src/jalview/io/FeaturesFile.java b/src/jalview/io/FeaturesFile.java index a83dff8..42b032d 100755 --- a/src/jalview/io/FeaturesFile.java +++ b/src/jalview/io/FeaturesFile.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle +* Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -40,15 +40,6 @@ public class FeaturesFile extends AlignFile { } - /** - * Creates a new FeaturesFile object. - * - * @param inStr DOCUMENT ME! - */ - public FeaturesFile(String inStr) - { - super(inStr); - } /** * Creates a new FeaturesFile object. @@ -65,12 +56,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) - throws IOException + 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, + Hashtable featureLink, + boolean removeHTML) { String line = null; try @@ -82,7 +90,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 +108,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 +120,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 +156,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) { @@ -149,7 +173,17 @@ public class FeaturesFile extends AlignFile catch (Exception ex) {} - seq.getDatasetSequence().addSequenceFeature(sf); + if(st.hasMoreTokens()) + { + StringBuffer attributes = new StringBuffer(); + while (st.hasMoreTokens()) + { + attributes.append("\t"+st.nextElement()); + } + sf.setValue("ATTRIBUTES", attributes.toString()); + } + + seq.addSequenceFeature(sf); break; } @@ -201,7 +235,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; @@ -211,15 +258,67 @@ public class FeaturesFile extends AlignFile catch (Exception ex) { 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; - } + public void parseDescriptionHTML(SequenceFeature sf, boolean removeHTML) + { + if(removeHTML && sf.getDescription().toUpperCase().indexOf("")==-1) + removeHTML = false; + + StringBuffer sb = new StringBuffer(); + StringTokenizer st = new StringTokenizer(sf.getDescription(), "<"); + String token, link; + int startTag; + String tag=null; + while(st.hasMoreElements()) + { + token = st.nextToken("&>"); + if(token.equalsIgnoreCase("html") || token.startsWith("/")) + { + continue; + } + + tag = null; + startTag = token.indexOf("<"); + + if (startTag > -1) + { + tag = token.substring(startTag+1); + token = token.substring(0, startTag); + } + + if (tag != null && tag.toUpperCase().startsWith("A HREF=")) + { + if(token.length()>0) + sb.append(token); + link = tag.substring(tag.indexOf("\"") + 1, tag.length() - 1); + String label = st.nextToken("<>"); + sf.addLink(label + "|" + link); + sb.append(label + "%LINK%"); + } + else if (tag != null && tag.equalsIgnoreCase("br")) + sb.append("\n"); + else if (token.startsWith("lt;")) + sb.append("<" + token.substring(3)); + else if (token.startsWith("gt;")) + sb.append(">" + token.substring(3)); + else if (token.startsWith("amp;")) + sb.append("&" + token.substring(4)); + else + { + sb.append(token); + } + } + + if(removeHTML) + sf.description = sb.toString(); + + } /** * DOCUMENT ME! @@ -278,12 +377,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,13 +397,50 @@ 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("")) out.append(next[j].type+"\t"); else - out.append(next[j].description + "\t"); + { + if(next[j].links!=null + && next[j].getDescription().indexOf("")==-1) + out.append(""); + + out.append(next[j].description+" "); + if(next[j].links!=null) + { + for(int l=0; l" + + label + + ""); + } + } + + if (next[j].getDescription().indexOf("") == -1) + out.append(""); + } + + + out.append("\t"); + } + out.append( seqs[i].getName() + "\t-1\t" + next[j].begin + "\t" @@ -312,14 +451,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(); @@ -329,6 +470,7 @@ public class FeaturesFile extends AlignFile { StringBuffer out = new StringBuffer(); SequenceFeature [] next; + String source; for(int i=0; i