X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FAnnotationReader.java;h=cd7abfdf62b67fa32cfeb636477a5270cbd83ce2;hb=69e9cd54dcfd25dd3067f353bc53eb6b4d7e27af;hp=5ba1e266706813ff7691d30904969bfb20f1ef11;hpb=e9d286eaa2ec9b85d1d2634ba53401fa65cf21bc;p=jalview.git diff --git a/src/jalview/io/AnnotationReader.java b/src/jalview/io/AnnotationReader.java index 5ba1e26..cd7abfd 100755 --- a/src/jalview/io/AnnotationReader.java +++ b/src/jalview/io/AnnotationReader.java @@ -4,89 +4,43 @@ 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; + java.io.InputStream is = getClass().getResourceAsStream("/" + file); + if (is != null) { - lineNo++; - st = new StringTokenizer(line, "\t"); - if (st.countTokens() == 2) + in = new BufferedReader(new java.io.InputStreamReader(is)); + } + else + { + try { - type = st.nextToken(); - UserColourScheme ucs = new UserColourScheme(st.nextToken()); - fr.setColour(type, ucs.findColour("A")); - continue; + URL url = new URL(file); + in = new BufferedReader(new InputStreamReader(url.openStream())); } - - while (st.hasMoreElements()) + catch (java.net.MalformedURLException ex) { - 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 = 1; + int existingAnnotations = 0; + if(al.getAlignmentAnnotation()!=null) + existingAnnotations = al.getAlignmentAnnotation().length; + int alWidth = al.getWidth(); StringTokenizer st; Annotation[] annotations; @@ -146,30 +100,34 @@ public class AnnotationReader try{ refSeqIndex = Integer.parseInt(st.nextToken()); } - catch(NumberFormatException ex) + catch(Exception ex) { - refSeqIndex = 0; + refSeqIndex = 1; } continue; } + graphStyle = AlignmentAnnotation.getGraphValueFromString(token); label = description = st.nextToken(); line = st.nextToken(); + st = new StringTokenizer(line, "|", true); - annotations = new Annotation[st.countTokens()]; + annotations = new Annotation[alWidth]; + index = 0; boolean emptyColumn = true; - while (st.hasMoreElements()) + + + while (st.hasMoreElements() && index