From: amwaterhouse Date: Fri, 3 Feb 2006 17:46:11 +0000 (+0000) Subject: Many changes X-Git-Tag: Root_VamJalview_2_07b+~172 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=3cf306f55e6e186f60de89f3e800c1cbc366be46;p=jalview.git Many changes --- diff --git a/src/jalview/io/AnnotationReader.java b/src/jalview/io/AnnotationReader.java index 5ba1e26..9c6dc49 100755 --- a/src/jalview/io/AnnotationReader.java +++ b/src/jalview/io/AnnotationReader.java @@ -4,89 +4,34 @@ import java.io.*; import jalview.datamodel.*; import java.util.StringTokenizer; import jalview.schemes.UserColourScheme; -import jalview.gui.FeatureRenderer; +import java.net.URL; public class AnnotationReader { - public boolean readGroupsFile(FeatureRenderer fr, AlignmentI al, String file) + public boolean readAnnotationFile(AlignmentI al, String file) { + try { - BufferedReader in = new BufferedReader(new FileReader(file)); - SequenceI seq = null; - String line, type, desc, token; - int index, start, end; - StringTokenizer st; - SequenceFeature sf; - int lineNo = 0; - while ( (line = in.readLine()) != null) + BufferedReader in = null; + try{ + URL url = new URL(file); + in = new BufferedReader(new InputStreamReader(url.openStream())); + } + catch(java.net.MalformedURLException ex) { - lineNo++; - st = new StringTokenizer(line, "\t"); - if (st.countTokens() == 2) - { - type = st.nextToken(); - UserColourScheme ucs = new UserColourScheme(st.nextToken()); - fr.setColour(type, ucs.findColour("A")); - continue; - } - - while (st.hasMoreElements()) - { - desc = st.nextToken(); - token = st.nextToken(); - if (!token.equals("ID_NOT_SPECIFIED")) - { - index = al.findIndex(al.findName(token)); - st.nextToken(); - } - else - { - index = Integer.parseInt(st.nextToken()); - } - - start = Integer.parseInt(st.nextToken()); - end = Integer.parseInt(st.nextToken()); - - seq = al.getSequenceAt(index); - start = seq.findIndex(start) - 1; - end = seq.findIndex(end) - 1; - - type = st.nextToken(); - - if (fr.getColour(type) == null) - { - // Probably the old style groups file - UserColourScheme ucs = new UserColourScheme(type); - fr.setColour(type, ucs.findColour("A")); - } - - sf = new SequenceFeature(type, desc, "", start, end); - - seq.getDatasetSequence().addSequenceFeature(sf); - } + in = new BufferedReader(new FileReader(file)); } - } - catch (Exception ex) - { - System.out.println("Error parsing groups file: " + ex); - return false; - } - return true; - } - public boolean readAnnotationFile(AlignmentI al, String file) - { - try - { - BufferedReader in = new BufferedReader(new FileReader(file)); String line, label, description, token; int graphStyle, index; SequenceI refSeq = null; - int refSeqIndex = -1; - + int refSeqIndex = 0; + int existingAnnotations = 0; + if(al.getAlignmentAnnotation()!=null) + existingAnnotations = al.getAlignmentAnnotation().length; StringTokenizer st; Annotation[] annotations; @@ -146,7 +91,7 @@ public class AnnotationReader try{ refSeqIndex = Integer.parseInt(st.nextToken()); } - catch(NumberFormatException ex) + catch(Exception ex) { refSeqIndex = 0; } @@ -159,8 +104,8 @@ public class AnnotationReader line = st.nextToken(); st = new StringTokenizer(line, "|", true); - annotations = new Annotation[st.countTokens()]; - index = 0; + annotations = new Annotation[st.countTokens()+refSeqIndex]; + index = refSeqIndex; boolean emptyColumn = true; while (st.hasMoreElements()) { @@ -187,12 +132,17 @@ public class AnnotationReader 0, graphStyle); - al.addAnnotation(annotation, refSeq, refSeqIndex); - + annotation = al.addAnnotation(annotation, refSeq); + al.setAnnotationIndex(annotation, al.getAlignmentAnnotation().length - existingAnnotations-1); } + + al.adjustSequenceAnnotations(); + + }catch(Exception ex) - {ex.printStackTrace(); - // System.out.println("Problem reading annotation file: "+ex); + { + ex.printStackTrace(); + System.out.println("Problem reading annotation file: "+ex); return false; } return true; @@ -213,7 +163,7 @@ public class AnnotationReader if(value==0) { try{ - value = Float.parseFloat(token); + value = new Float(token).floatValue(); }catch(NumberFormatException ex){} } @@ -303,8 +253,7 @@ public class AnnotationReader if(annotation==null) return; - - float value = Float.parseFloat(st.nextToken()); + float value = new Float(st.nextToken()).floatValue(); String label = st.hasMoreTokens() ? st.nextToken() : null; java.awt.Color colour = null; if(st.hasMoreTokens())