2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.SequenceIdMatcher;
24 import jalview.datamodel.AlignedCodonFrame;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.SequenceDummy;
27 import jalview.datamodel.SequenceFeature;
28 import jalview.datamodel.SequenceI;
29 import jalview.schemes.AnnotationColourGradient;
30 import jalview.schemes.GraduatedColor;
31 import jalview.schemes.UserColourScheme;
32 import jalview.util.Format;
33 import jalview.util.MapList;
35 import java.io.IOException;
36 import java.util.ArrayList;
37 import java.util.Arrays;
38 import java.util.HashMap;
39 import java.util.Hashtable;
40 import java.util.Iterator;
41 import java.util.List;
43 import java.util.StringTokenizer;
44 import java.util.Vector;
47 * Parse and create Jalview Features files Detects GFF format features files and
48 * parses. Does not implement standard print() - call specific printFeatures or
49 * printGFF. Uses AlignmentI.findSequence(String id) to find the sequence object
50 * for the features annotation - this normally works on an exact match.
55 public class FeaturesFile extends AlignFile
58 * work around for GFF interpretation bug where source string becomes
59 * description rather than a group
61 private boolean doGffSource = true;
64 * Creates a new FeaturesFile object.
71 * Creates a new FeaturesFile object.
81 public FeaturesFile(String inFile, String type) throws IOException
86 public FeaturesFile(FileParse source) throws IOException
92 * Parse GFF or sequence features file using case-independent matching,
96 * - alignment/dataset containing sequences that are to be annotated
98 * - hashtable to store feature colour definitions
100 * - process html strings into plain text
101 * @return true if features were added
103 public boolean parse(AlignmentI align, Hashtable colours,
106 return parse(align, colours, null, removeHTML, false);
110 * Parse GFF or sequence features file optionally using case-independent
111 * matching, discarding URLs
114 * - alignment/dataset containing sequences that are to be annotated
116 * - hashtable to store feature colour definitions
118 * - process html strings into plain text
119 * @param relaxedIdmatching
120 * - when true, ID matches to compound sequence IDs are allowed
121 * @return true if features were added
123 public boolean parse(AlignmentI align, Map colours, boolean removeHTML,
124 boolean relaxedIdMatching)
126 return parse(align, colours, null, removeHTML, relaxedIdMatching);
130 * Parse GFF or sequence features file optionally using case-independent
134 * - alignment/dataset containing sequences that are to be annotated
136 * - hashtable to store feature colour definitions
138 * - hashtable to store associated URLs
140 * - process html strings into plain text
141 * @return true if features were added
143 public boolean parse(AlignmentI align, Map colours, Map featureLink,
146 return parse(align, colours, featureLink, removeHTML, false);
150 * Parse GFF or sequence features file
153 * - alignment/dataset containing sequences that are to be annotated
155 * - hashtable to store feature colour definitions
157 * - hashtable to store associated URLs
159 * - process html strings into plain text
160 * @param relaxedIdmatching
161 * - when true, ID matches to compound sequence IDs are allowed
162 * @return true if features were added
164 public boolean parse(AlignmentI align, Map colours, Map featureLink,
165 boolean removeHTML, boolean relaxedIdmatching)
171 SequenceI seq = null;
173 * keep track of any sequences we try to create from the data if it is a GFF3 file
175 ArrayList<SequenceI> newseqs = new ArrayList<SequenceI>();
176 String type, desc, token = null;
178 int index, start, end;
182 String featureGroup = null, groupLink = null;
183 Map typeLink = new Hashtable();
185 * when true, assume GFF style features rather than Jalview style.
187 boolean GFFFile = true;
188 while ((line = nextLine()) != null)
190 if (line.startsWith("#"))
195 st = new StringTokenizer(line, "\t");
196 if (st.countTokens() == 1)
198 if (line.trim().equalsIgnoreCase("GFF"))
200 // Start parsing file as if it might be GFF again.
205 if (st.countTokens() > 1 && st.countTokens() < 4)
208 type = st.nextToken();
209 if (type.equalsIgnoreCase("startgroup"))
211 featureGroup = st.nextToken();
212 if (st.hasMoreElements())
214 groupLink = st.nextToken();
215 featureLink.put(featureGroup, groupLink);
218 else if (type.equalsIgnoreCase("endgroup"))
220 // We should check whether this is the current group,
221 // but at present theres no way of showing more than 1 group
228 Object colour = null;
229 String colscheme = st.nextToken();
230 if (colscheme.indexOf("|") > -1
231 || colscheme.trim().equalsIgnoreCase("label"))
233 // Parse '|' separated graduated colourscheme fields:
234 // [label|][mincolour|maxcolour|[absolute|]minvalue|maxvalue|thresholdtype|thresholdvalue]
235 // can either provide 'label' only, first is optional, next two
236 // colors are required (but may be
237 // left blank), next is optional, nxt two min/max are required.
238 // first is either 'label'
239 // first/second and third are both hexadecimal or word equivalent
241 // next two are values parsed as floats.
242 // fifth is either 'above','below', or 'none'.
243 // sixth is a float value and only required when fifth is either
244 // 'above' or 'below'.
245 StringTokenizer gcol = new StringTokenizer(colscheme, "|",
248 int threshtype = AnnotationColourGradient.NO_THRESHOLD;
249 float min = Float.MIN_VALUE, max = Float.MAX_VALUE, threshval = Float.NaN;
250 boolean labelCol = false;
252 String mincol = gcol.nextToken();
256 .println("Expected either 'label' or a colour specification in the line: "
260 String maxcol = null;
261 if (mincol.toLowerCase().indexOf("label") == 0)
264 mincol = (gcol.hasMoreTokens() ? gcol.nextToken() : null); // skip
266 mincol = (gcol.hasMoreTokens() ? gcol.nextToken() : null);
268 String abso = null, minval, maxval;
271 // at least four more tokens
272 if (mincol.equals("|"))
278 gcol.nextToken(); // skip next '|'
280 // continue parsing rest of line
281 maxcol = gcol.nextToken();
282 if (maxcol.equals("|"))
288 gcol.nextToken(); // skip next '|'
290 abso = gcol.nextToken();
291 gcol.nextToken(); // skip next '|'
292 if (abso.toLowerCase().indexOf("abso") != 0)
299 minval = gcol.nextToken();
300 gcol.nextToken(); // skip next '|'
302 maxval = gcol.nextToken();
303 if (gcol.hasMoreTokens())
305 gcol.nextToken(); // skip next '|'
309 if (minval.length() > 0)
311 min = new Float(minval).floatValue();
313 } catch (Exception e)
316 .println("Couldn't parse the minimum value for graduated colour for type ("
318 + ") - did you misspell 'auto' for the optional automatic colour switch ?");
323 if (maxval.length() > 0)
325 max = new Float(maxval).floatValue();
327 } catch (Exception e)
330 .println("Couldn't parse the maximum value for graduated colour for type ("
337 // add in some dummy min/max colours for the label-only
344 colour = new jalview.schemes.GraduatedColor(
345 new UserColourScheme(mincol).findColour('A'),
346 new UserColourScheme(maxcol).findColour('A'), min,
348 } catch (Exception e)
351 .println("Couldn't parse the graduated colour scheme ("
357 ((jalview.schemes.GraduatedColor) colour)
358 .setColourByLabel(labelCol);
359 ((jalview.schemes.GraduatedColor) colour)
360 .setAutoScaled(abso == null);
361 // add in any additional parameters
362 String ttype = null, tval = null;
363 if (gcol.hasMoreTokens())
365 // threshold type and possibly a threshold value
366 ttype = gcol.nextToken();
367 if (ttype.toLowerCase().startsWith("below"))
369 ((jalview.schemes.GraduatedColor) colour)
370 .setThreshType(AnnotationColourGradient.BELOW_THRESHOLD);
372 else if (ttype.toLowerCase().startsWith("above"))
374 ((jalview.schemes.GraduatedColor) colour)
375 .setThreshType(AnnotationColourGradient.ABOVE_THRESHOLD);
379 ((jalview.schemes.GraduatedColor) colour)
380 .setThreshType(AnnotationColourGradient.NO_THRESHOLD);
381 if (!ttype.toLowerCase().startsWith("no"))
384 .println("Ignoring unrecognised threshold type : "
389 if (((GraduatedColor) colour).getThreshType() != AnnotationColourGradient.NO_THRESHOLD)
394 tval = gcol.nextToken();
395 ((jalview.schemes.GraduatedColor) colour)
396 .setThresh(new Float(tval).floatValue());
397 } catch (Exception e)
400 .println("Couldn't parse threshold value as a float: ("
405 // parse the thresh-is-min token ?
406 if (gcol.hasMoreTokens())
409 .println("Ignoring additional tokens in parameters in graduated colour specification\n");
410 while (gcol.hasMoreTokens())
412 System.err.println("|" + gcol.nextToken());
414 System.err.println("\n");
420 UserColourScheme ucs = new UserColourScheme(colscheme);
421 colour = ucs.findColour('A');
425 colours.put(type, colour);
427 if (st.hasMoreElements())
429 String link = st.nextToken();
430 typeLink.put(type, link);
431 if (featureLink == null)
433 featureLink = new Hashtable();
435 featureLink.put(type, link);
441 while (st.hasMoreElements())
446 // Still possible this is an old Jalview file,
447 // which does not have type colours at the beginning
448 seqId = token = st.nextToken();
449 seq = findName(align, seqId, relaxedIdmatching, newseqs);
452 desc = st.nextToken();
454 if (doGffSource && desc.indexOf(' ') == -1)
456 // could also be a source term rather than description line
457 group = new String(desc);
459 type = st.nextToken();
462 String stt = st.nextToken();
463 if (stt.length() == 0 || stt.equals("-"))
469 start = Integer.parseInt(stt);
471 } catch (NumberFormatException ex)
477 String stt = st.nextToken();
478 if (stt.length() == 0 || stt.equals("-"))
484 end = Integer.parseInt(stt);
486 } catch (NumberFormatException ex)
490 // TODO: decide if non positional feature assertion for input data
491 // where end==0 is generally valid
494 // treat as non-positional feature, regardless.
499 score = new Float(st.nextToken()).floatValue();
500 } catch (NumberFormatException ex)
505 sf = new SequenceFeature(type, desc, start, end, score, group);
509 sf.setValue("STRAND", st.nextToken());
510 sf.setValue("FRAME", st.nextToken());
511 } catch (Exception ex)
515 if (st.hasMoreTokens())
517 StringBuffer attributes = new StringBuffer();
519 while (st.hasMoreTokens())
521 attributes.append((sep ? "\t" : "") + st.nextElement());
524 // TODO validate and split GFF2 attributes field ? parse out
525 // ([A-Za-z][A-Za-z0-9_]*) <value> ; and add as
526 // sf.setValue(attrib, val);
527 sf.setValue("ATTRIBUTES", attributes.toString());
530 if (processOrAddSeqFeature(align, newseqs, seq, sf, GFFFile,
533 // check whether we should add the sequence feature to any other
534 // sequences in the alignment with the same or similar
535 while ((seq = align.findName(seq, seqId, true)) != null)
537 seq.addSequenceFeature(new SequenceFeature(sf));
544 if (GFFFile && seq == null)
550 desc = st.nextToken();
552 if (!st.hasMoreTokens())
555 .println("DEBUG: Run out of tokens when trying to identify the destination for the feature.. giving up.");
556 // in all probability, this isn't a file we understand, so bail
561 token = st.nextToken();
563 if (!token.equals("ID_NOT_SPECIFIED"))
565 seq = findName(align, seqId = token, relaxedIdmatching, null);
573 index = Integer.parseInt(st.nextToken());
574 seq = align.getSequenceAt(index);
575 } catch (NumberFormatException ex)
583 System.out.println("Sequence not found: " + line);
587 start = Integer.parseInt(st.nextToken());
588 end = Integer.parseInt(st.nextToken());
590 type = st.nextToken();
592 if (!colours.containsKey(type))
594 // Probably the old style groups file
595 UserColourScheme ucs = new UserColourScheme(type);
596 colours.put(type, ucs.findColour('A'));
598 sf = new SequenceFeature(type, desc, "", start, end, featureGroup);
599 if (st.hasMoreTokens())
603 score = new Float(st.nextToken()).floatValue();
604 // update colourgradient bounds if allowed to
605 } catch (NumberFormatException ex)
611 if (groupLink != null && removeHTML)
613 sf.addLink(groupLink);
614 sf.description += "%LINK%";
616 if (typeLink.containsKey(type) && removeHTML)
618 sf.addLink(typeLink.get(type).toString());
619 sf.description += "%LINK%";
622 parseDescriptionHTML(sf, removeHTML);
624 seq.addSequenceFeature(sf);
627 && (seq = align.findName(seq, seqId, false)) != null)
629 seq.addSequenceFeature(new SequenceFeature(sf));
631 // If we got here, its not a GFFFile
636 } catch (Exception ex)
638 System.out.println("Error parsing feature file: " + ex + "\n" + line);
639 ex.printStackTrace(System.err);
649 * take a sequence feature and examine its attributes to decide how it should
650 * be added to a sequence
653 * - the destination sequence constructed or discovered in the
656 * - the base feature with ATTRIBUTES property containing any
657 * additional attributes
659 * - true if we are processing a GFF annotation file
660 * @return true if sf was actually added to the sequence, false if it was
661 * processed in another way
663 public boolean processOrAddSeqFeature(AlignmentI align, List<SequenceI> newseqs, SequenceI seq, SequenceFeature sf,
664 boolean gFFFile, boolean relaxedIdMatching)
666 String attr = (String) sf.getValue("ATTRIBUTES");
668 if (gFFFile && attr != null)
672 for (String attset : attr.split("\t"))
674 if (attset==null || attset.trim().length()==0)
679 Map<String, List<String>> set = new HashMap<String, List<String>>();
680 // normally, only expect one column - 9 - in this field
681 // the attributes (Gff3) or groups (gff2) field
682 for (String pair : attset.trim().split(";"))
685 if (pair.length() == 0)
690 // expect either space seperated (gff2) or '=' separated (gff3)
691 // key/value pairs here
693 int eqpos = pair.indexOf('='),sppos = pair.indexOf(' ');
694 String key = null, value = null;
696 if (sppos > -1 && (eqpos == -1 || sppos < eqpos))
698 key = pair.substring(0, sppos);
699 value = pair.substring(sppos + 1);
701 if (eqpos > -1 && (sppos == -1 || eqpos < sppos))
703 key = pair.substring(0, eqpos);
704 value = pair.substring(eqpos + 1);
712 List<String> vals = set.get(key);
715 vals = new ArrayList<String>();
720 vals.add(value.trim());
726 add &= processGffKey(set, nattr, seq, sf, align, newseqs,
727 relaxedIdMatching); // process decides if
728 // feature is actually
730 } catch (InvalidGFF3FieldException ivfe)
732 System.err.println(ivfe);
738 seq.addSequenceFeature(sf);
743 public class InvalidGFF3FieldException extends Exception
747 public InvalidGFF3FieldException(String field,
748 Map<String, List<String>> set, String message)
750 super(message + " (Field was " + field + " and value was "
751 + set.get(field).toString());
753 this.value = set.get(field).toString();
759 * take a set of keys for a feature and interpret them
767 public boolean processGffKey(Map<String, List<String>> set, int nattr,
768 SequenceI seq, SequenceFeature sf, AlignmentI align,
769 List<SequenceI> newseqs, boolean relaxedIdMatching)
770 throws InvalidGFF3FieldException
773 // decide how to interpret according to type
774 if (sf.getType().equals("similarity"))
776 int strand = sf.getStrand();
777 // exonerate cdna/protein map
779 List<SequenceI> querySeq = findNames(align, newseqs,
780 relaxedIdMatching, set.get(attr="Query"));
781 if (querySeq==null || querySeq.size()!=1)
783 throw new InvalidGFF3FieldException( attr, set,
784 "Expecting exactly one sequence in Query field (got "
785 + set.get(attr) + ")");
787 if (set.containsKey(attr="Align"))
789 // process the align maps and create cdna/protein maps
790 // ideally, the query sequences are in the alignment, but maybe not...
792 AlignedCodonFrame alco = new AlignedCodonFrame();
793 MapList codonmapping = constructCodonMappingFromAlign(set, attr,
796 // add codon mapping, and hope!
797 alco.addMap(seq, querySeq.get(0), codonmapping);
798 align.addCodonFrame(alco);
799 // everything that's needed to be done is done
800 // no features to create here !
808 private MapList constructCodonMappingFromAlign(
809 Map<String, List<String>> set,
810 String attr, int strand) throws InvalidGFF3FieldException
814 throw new InvalidGFF3FieldException(attr, set,
815 "Invalid strand for a codon mapping (cannot be 0)");
817 List<Integer> fromrange = new ArrayList<Integer>(), torange = new ArrayList<Integer>();
818 int lastppos = 0, lastpframe = 0;
819 for (String range : set.get(attr))
821 List<Integer> ints = new ArrayList<Integer>();
822 StringTokenizer st = new StringTokenizer(range, " ");
823 while (st.hasMoreTokens())
825 String num = st.nextToken();
828 ints.add(new Integer(num));
829 } catch (NumberFormatException nfe)
831 throw new InvalidGFF3FieldException(attr, set,
832 "Invalid number in field " + num);
835 // Align positionInRef positionInQuery LengthInRef
836 // contig_1146 exonerate:protein2genome:local similarity 8534 11269
837 // 3652 - . alignment_id 0 ;
838 // Query DDB_G0269124
839 // Align 11270 143 120
840 // corresponds to : 120 bases align at pos 143 in protein to 11270 on
841 // dna in strand direction
842 // Align 11150 187 282
843 // corresponds to : 282 bases align at pos 187 in protein to 11150 on
844 // dna in strand direction
846 // Align 10865 281 888
847 // Align 9977 578 1068
848 // Align 8909 935 375
850 if (ints.size() != 3)
852 throw new InvalidGFF3FieldException(attr, set,
853 "Invalid number of fields for this attribute ("
854 + ints.size() + ")");
856 fromrange.add(new Integer(ints.get(0).intValue()));
857 fromrange.add(new Integer(ints.get(0).intValue() + strand
858 * ints.get(2).intValue()));
859 // how are intron/exon boundaries that do not align in codons
861 if (ints.get(1).equals(lastppos) && lastpframe > 0)
863 // extend existing to map
864 lastppos += ints.get(2) / 3;
865 lastpframe = ints.get(2) % 3;
866 torange.set(torange.size() - 1, new Integer(lastppos));
871 torange.add(ints.get(1));
872 lastppos = ints.get(1) + ints.get(2) / 3;
873 lastpframe = ints.get(2) % 3;
874 torange.add(new Integer(lastppos));
877 // from and to ranges must end up being a series of start/end intervals
878 if (fromrange.size() % 2 == 1)
880 throw new InvalidGFF3FieldException(attr, set,
881 "Couldn't parse the DNA alignment range correctly");
883 if (torange.size() % 2 == 1)
885 throw new InvalidGFF3FieldException(attr, set,
886 "Couldn't parse the protein alignment range correctly");
888 // finally, build the map
889 int[] frommap = new int[fromrange.size()], tomap = new int[torange
892 for (Integer ip : fromrange)
894 frommap[p++] = ip.intValue();
897 for (Integer ip : torange)
899 tomap[p++] = ip.intValue();
902 return new MapList(frommap, tomap, 3, 1);
905 private List<SequenceI> findNames(AlignmentI align,
906 List<SequenceI> newseqs, boolean relaxedIdMatching,
909 List<SequenceI> found = new ArrayList<SequenceI>();
910 for (String seqId : list)
912 SequenceI seq = findName(align, seqId, relaxedIdMatching, newseqs);
921 private AlignmentI lastmatchedAl = null;
923 private SequenceIdMatcher matcher = null;
926 * clear any temporary handles used to speed up ID matching
928 private void resetMatcher()
930 lastmatchedAl = null;
934 private SequenceI findName(AlignmentI align, String seqId,
935 boolean relaxedIdMatching, List<SequenceI> newseqs)
937 SequenceI match = null;
938 if (relaxedIdMatching)
940 if (lastmatchedAl != align)
942 matcher = new SequenceIdMatcher(
943 (lastmatchedAl = align).getSequencesArray());
946 matcher.addAll(newseqs);
949 match = matcher.findIdMatch(seqId);
953 match = align.findName(seqId, true);
956 if (match==null && newseqs!=null)
958 match = new SequenceDummy(seqId);
959 if (relaxedIdMatching)
961 matcher.addAll(Arrays.asList(new SequenceI[]
967 public void parseDescriptionHTML(SequenceFeature sf, boolean removeHTML)
969 if (sf.getDescription() == null)
973 jalview.util.ParseHtmlBodyAndLinks parsed = new jalview.util.ParseHtmlBodyAndLinks(
974 sf.getDescription(), removeHTML, newline);
976 sf.description = (removeHTML) ? parsed.getNonHtmlContent()
978 for (String link : parsed.getLinks())
986 * generate a features file for seqs includes non-pos features by default.
989 * source of sequence features
991 * hash of feature types and colours
992 * @return features file contents
994 public String printJalviewFormat(SequenceI[] seqs, Map<String,Object> visible)
996 return printJalviewFormat(seqs, visible, true, true);
1000 * generate a features file for seqs with colours from visible (if any)
1003 * source of features
1005 * hash of Colours for each feature type
1007 * when true only feature types in 'visible' will be output
1009 * indicates if non-positional features should be output (regardless
1011 * @return features file contents
1013 public String printJalviewFormat(SequenceI[] seqs, Map visible,
1014 boolean visOnly, boolean nonpos)
1016 StringBuffer out = new StringBuffer();
1017 SequenceFeature[] next;
1018 boolean featuresGen = false;
1019 if (visOnly && !nonpos && (visible == null || visible.size() < 1))
1021 // no point continuing.
1022 return "No Features Visible";
1025 if (visible != null && visOnly)
1027 // write feature colours only if we're given them and we are generating
1029 // TODO: decide if feature links should also be written here ?
1030 Iterator en = visible.keySet().iterator();
1032 while (en.hasNext())
1034 type = en.next().toString();
1036 if (visible.get(type) instanceof GraduatedColor)
1038 GraduatedColor gc = (GraduatedColor) visible.get(type);
1039 color = (gc.isColourByLabel() ? "label|" : "")
1040 + Format.getHexString(gc.getMinColor()) + "|"
1041 + Format.getHexString(gc.getMaxColor())
1042 + (gc.isAutoScale() ? "|" : "|abso|") + gc.getMin() + "|"
1043 + gc.getMax() + "|";
1044 if (gc.getThreshType() != AnnotationColourGradient.NO_THRESHOLD)
1046 if (gc.getThreshType() == AnnotationColourGradient.BELOW_THRESHOLD)
1052 if (gc.getThreshType() != AnnotationColourGradient.ABOVE_THRESHOLD)
1054 System.err.println("WARNING: Unsupported threshold type ("
1055 + gc.getThreshType() + ") : Assuming 'above'");
1060 color += "|" + gc.getThresh();
1067 else if (visible.get(type) instanceof java.awt.Color)
1069 color = Format.getHexString((java.awt.Color) visible.get(type));
1073 // legacy support for integer objects containing colour triplet values
1074 color = Format.getHexString(new java.awt.Color(Integer
1075 .parseInt(visible.get(type).toString())));
1080 out.append(newline);
1083 // Work out which groups are both present and visible
1084 Vector groups = new Vector();
1086 boolean isnonpos = false;
1088 for (int i = 0; i < seqs.length; i++)
1090 next = seqs[i].getSequenceFeatures();
1093 for (int j = 0; j < next.length; j++)
1095 isnonpos = next[j].begin == 0 && next[j].end == 0;
1096 if ((!nonpos && isnonpos)
1097 || (!isnonpos && visOnly && !visible
1098 .containsKey(next[j].type)))
1103 if (next[j].featureGroup != null
1104 && !groups.contains(next[j].featureGroup))
1106 groups.addElement(next[j].featureGroup);
1112 String group = null;
1116 if (groups.size() > 0 && groupIndex < groups.size())
1118 group = groups.elementAt(groupIndex).toString();
1119 out.append(newline);
1120 out.append("STARTGROUP\t");
1122 out.append(newline);
1129 for (int i = 0; i < seqs.length; i++)
1131 next = seqs[i].getSequenceFeatures();
1134 for (int j = 0; j < next.length; j++)
1136 isnonpos = next[j].begin == 0 && next[j].end == 0;
1137 if ((!nonpos && isnonpos)
1138 || (!isnonpos && visOnly && !visible
1139 .containsKey(next[j].type)))
1141 // skip if feature is nonpos and we ignore them or if we only
1142 // output visible and it isn't non-pos and it's not visible
1147 && (next[j].featureGroup == null || !next[j].featureGroup
1153 if (group == null && next[j].featureGroup != null)
1157 // we have features to output
1159 if (next[j].description == null
1160 || next[j].description.equals(""))
1162 out.append(next[j].type + "\t");
1166 if (next[j].links != null
1167 && next[j].getDescription().indexOf("<html>") == -1)
1169 out.append("<html>");
1172 out.append(next[j].description + " ");
1173 if (next[j].links != null)
1175 for (int l = 0; l < next[j].links.size(); l++)
1177 String label = next[j].links.elementAt(l).toString();
1178 String href = label.substring(label.indexOf("|") + 1);
1179 label = label.substring(0, label.indexOf("|"));
1181 if (next[j].description.indexOf(href) == -1)
1183 out.append("<a href=\"" + href + "\">" + label + "</a>");
1187 if (next[j].getDescription().indexOf("</html>") == -1)
1189 out.append("</html>");
1195 out.append(seqs[i].getName());
1196 out.append("\t-1\t");
1197 out.append(next[j].begin);
1199 out.append(next[j].end);
1201 out.append(next[j].type);
1202 if (next[j].score != Float.NaN)
1205 out.append(next[j].score);
1207 out.append(newline);
1214 out.append("ENDGROUP\t");
1216 out.append(newline);
1224 } while (groupIndex < groups.size() + 1);
1228 return "No Features Visible";
1231 return out.toString();
1235 * generate a gff file for sequence features includes non-pos features by
1242 public String printGFFFormat(SequenceI[] seqs, Map<String,Object> visible)
1244 return printGFFFormat(seqs, visible, true, true);
1247 public String printGFFFormat(SequenceI[] seqs, Map<String,Object> visible,
1248 boolean visOnly, boolean nonpos)
1250 StringBuffer out = new StringBuffer();
1251 SequenceFeature[] next;
1254 for (int i = 0; i < seqs.length; i++)
1256 if (seqs[i].getSequenceFeatures() != null)
1258 next = seqs[i].getSequenceFeatures();
1259 for (int j = 0; j < next.length; j++)
1261 isnonpos = next[j].begin == 0 && next[j].end == 0;
1262 if ((!nonpos && isnonpos)
1263 || (!isnonpos && visOnly && !visible
1264 .containsKey(next[j].type)))
1269 source = next[j].featureGroup;
1272 source = next[j].getDescription();
1275 out.append(seqs[i].getName());
1279 out.append(next[j].type);
1281 out.append(next[j].begin);
1283 out.append(next[j].end);
1285 out.append(next[j].score);
1288 if (next[j].getValue("STRAND") != null)
1290 out.append(next[j].getValue("STRAND"));
1298 if (next[j].getValue("FRAME") != null)
1300 out.append(next[j].getValue("FRAME"));
1306 // TODO: verify/check GFF - should there be a /t here before attribute
1309 if (next[j].getValue("ATTRIBUTES") != null)
1311 out.append(next[j].getValue("ATTRIBUTES"));
1314 out.append(newline);
1320 return out.toString();
1324 * this is only for the benefit of object polymorphism - method does nothing.
1332 * this is only for the benefit of object polymorphism - method does nothing.
1334 * @return error message
1336 public String print()
1338 return "USE printGFFFormat() or printJalviewFormat()";