From: amwaterhouse Date: Mon, 30 Jan 2006 14:46:15 +0000 (+0000) Subject: New files X-Git-Tag: Root_VamJalview_2_07b+~211 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=e9d286eaa2ec9b85d1d2634ba53401fa65cf21bc;p=jalview.git New files --- diff --git a/src/jalview/datamodel/GraphLine.java b/src/jalview/datamodel/GraphLine.java new file mode 100755 index 0000000..2f484ac --- /dev/null +++ b/src/jalview/datamodel/GraphLine.java @@ -0,0 +1,37 @@ +/* +* Jalview - A Sequence Alignment Editor and Viewer +* Copyright (C) 2005 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 +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +*/ +package jalview.datamodel; + +public class GraphLine +{ + public float value; + public String label = ""; + public java.awt.Color colour = java.awt.Color.black; + public boolean displayed = true; + + public GraphLine(float value, String label, java.awt.Color col) + { + this.value = value; + if(label != null) + this.label = label; + + if(col != null ) + this.colour = col; + } +} diff --git a/src/jalview/io/AnnotationReader.java b/src/jalview/io/AnnotationReader.java new file mode 100755 index 0000000..5ba1e26 --- /dev/null +++ b/src/jalview/io/AnnotationReader.java @@ -0,0 +1,319 @@ +package jalview.io; + +import java.io.*; +import jalview.datamodel.*; +import java.util.StringTokenizer; +import jalview.schemes.UserColourScheme; +import jalview.gui.FeatureRenderer; + +public class AnnotationReader +{ + public boolean readGroupsFile(FeatureRenderer fr, 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) + { + 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); + } + } + } + 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; + + + StringTokenizer st; + Annotation[] annotations; + AlignmentAnnotation annotation = null; + + // First confirm this is an Annotation file + boolean jvAnnotationFile = false; + while ( (line = in.readLine()) != null) + { + if (line.indexOf("#") == 0 ) + continue; + + if (line.indexOf("JALVIEW_ANNOTATION") > -1) + { + jvAnnotationFile = true; + break; + } + } + + if(!jvAnnotationFile) + { + in.close(); + return false; + } + + while ( (line = in.readLine()) != null) + { + 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")) + { + colourAnnotations(al, st.nextToken(), st.nextToken()); + continue; + } + + if(token.equalsIgnoreCase("COMBINE") ) + { + combineAnnotations(al, st); + continue; + } + + if (token.equalsIgnoreCase("GRAPHLINE")) + { + addLine(al, st); + continue; + } + + + if(token.equalsIgnoreCase("SEQUENCE_REF") ) + { + refSeq = al.findName(st.nextToken()); + try{ + refSeqIndex = Integer.parseInt(st.nextToken()); + } + catch(NumberFormatException ex) + { + refSeqIndex = 0; + } + + continue; + } + + graphStyle = AlignmentAnnotation.getGraphValueFromString(token); + label = description = st.nextToken(); + + line = st.nextToken(); + st = new StringTokenizer(line, "|", true); + annotations = new Annotation[st.countTokens()]; + index = 0; + boolean emptyColumn = true; + while (st.hasMoreElements()) + { + token = st.nextToken().trim(); + + if(token.equals("|")) + { + if(emptyColumn) + annotations[index++] = parseAnnotation(""); + + emptyColumn = true; + } + else + { + annotations[index++] = parseAnnotation(token); + emptyColumn = false; + } + } + + annotation = new AlignmentAnnotation(label, + description, + annotations, + 0, + 0, + graphStyle); + + al.addAnnotation(annotation, refSeq, refSeqIndex); + + } + }catch(Exception ex) + {ex.printStackTrace(); + // System.out.println("Problem reading annotation file: "+ex); + return false; + } + return true; + } + + Annotation parseAnnotation(String string) + { + String desc = "", displayChar=""; + char ss = ' '; // secondaryStructure + float value = 0; + StringTokenizer st = new StringTokenizer(string, ","); + String token; + while(st.hasMoreTokens()) + { + token = st.nextToken().trim(); + if(token.length()==0) + continue; + + if(value==0) + { try{ + value = Float.parseFloat(token); + }catch(NumberFormatException ex){} + } + + if(token.length()==1) + { + // Either this character represents a helix or sheet + // or an integer which can be displayed + if(token.equals("H") || token.equals("E")) + { + ss = token.charAt(0); + } + else //if(value!=0) + { + displayChar = token; + } + } + else if(desc.length()<1) + desc = token; + else + displayChar = token; + } + + return new Annotation(displayChar, desc, ss, value); + } + + void colourAnnotations(AlignmentI al, String label, String colour) + { + UserColourScheme ucs = new UserColourScheme(colour); + Annotation[] annotations; + for(int i=0; i=annotation.getGraphLine(0).value)) + { + dr = rr * + ((annotation.annotations[j].value-annotation.graphMin) / range ) + +r1; + dg = gg * + ((annotation.annotations[j].value-annotation.graphMin) / range ) + +g1; + db = bb * + ((annotation.annotations[j].value-annotation.graphMin) / range ) + +b1; + + currentColour = new Color( (int) dr, (int) dg, (int) db); + } + else + currentColour = Color.white; + } + } + else + { + return Color.white; + } + + if(conservationColouring) + applyConservation(j); + + return currentColour; + } +}