X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fio%2FFeaturesFile.java;h=462ee22dd65d8260f500437db9f2b22d4abc7bfe;hb=7897c6cb08b496285bcb5fa9ed2d9f7d887d0068;hp=e961683a97a03c83a640efd93b4770b56d9b5178;hpb=3a993bbe274824870c78bd7695c42fa93908cb30;p=jalview.git
diff --git a/src/jalview/io/FeaturesFile.java b/src/jalview/io/FeaturesFile.java
index e961683..462ee22 100755
--- a/src/jalview/io/FeaturesFile.java
+++ b/src/jalview/io/FeaturesFile.java
@@ -1,17 +1,17 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
- *
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
+ * Copyright (C) 2008 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
@@ -25,15 +25,15 @@ import jalview.datamodel.*;
import jalview.schemes.*;
/**
- * Parse and create Jalview Features files
- * Detects GFF format features files and parses.
- * Does not implement standard print() - call specific printFeatures or printGFF.
- * Uses AlignmentI.findSequence(String id) to find the sequence object for the features annotation - this normally works on an exact match.
+ * Parse and create Jalview Features files Detects GFF format features files and
+ * parses. Does not implement standard print() - call specific printFeatures or
+ * printGFF. Uses AlignmentI.findSequence(String id) to find the sequence object
+ * for the features annotation - this normally works on an exact match.
+ *
* @author AMW
* @version $Revision$
*/
-public class FeaturesFile
- extends AlignFile
+public class FeaturesFile extends AlignFile
{
/**
* Creates a new FeaturesFile object.
@@ -44,47 +44,47 @@ public class FeaturesFile
/**
* Creates a new FeaturesFile object.
- *
- * @param inFile DOCUMENT ME!
- * @param type DOCUMENT ME!
- *
- * @throws IOException DOCUMENT ME!
+ *
+ * @param inFile
+ * DOCUMENT ME!
+ * @param type
+ * DOCUMENT ME!
+ *
+ * @throws IOException
+ * DOCUMENT ME!
*/
- public FeaturesFile(String inFile, String type)
- throws IOException
+ public FeaturesFile(String inFile, String type) throws IOException
{
super(inFile, type);
}
+
public FeaturesFile(FileParse source) throws IOException
{
super(source);
}
/**
- * The Application can render HTML, but the applet will
- * remove HTML tags and replace links with %LINK%
- * Both need to read links in HTML however
- *
- * @throws IOException DOCUMENT ME!
+ * The Application can render HTML, but the applet will remove HTML tags and
+ * replace links with %LINK% Both need to read links in HTML however
+ *
+ * @throws IOException
+ * DOCUMENT ME!
*/
- public boolean parse(AlignmentI align,
- Hashtable colours,
- boolean removeHTML)
+ public boolean parse(AlignmentI align, Hashtable colours,
+ boolean removeHTML)
{
return parse(align, colours, null, removeHTML);
}
/**
- * The Application can render HTML, but the applet will
- * remove HTML tags and replace links with %LINK%
- * Both need to read links in HTML however
- *
- * @throws IOException DOCUMENT ME!
+ * The Application can render HTML, but the applet will remove HTML tags and
+ * replace links with %LINK% Both need to read links in HTML however
+ *
+ * @throws IOException
+ * DOCUMENT ME!
*/
- public boolean parse(AlignmentI align,
- Hashtable colours,
- Hashtable featureLink,
- boolean removeHTML)
+ public boolean parse(AlignmentI align, Hashtable colours,
+ Hashtable featureLink, boolean removeHTML)
{
String line = null;
try
@@ -101,7 +101,7 @@ public class FeaturesFile
boolean GFFFile = true;
- while ( (line = nextLine()) != null)
+ while ((line = nextLine()) != null)
{
if (line.startsWith("#"))
{
@@ -124,8 +124,8 @@ public class FeaturesFile
}
else if (type.equalsIgnoreCase("endgroup"))
{
- //We should check whether this is the current group,
- //but at present theres no way of showing more than 1 group
+ // We should check whether this is the current group,
+ // but at present theres no way of showing more than 1 group
st.nextToken();
featureGroup = null;
groupLink = null;
@@ -148,7 +148,7 @@ public class FeaturesFile
}
continue;
}
-
+ String seqId = "";
while (st.hasMoreElements())
{
@@ -156,30 +156,30 @@ public class FeaturesFile
{
// Still possible this is an old Jalview file,
// which does not have type colours at the beginning
- token = st.nextToken();
- seq = align.findName(token, true);
+ seqId = token = st.nextToken();
+ seq = align.findName(seqId, true);
if (seq != null)
{
desc = st.nextToken();
type = st.nextToken();
- try {
- start = Integer.parseInt(st.nextToken());
+ try
+ {
+ start = Integer.parseInt(st.nextToken());
} catch (NumberFormatException ex)
{
- start=0;
+ start = 0;
}
- try {
+ try
+ {
end = Integer.parseInt(st.nextToken());
- }
- catch (NumberFormatException ex)
+ } catch (NumberFormatException ex)
{
- end=-1;
- }
+ end = -1;
+ }
try
{
score = new Float(st.nextToken()).floatValue();
- }
- catch (NumberFormatException ex)
+ } catch (NumberFormatException ex)
{
score = 0;
}
@@ -190,9 +190,9 @@ public class FeaturesFile
{
sf.setValue("STRAND", st.nextToken());
sf.setValue("FRAME", st.nextToken());
+ } catch (Exception ex)
+ {
}
- catch (Exception ex)
- {}
if (st.hasMoreTokens())
{
@@ -205,7 +205,10 @@ public class FeaturesFile
}
seq.addSequenceFeature(sf);
-
+ while ((seq = align.findName(seq, seqId, true)) != null)
+ {
+ seq.addSequenceFeature(new SequenceFeature(sf));
+ }
break;
}
}
@@ -220,26 +223,28 @@ public class FeaturesFile
}
if (!st.hasMoreTokens())
{
- System.err.println("DEBUG: Run out of tokens when trying to identify the destination for the feature.. giving up.");
- // in all probability, this isn't a file we understand, so bail quietly.
+ System.err
+ .println("DEBUG: Run out of tokens when trying to identify the destination for the feature.. giving up.");
+ // in all probability, this isn't a file we understand, so bail
+ // quietly.
return false;
}
-
+
token = st.nextToken();
-
+
if (!token.equals("ID_NOT_SPECIFIED"))
{
- seq = align.findName(token, true);
+ seq = align.findName(seqId = token, true);
st.nextToken();
}
else
{
+ seqId = null;
try
{
index = Integer.parseInt(st.nextToken());
seq = align.getSequenceAt(index);
- }
- catch (NumberFormatException ex)
+ } catch (NumberFormatException ex)
{
seq = null;
}
@@ -265,8 +270,6 @@ public class FeaturesFile
sf = new SequenceFeature(type, desc, "", start, end, featureGroup);
- seq.addSequenceFeature(sf);
-
if (groupLink != null && removeHTML)
{
sf.addLink(groupLink);
@@ -280,12 +283,18 @@ public class FeaturesFile
parseDescriptionHTML(sf, removeHTML);
- //If we got here, its not a GFFFile
+ seq.addSequenceFeature(sf);
+
+ while (seqId != null
+ && (seq = align.findName(seq, seqId, false)) != null)
+ {
+ seq.addSequenceFeature(new SequenceFeature(sf));
+ }
+ // If we got here, its not a GFFFile
GFFFile = false;
}
}
- }
- catch (Exception ex)
+ } catch (Exception ex)
{
System.out.println(line);
System.out.println("Error parsing feature file: " + ex + "\n" + line);
@@ -303,7 +312,8 @@ public class FeaturesFile
return;
}
- if (removeHTML && sf.getDescription().toUpperCase().indexOf("") == -1)
+ if (removeHTML
+ && sf.getDescription().toUpperCase().indexOf("") == -1)
{
removeHTML = false;
}
@@ -371,40 +381,58 @@ public class FeaturesFile
}
/**
- * DOCUMENT ME!
- *
- * @param s DOCUMENT ME!
- * @param len DOCUMENT ME!
- * @param gaps DOCUMENT ME!
- * @param displayId DOCUMENT ME!
- *
- * @return DOCUMENT ME!
+ * generate a features file for seqs
+ *
+ * @param seqs
+ * source of sequence features
+ * @param visible
+ * hash of feature types and colours
+ * @return features file contents
+ */
+ public String printJalviewFormat(SequenceI[] seqs, Hashtable visible)
+ {
+ return printJalviewFormat(seqs, visible, true);
+ }
+
+ /**
+ * generate a features file for seqs with colours from visible (if any)
+ *
+ * @param seqs
+ * source of features
+ * @param visible
+ * hash of Colours for each feature type
+ * @param visOnly
+ * when true only feature types in 'visible' will be output
+ * @return features file contents
*/
- public String printJalviewFormat(SequenceI[] seqs,
- Hashtable visible)
+ public String printJalviewFormat(SequenceI[] seqs, Hashtable visible,
+ boolean visOnly)
{
StringBuffer out = new StringBuffer();
SequenceFeature[] next;
- if (visible == null || visible.size() < 1)
+ if (visOnly && (visible == null || visible.size() < 1))
{
return "No Features Visible";
}
-
- Enumeration en = visible.keys();
- String type;
- int color;
- while (en.hasMoreElements())
+ if (visible != null && visOnly)
{
- type = en.nextElement().toString();
- color = Integer.parseInt(visible.get(type).toString());
- out.append(type + "\t"
- + jalview.util.Format.getHexString(
- new java.awt.Color(color))
- + "\n");
+ // write feature colours only if we're given them and we are generating
+ // viewed features
+ Enumeration en = visible.keys();
+ String type;
+ int color;
+ while (en.hasMoreElements())
+ {
+ type = en.nextElement().toString();
+ color = Integer.parseInt(visible.get(type).toString());
+ out.append(type
+ + "\t"
+ + jalview.util.Format
+ .getHexString(new java.awt.Color(color)) + "\n");
+ }
}
-
- //Work out which groups are both present and visible
+ // Work out which groups are both present and visible
Vector groups = new Vector();
int groupIndex = 0;
@@ -415,13 +443,13 @@ public class FeaturesFile
{
for (int j = 0; j < next.length; j++)
{
- if (!visible.containsKey(next[j].type))
+ if (visOnly && !visible.containsKey(next[j].type))
{
continue;
}
if (next[j].featureGroup != null
- && !groups.contains(next[j].featureGroup))
+ && !groups.contains(next[j].featureGroup))
{
groups.addElement(next[j].featureGroup);
}
@@ -451,15 +479,14 @@ public class FeaturesFile
{
for (int j = 0; j < next.length; j++)
{
- if (!visible.containsKey(next[j].type))
+ if (visOnly && !visible.containsKey(next[j].type))
{
continue;
}
if (group != null
- && (next[j].featureGroup == null
- || !next[j].featureGroup.equals(group))
- )
+ && (next[j].featureGroup == null || !next[j].featureGroup
+ .equals(group)))
{
continue;
}
@@ -469,14 +496,15 @@ public class FeaturesFile
continue;
}
- if (next[j].description == null || next[j].description.equals(""))
+ if (next[j].description == null
+ || next[j].description.equals(""))
{
out.append(next[j].type + "\t");
}
else
{
if (next[j].links != null
- && next[j].getDescription().indexOf("") == -1)
+ && next[j].getDescription().indexOf("") == -1)
{
out.append("");
}
@@ -492,11 +520,9 @@ public class FeaturesFile
if (next[j].description.indexOf(href) == -1)
{
- out.append(""
- + label
- + "");
+ out
+ .append("" + label
+ + "");
}
}
@@ -509,11 +535,8 @@ public class FeaturesFile
out.append("\t");
}
- out.append(seqs[i].getName() + "\t-1\t"
- + next[j].begin + "\t"
- + next[j].end + "\t"
- + next[j].type + "\n"
- );
+ out.append(seqs[i].getName() + "\t-1\t" + next[j].begin + "\t"
+ + next[j].end + "\t" + next[j].type + "\n");
}
}
}
@@ -528,14 +551,19 @@ public class FeaturesFile
break;
}
- }
- while (groupIndex < groups.size() + 1);
+ } while (groupIndex < groups.size() + 1);
return out.toString();
}
public String printGFFFormat(SequenceI[] seqs, Hashtable visible)
{
+ return printGFFFormat(seqs, visible, true);
+ }
+
+ public String printGFFFormat(SequenceI[] seqs, Hashtable visible,
+ boolean visOnly)
+ {
StringBuffer out = new StringBuffer();
SequenceFeature[] next;
String source;
@@ -547,7 +575,7 @@ public class FeaturesFile
next = seqs[i].getSequenceFeatures();
for (int j = 0; j < next.length; j++)
{
- if (!visible.containsKey(next[j].type))
+ if (visOnly && !visible.containsKey(next[j].type))
{
continue;
}
@@ -558,13 +586,9 @@ public class FeaturesFile
source = next[j].getDescription();
}
- out.append(seqs[i].getName() + "\t"
- + source + "\t"
- + next[j].type + "\t"
- + next[j].begin + "\t"
- + next[j].end + "\t"
- + next[j].score + "\t"
- );
+ out.append(seqs[i].getName() + "\t" + source + "\t"
+ + next[j].type + "\t" + next[j].begin + "\t"
+ + next[j].end + "\t" + next[j].score + "\t");
if (next[j].getValue("STRAND") != null)
{
@@ -598,15 +622,18 @@ public class FeaturesFile
return out.toString();
}
+ /**
+ * this is only for the benefit of object polymorphism - method does nothing.
+ */
public void parse()
{
- //IGNORED
+ // IGNORED
}
/**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
+ * this is only for the benefit of object polymorphism - method does nothing.
+ *
+ * @return error message
*/
public String print()
{