From 544ccf2cea9d02873528cc8be4ca1682d56cfaad Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 14 Dec 2006 18:42:25 +0000 Subject: [PATCH] Are the labels all secondary Strutures? are the displayChars actually descriptions? --- src/jalview/datamodel/AlignmentAnnotation.java | 74 ++++++++++++++---------- src/jalview/io/AnnotationFile.java | 40 +++++++++---- 2 files changed, 75 insertions(+), 39 deletions(-) diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index c3396b6..7c57e6b 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -103,21 +103,53 @@ public class AlignmentAnnotation this.description = description; this.annotations = annotations; - for (int i = 0; i < annotations.length; i++) + areLabelsSecondaryStructure(); + } + + void areLabelsSecondaryStructure() + { + boolean nonSSLabel = false; + for (int i = 0; i < annotations.length; i++) + { + if(annotations[i]==null) + continue; + + if (annotations[i].secondaryStructure == 'H' || + annotations[i].secondaryStructure == 'E') { - if ((annotations[i] != null) && - ((annotations[i].secondaryStructure == 'H') || - (annotations[i].secondaryStructure == 'E'))) - { - hasIcons = true; - } + hasIcons = true; + } + + if (annotations[i].secondaryStructure != 'H' + && annotations[i].secondaryStructure != 'E') + { + nonSSLabel = true; + } + + if (annotations[i].displayCharacter.length() > 0) + { + hasText = true; + } + } + + if(nonSSLabel) + { + hasIcons = false; + for (int j = 0; j < annotations.length; j++) + { + if(annotations[j] !=null && annotations[j].secondaryStructure!=' ') + { + annotations[j].displayCharacter + =String.valueOf(annotations[j].secondaryStructure); + annotations[j].secondaryStructure = ' '; + if(annotations[j].description.length()<1) + annotations[j].description = annotations[j].displayCharacter; + } - if ((annotations[i] != null) && - (annotations[i].displayCharacter.length() > 0)) - { - hasText = true; - } } + + } + } /** @@ -171,23 +203,7 @@ public class AlignmentAnnotation graphMin = min; graphMax = max; - for (int i = 0; i < annotations.length; i++) - { - if (!hasIcons - && annotations[i] != null - && ((annotations[i].secondaryStructure == 'H') || - (annotations[i].secondaryStructure == 'E'))) - { - hasIcons = true; - } - - if (!hasText - && annotations[i]!=null - && annotations[i].displayCharacter.length() > 0) - { - hasText = true; - } - } + areLabelsSecondaryStructure(); if(!drawValues && graphType!=NO_GRAPH) { diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index 77f8810..a211d1a 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -38,7 +38,7 @@ public class AnnotationFile AlignmentAnnotation row; String comma; - String seqref = null; + SequenceI seqref = null; StringBuffer colours = new StringBuffer(); StringBuffer graphLine = new StringBuffer(); @@ -55,11 +55,10 @@ public class AnnotationFile if( row.sequenceRef == null) seqref = null; - else if (seqref == null - || !seqref.equals(row.sequenceRef.getName())) + else if (seqref == null || seqref != row.sequenceRef) { - seqref = row.sequenceRef.getName(); - text.append("\nSEQUENCE_REF\t" + seqref + "\n"); + seqref = row.sequenceRef; + text.append("\nSEQUENCE_REF\t" + seqref.getName() + "\n"); } @@ -98,6 +97,9 @@ public class AnnotationFile for(int j=0; j 0 + if (row.annotations[j].displayCharacter.length() > 0 && !row.annotations[j].displayCharacter.equals(" ")) { text.append(comma + row.annotations[j].displayCharacter); comma = ","; } - if (row.annotations[j].value!=0f) + + if (row.annotations[j]!=null) { color = row.annotations[j].colour; - text.append(comma + row.annotations[j].value); + if (row.annotations[j].value!=0f) + text.append(comma + row.annotations[j].value); } } text.append("|"); @@ -239,6 +243,11 @@ public class AnnotationFile refSeq = al.findName(st.nextToken()); try{ refSeqIndex = Integer.parseInt(st.nextToken()); + if(refSeqIndex<1) + { + refSeqIndex = 1; + System.out.println("WARNING: SEQUENCE_REF index must be > 0 in AnnotationFile"); + } } catch(Exception ex) { @@ -307,7 +316,7 @@ public class AnnotationFile Annotation parseAnnotation(String string) { - String desc = "", displayChar=""; + String desc = null, displayChar=""; char ss = ' '; // secondaryStructure float value = 0; boolean parsedValue = false; @@ -325,6 +334,7 @@ public class AnnotationFile displayChar = token; value = new Float(token).floatValue(); parsedValue = true; + continue; }catch(NumberFormatException ex){} } @@ -336,11 +346,21 @@ public class AnnotationFile if(displayChar.equals(token.substring(0,1))) displayChar = ""; } - else if(desc.length()<1) + else if(desc==null) desc = token; } + if(desc == null) + desc = value+""; + + if(displayChar.length()>1 && desc.length()==1) + { + String tmp = displayChar; + displayChar = desc; + desc = tmp; + } + return new Annotation(displayChar, desc, ss, value); } -- 1.7.10.2