import jalview.datamodel.*;\r
import java.util.StringTokenizer;\r
import jalview.schemes.UserColourScheme;\r
-import jalview.gui.FeatureRenderer;\r
+import java.net.URL;\r
\r
public class AnnotationReader\r
{\r
- public boolean readGroupsFile(FeatureRenderer fr, AlignmentI al, String file)\r
+ public boolean readAnnotationFile(AlignmentI al, String file)\r
{\r
+\r
try\r
{\r
- BufferedReader in = new BufferedReader(new FileReader(file));\r
- SequenceI seq = null;\r
- String line, type, desc, token;\r
\r
- int index, start, end;\r
- StringTokenizer st;\r
- SequenceFeature sf;\r
- int lineNo = 0;\r
- while ( (line = in.readLine()) != null)\r
+ BufferedReader in = null;\r
+ try{\r
+ URL url = new URL(file);\r
+ in = new BufferedReader(new InputStreamReader(url.openStream()));\r
+ }\r
+ catch(java.net.MalformedURLException ex)\r
{\r
- lineNo++;\r
- st = new StringTokenizer(line, "\t");\r
- if (st.countTokens() == 2)\r
- {\r
- type = st.nextToken();\r
- UserColourScheme ucs = new UserColourScheme(st.nextToken());\r
- fr.setColour(type, ucs.findColour("A"));\r
- continue;\r
- }\r
-\r
- while (st.hasMoreElements())\r
- {\r
- desc = st.nextToken();\r
- token = st.nextToken();\r
- if (!token.equals("ID_NOT_SPECIFIED"))\r
- {\r
- index = al.findIndex(al.findName(token));\r
- st.nextToken();\r
- }\r
- else\r
- {\r
- index = Integer.parseInt(st.nextToken());\r
- }\r
-\r
- start = Integer.parseInt(st.nextToken());\r
- end = Integer.parseInt(st.nextToken());\r
-\r
- seq = al.getSequenceAt(index);\r
- start = seq.findIndex(start) - 1;\r
- end = seq.findIndex(end) - 1;\r
-\r
- type = st.nextToken();\r
-\r
- if (fr.getColour(type) == null)\r
- {\r
- // Probably the old style groups file\r
- UserColourScheme ucs = new UserColourScheme(type);\r
- fr.setColour(type, ucs.findColour("A"));\r
- }\r
-\r
- sf = new SequenceFeature(type, desc, "", start, end);\r
-\r
- seq.getDatasetSequence().addSequenceFeature(sf);\r
- }\r
+ in = new BufferedReader(new FileReader(file));\r
}\r
- }\r
- catch (Exception ex)\r
- {\r
- System.out.println("Error parsing groups file: " + ex);\r
- return false;\r
- }\r
\r
- return true;\r
- }\r
\r
- public boolean readAnnotationFile(AlignmentI al, String file)\r
- {\r
- try\r
- {\r
- BufferedReader in = new BufferedReader(new FileReader(file));\r
String line, label, description, token;\r
int graphStyle, index;\r
SequenceI refSeq = null;\r
- int refSeqIndex = -1;\r
-\r
+ int refSeqIndex = 0;\r
+ int existingAnnotations = 0;\r
+ if(al.getAlignmentAnnotation()!=null)\r
+ existingAnnotations = al.getAlignmentAnnotation().length;\r
\r
StringTokenizer st;\r
Annotation[] annotations;\r
try{\r
refSeqIndex = Integer.parseInt(st.nextToken());\r
}\r
- catch(NumberFormatException ex)\r
+ catch(Exception ex)\r
{\r
refSeqIndex = 0;\r
}\r
\r
line = st.nextToken();\r
st = new StringTokenizer(line, "|", true);\r
- annotations = new Annotation[st.countTokens()];\r
- index = 0;\r
+ annotations = new Annotation[st.countTokens()+refSeqIndex];\r
+ index = refSeqIndex;\r
boolean emptyColumn = true;\r
while (st.hasMoreElements())\r
{\r
0,\r
graphStyle);\r
\r
- al.addAnnotation(annotation, refSeq, refSeqIndex);\r
-\r
+ annotation = al.addAnnotation(annotation, refSeq);\r
+ al.setAnnotationIndex(annotation, al.getAlignmentAnnotation().length - existingAnnotations-1);\r
}\r
+\r
+ al.adjustSequenceAnnotations();\r
+\r
+\r
}catch(Exception ex)\r
- {ex.printStackTrace();\r
- // System.out.println("Problem reading annotation file: "+ex);\r
+ {\r
+ ex.printStackTrace();\r
+ System.out.println("Problem reading annotation file: "+ex);\r
return false;\r
}\r
return true;\r
\r
if(value==0)\r
{ try{\r
- value = Float.parseFloat(token);\r
+ value = new Float(token).floatValue();\r
}catch(NumberFormatException ex){}\r
}\r
\r
\r
if(annotation==null)\r
return;\r
-\r
- float value = Float.parseFloat(st.nextToken());\r
+ float value = new Float(st.nextToken()).floatValue();\r
String label = st.hasMoreTokens() ? st.nextToken() : null;\r
java.awt.Color colour = null;\r
if(st.hasMoreTokens())\r