X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FAnnotationFile.java;h=1b7b72a70f267ed4539b43fe31957e9d9b8ca311;hb=7bc226b58110fa26d9dbd3f0c78095d06909ffc3;hp=8ec234d12128745ff90f873ed3fa50611d9448c0;hpb=dd74fc4938723fe5ec48d4e5fdcfbe58ac42a48d;p=jalview.git diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index 8ec234d..1b7b72a 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2007 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 @@ -20,24 +20,24 @@ package jalview.io; import java.io.*; -import jalview.datamodel.*; +import java.net.*; import java.util.*; -import java.net.URL; -import jalview.schemes.*; -import jalview.analysis.Conservation; +import jalview.analysis.*; +import jalview.datamodel.*; +import jalview.schemes.*; public class AnnotationFile { StringBuffer text = new StringBuffer( - "JALVIEW_ANNOTATION\n" - +"# Created: " - +new java.util.Date()+"\n\n"); + "JALVIEW_ANNOTATION\n" + + "# Created: " + + new java.util.Date() + "\n\n"); - public String printAnnotations(AlignmentAnnotation [] annotations, - Vector groups) + public String printAnnotations(AlignmentAnnotation[] annotations, + Vector groups) { - if(annotations!=null) + if (annotations != null) { AlignmentAnnotation row; String comma; @@ -55,14 +55,18 @@ public class AnnotationFile row = annotations[i]; if (!row.visible) + { continue; + } color = null; if (row.sequenceRef == null) { if (seqref != null) + { text.append("\nSEQUENCE_REF\tALIGNMENT\n"); + } seqref = null; } @@ -80,11 +84,16 @@ public class AnnotationFile else { if (row.graph == AlignmentAnnotation.BAR_GRAPH) + { text.append("BAR_GRAPH\t"); + } else if (row.graph == AlignmentAnnotation.LINE_GRAPH) + { text.append("LINE_GRAPH\t"); + } if (row.getThreshold() != null) + { graphLine.append("GRAPHLINE\t" + row.label + "\t" + row.getThreshold().value + "\t" @@ -92,27 +101,36 @@ public class AnnotationFile + jalview.util.Format.getHexString( row.getThreshold().colour) + "\n" ); + } if (row.graphGroup > -1) { String key = String.valueOf(row.graphGroup); if (graphGroup.containsKey(key)) + { graphGroup.put(key, graphGroup.get(key) + "\t" + row.label); + } else + { graphGroup.put(key, row.label); + } } } text.append(row.label + "\t"); if (row.description != null) + { text.append(row.description + "\t"); + } for (int j = 0; j < row.annotations.length; j++) { if (seqref != null && jalview.util.Comparison.isGap(seqref.getCharAt(j))) + { continue; + } if (row.annotations[j] != null) { @@ -133,7 +151,9 @@ public class AnnotationFile { color = row.annotations[j].colour; if (row.annotations[j].value != 0f) + { text.append(comma + row.annotations[j].value); + } } } text.append("|"); @@ -165,8 +185,7 @@ public class AnnotationFile } } - - if(groups!=null) + if (groups != null) { printGroups(groups); } @@ -174,7 +193,6 @@ public class AnnotationFile return text.toString(); } - public void printGroups(Vector sequenceGroups) { SequenceGroup sg; @@ -183,47 +201,60 @@ public class AnnotationFile sg = (SequenceGroup) sequenceGroups.elementAt(i); text.append("SEQUENCE_GROUP\t" + sg.getName() + "\t" - + (sg.getStartRes()+1) + "\t" - + (sg.getEndRes()+1) + "\t" + "-1\t"); - for(int s=0; s -1) { @@ -281,7 +316,7 @@ public class AnnotationFile } } - if(!jvAnnotationFile) + if (!jvAnnotationFile) { in.close(); return false; @@ -289,20 +324,22 @@ public class AnnotationFile while ( (line = in.readLine()) != null) { - if(line.indexOf("#")==0 - || line.indexOf("JALVIEW_ANNOTATION")>-1 - || line.length()==0) + if (line.indexOf("#") == 0 + || line.indexOf("JALVIEW_ANNOTATION") > -1 + || line.length() == 0) + { continue; + } st = new StringTokenizer(line, "\t"); token = st.nextToken(); - if(token.equalsIgnoreCase("COLOUR")) + if (token.equalsIgnoreCase("COLOUR")) { colourAnnotations(al, st.nextToken(), st.nextToken()); continue; } - else if(token.equalsIgnoreCase("COMBINE") ) + else if (token.equalsIgnoreCase("COMBINE")) { combineAnnotations(al, st); continue; @@ -314,46 +351,50 @@ public class AnnotationFile continue; } - - else if(token.equalsIgnoreCase("SEQUENCE_REF") ) + else if (token.equalsIgnoreCase("SEQUENCE_REF")) { refSeq = al.findName(st.nextToken()); - try{ + try + { refSeqIndex = Integer.parseInt(st.nextToken()); - if(refSeqIndex<1) + if (refSeqIndex < 1) { refSeqIndex = 1; - System.out.println("WARNING: SEQUENCE_REF index must be > 0 in AnnotationFile"); + System.out.println( + "WARNING: SEQUENCE_REF index must be > 0 in AnnotationFile"); } } - catch(Exception ex) + catch (Exception ex) { refSeqIndex = 1; } - continue; + continue ; } - else if(token.equalsIgnoreCase("SEQUENCE_GROUP")) + else if (token.equalsIgnoreCase("SEQUENCE_GROUP")) { addGroup(al, st); continue; } - else if(token.equalsIgnoreCase("PROPERTIES")) + else if (token.equalsIgnoreCase("PROPERTIES")) { addProperties(al, st); continue; } - graphStyle = AlignmentAnnotation.getGraphValueFromString(token); label = st.nextToken(); - if(st.countTokens()>1) + if (st.countTokens() > 1) + { description = st.nextToken(); + } else + { description = null; + } line = st.nextToken(); @@ -363,14 +404,15 @@ public class AnnotationFile index = 0; boolean emptyColumn = true; - - while (st.hasMoreElements() && index1 && desc.length()==1) + if (displayChar.length() > 1 && desc.length() == 1) { String tmp = displayChar; displayChar = desc; @@ -462,15 +518,17 @@ public class AnnotationFile { UserColourScheme ucs = new UserColourScheme(colour); Annotation[] annotations; - for(int i=0; i start) + { for (int i = start; i <= end; i++) - sg.addSequence(al.getSequenceAt(i-1), false); + { + sg.addSequence(al.getSequenceAt(i - 1), false); + } + } } else { - sg.addSequence(al.getSequenceAt(Integer.parseInt(tmp)-1 ), false); + sg.addSequence(al.getSequenceAt(Integer.parseInt(tmp) - 1), false); } } } - if(refSeq!=null) + if (refSeq != null) { - sg.setStartRes( refSeq.findIndex( sg.getStartRes()+1 )-1 ); - sg.setEndRes( refSeq.findIndex( sg.getEndRes() +1) -1 ); + sg.setStartRes(refSeq.findIndex(sg.getStartRes() + 1) - 1); + sg.setEndRes(refSeq.findIndex(sg.getEndRes() + 1) - 1); } - if(sg.getSize()>0) + if (sg.getSize() > 0) { al.addGroup(sg); } @@ -599,35 +663,45 @@ public class AnnotationFile //So far we have only added groups to the annotationHash, //the idea is in the future properties can be added to //alignments, other annotations etc - if(al.getGroups()==null) + if (al.getGroups() == null) + { return; + } SequenceGroup sg = null; String name = st.nextToken(); Vector groups = al.getGroups(); - for(int i=0; i