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.api.FeatureColourI;
25 import jalview.datamodel.AlignedCodonFrame;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.SequenceDummy;
28 import jalview.datamodel.SequenceFeature;
29 import jalview.datamodel.SequenceI;
30 import jalview.schemes.FeatureColour;
31 import jalview.schemes.UserColourScheme;
32 import jalview.util.MapList;
34 import java.io.IOException;
35 import java.util.ArrayList;
36 import java.util.Arrays;
37 import java.util.HashMap;
38 import java.util.Hashtable;
39 import java.util.Iterator;
40 import java.util.List;
42 import java.util.StringTokenizer;
43 import java.util.Vector;
46 * Parse and create Jalview Features files Detects GFF format features files and
47 * parses. Does not implement standard print() - call specific printFeatures or
48 * printGFF. Uses AlignmentI.findSequence(String id) to find the sequence object
49 * for the features annotation - this normally works on an exact match.
54 public class FeaturesFile extends AlignFile
57 * work around for GFF interpretation bug where source string becomes
58 * description rather than a group
60 private boolean doGffSource = true;
62 private int gffversion;
65 * Creates a new FeaturesFile object.
76 public FeaturesFile(String inFile, String type) throws IOException
85 public FeaturesFile(FileParse source) throws IOException
91 * @param parseImmediately
95 public FeaturesFile(boolean parseImmediately, FileParse source)
98 super(parseImmediately, source);
102 * @param parseImmediately
105 * @throws IOException
107 public FeaturesFile(boolean parseImmediately, String inFile, String type)
110 super(parseImmediately, inFile, type);
114 * Parse GFF or sequence features file using case-independent matching,
118 * - alignment/dataset containing sequences that are to be annotated
120 * - hashtable to store feature colour definitions
122 * - process html strings into plain text
123 * @return true if features were added
125 public boolean parse(AlignmentI align, Map colours, boolean removeHTML)
127 return parse(align, colours, null, removeHTML, false);
131 * Parse GFF or sequence features file optionally using case-independent
132 * matching, discarding URLs
135 * - alignment/dataset containing sequences that are to be annotated
137 * - hashtable to store feature colour definitions
139 * - process html strings into plain text
140 * @param relaxedIdmatching
141 * - when true, ID matches to compound sequence IDs are allowed
142 * @return true if features were added
144 public boolean parse(AlignmentI align, Map colours, boolean removeHTML,
145 boolean relaxedIdMatching)
147 return parse(align, colours, null, removeHTML, relaxedIdMatching);
151 * Parse GFF or sequence features file optionally using case-independent
155 * - alignment/dataset containing sequences that are to be annotated
157 * - hashtable to store feature colour definitions
159 * - hashtable to store associated URLs
161 * - process html strings into plain text
162 * @return true if features were added
164 public boolean parse(AlignmentI align, Map colours, Map featureLink,
167 return parse(align, colours, featureLink, removeHTML, false);
171 public void addAnnotations(AlignmentI al)
173 // TODO Auto-generated method stub
174 super.addAnnotations(al);
178 public void addProperties(AlignmentI al)
180 // TODO Auto-generated method stub
181 super.addProperties(al);
185 public void addSeqGroups(AlignmentI al)
187 // TODO Auto-generated method stub
188 super.addSeqGroups(al);
192 * Parse GFF or sequence features file
195 * - alignment/dataset containing sequences that are to be annotated
197 * - hashtable to store feature colour definitions
199 * - hashtable to store associated URLs
201 * - process html strings into plain text
202 * @param relaxedIdmatching
203 * - when true, ID matches to compound sequence IDs are allowed
204 * @return true if features were added
206 public boolean parse(AlignmentI align, Map colours, Map featureLink,
207 boolean removeHTML, boolean relaxedIdmatching)
213 SequenceI seq = null;
215 * keep track of any sequences we try to create from the data if it is a
218 ArrayList<SequenceI> newseqs = new ArrayList<SequenceI>();
219 String theType, desc, token = null;
223 String featureGroup = null, groupLink = null;
224 Map<String, String> typeLink = new Hashtable<String, String>();
226 * when true, assume GFF style features rather than Jalview style.
228 boolean GFFFile = true;
229 Map<String, String> gffProps = new HashMap<String, String>();
230 while ((line = nextLine()) != null)
232 int featureStart, featureEnd;
233 // skip comments/process pragmas
234 if (line.startsWith("#"))
236 if (line.startsWith("##"))
238 // possibly GFF2/3 version and metadata header
239 processGffPragma(line, gffProps, align, newseqs);
245 st = new StringTokenizer(line, "\t");
246 if (st.countTokens() == 1)
248 if (line.trim().equalsIgnoreCase("GFF"))
250 // Start parsing file as if it might be GFF again.
255 if (st.countTokens() > 1 && st.countTokens() < 4)
258 theType = st.nextToken();
259 if (theType.equalsIgnoreCase("startgroup"))
261 featureGroup = st.nextToken();
262 if (st.hasMoreElements())
264 groupLink = st.nextToken();
265 featureLink.put(featureGroup, groupLink);
268 else if (theType.equalsIgnoreCase("endgroup"))
270 // We should check whether this is the current group,
271 // but at present theres no way of showing more than 1 group
278 String colscheme = st.nextToken();
281 FeatureColourI colour = FeatureColour
282 .parseJalviewFeatureColour(colscheme);
285 colours.put(theType, colour);
287 if (st.hasMoreElements())
289 String link = st.nextToken();
290 typeLink.put(theType, link);
291 if (featureLink == null)
293 featureLink = new Hashtable();
295 featureLink.put(theType, link);
297 } catch (IllegalArgumentException e)
299 System.err.println("Error parsing feature colour scheme "
300 + colscheme + " : " + e.getMessage());
306 while (st.hasMoreElements())
311 // Still possible this is an old Jalview file,
312 // which does not have type colours at the beginning
313 seqId = token = st.nextToken();
314 seq = findName(align, seqId, relaxedIdmatching, newseqs);
317 desc = st.nextToken();
319 if (doGffSource && desc.indexOf(' ') == -1)
321 // could also be a source term rather than description line
322 group = new String(desc);
324 theType = st.nextToken();
327 String stt = st.nextToken();
328 if (stt.length() == 0 || stt.equals("-"))
334 featureStart = Integer.parseInt(stt);
336 } catch (NumberFormatException ex)
342 String stt = st.nextToken();
343 if (stt.length() == 0 || stt.equals("-"))
349 featureEnd = Integer.parseInt(stt);
351 } catch (NumberFormatException ex)
355 // TODO: decide if non positional feature assertion for input data
356 // where end==0 is generally valid
359 // treat as non-positional feature, regardless.
365 score = new Float(st.nextToken()).floatValue();
366 } catch (NumberFormatException ex)
371 sf = new SequenceFeature(theType, desc, featureStart, featureEnd, score, group);
375 sf.setValue("STRAND", st.nextToken());
376 sf.setValue("FRAME", st.nextToken());
377 } catch (Exception ex)
381 if (st.hasMoreTokens())
383 StringBuilder attributes = new StringBuilder();
385 while (st.hasMoreTokens())
387 attributes.append(sep ? "\t" : "").append(
391 // TODO validate and split GFF2 attributes field ? parse out
392 // ([A-Za-z][A-Za-z0-9_]*) <value> ; and add as
393 // sf.setValue(attrib, val);
394 sf.setValue("ATTRIBUTES", attributes.toString());
397 if (processOrAddSeqFeature(align, newseqs, seq, sf, GFFFile,
400 // check whether we should add the sequence feature to any other
401 // sequences in the alignment with the same or similar
402 while ((seq = align.findName(seq, seqId, true)) != null)
404 seq.addSequenceFeature(new SequenceFeature(sf));
411 if (GFFFile && seq == null)
417 desc = st.nextToken();
419 if (!st.hasMoreTokens())
422 .println("DEBUG: Run out of tokens when trying to identify the destination for the feature.. giving up.");
423 // in all probability, this isn't a file we understand, so bail
428 token = st.nextToken();
430 if (!token.equals("ID_NOT_SPECIFIED"))
432 seq = findName(align, seqId = token, relaxedIdmatching, null);
440 int idx = Integer.parseInt(st.nextToken());
441 seq = align.getSequenceAt(idx);
442 } catch (NumberFormatException ex)
450 System.out.println("Sequence not found: " + line);
454 featureStart = Integer.parseInt(st.nextToken());
455 featureEnd = Integer.parseInt(st.nextToken());
457 theType = st.nextToken();
459 if (!colours.containsKey(theType))
461 // Probably the old style groups file
464 new FeatureColour(UserColourScheme
465 .getColourFromString(theType)));
467 sf = new SequenceFeature(theType, desc, "", featureStart, featureEnd, featureGroup);
468 if (st.hasMoreTokens())
473 score = new Float(st.nextToken()).floatValue();
474 // update colourgradient bounds if allowed to
475 } catch (NumberFormatException ex)
481 if (groupLink != null && removeHTML)
483 sf.addLink(groupLink);
484 sf.description += "%LINK%";
486 if (typeLink.containsKey(theType) && removeHTML)
488 sf.addLink(typeLink.get(theType));
489 sf.description += "%LINK%";
492 parseDescriptionHTML(sf, removeHTML);
494 seq.addSequenceFeature(sf);
497 && (seq = align.findName(seq, seqId, false)) != null)
499 seq.addSequenceFeature(new SequenceFeature(sf));
501 // If we got here, its not a GFFFile
506 } catch (Exception ex)
508 // should report somewhere useful for UI if necessary
509 warningMessage = ((warningMessage == null) ? "" : warningMessage)
510 + "Parsing error at\n" + line;
511 System.out.println("Error parsing feature file: " + ex + "\n" + line);
512 ex.printStackTrace(System.err);
520 private enum GffPragmas
522 gff_version, sequence_region, feature_ontology, attribute_ontology, source_ontology, species_build, fasta, hash
525 private static Map<String, GffPragmas> GFFPRAGMA;
528 GFFPRAGMA = new HashMap<String, GffPragmas>();
529 GFFPRAGMA.put("sequence-region", GffPragmas.sequence_region);
530 GFFPRAGMA.put("feature-ontology", GffPragmas.feature_ontology);
531 GFFPRAGMA.put("#", GffPragmas.hash);
532 GFFPRAGMA.put("fasta", GffPragmas.fasta);
533 GFFPRAGMA.put("species-build", GffPragmas.species_build);
534 GFFPRAGMA.put("source-ontology", GffPragmas.source_ontology);
535 GFFPRAGMA.put("attribute-ontology", GffPragmas.attribute_ontology);
538 private void processGffPragma(String line, Map<String, String> gffProps,
539 AlignmentI align, ArrayList<SequenceI> newseqs)
542 // line starts with ##
543 int spacepos = line.indexOf(' ');
544 String pragma = spacepos == -1 ? line.substring(2).trim() : line
545 .substring(2, spacepos);
546 GffPragmas gffpragma = GFFPRAGMA.get(pragma.toLowerCase());
547 if (gffpragma == null)
556 gffversion = Integer.parseInt(line.substring(spacepos + 1));
562 case feature_ontology:
563 // resolve against specific feature ontology
565 case attribute_ontology:
566 // resolve against specific attribute ontology
568 case source_ontology:
569 // resolve against specific source ontology
572 // resolve against specific NCBI taxon version
575 // close off any open feature hierarchies
578 // process the rest of the file as a fasta file and replace any dummy
580 process_as_fasta(align, newseqs);
584 System.err.println("Ignoring unknown pragma:\n" + line);
588 private void process_as_fasta(AlignmentI align, List<SequenceI> newseqs)
594 } catch (IOException q)
597 FastaFile parser = new FastaFile(this);
598 List<SequenceI> includedseqs = parser.getSeqs();
599 SequenceIdMatcher smatcher = new SequenceIdMatcher(newseqs);
600 // iterate over includedseqs, and replacing matching ones with newseqs
601 // sequences. Generic iterator not used here because we modify includedseqs
603 for (int p = 0, pSize = includedseqs.size(); p < pSize; p++)
605 // search for any dummy seqs that this sequence can be used to update
606 SequenceI dummyseq = smatcher.findIdMatch(includedseqs.get(p));
607 if (dummyseq != null)
609 // dummyseq was created so it could be annotated and referred to in
610 // alignments/codon mappings
612 SequenceI mseq = includedseqs.get(p);
613 // mseq is the 'template' imported from the FASTA file which we'll use
614 // to coomplete dummyseq
615 if (dummyseq instanceof SequenceDummy)
617 // probably have the pattern wrong
618 // idea is that a flyweight proxy for a sequence ID can be created for
619 // 1. stable reference creation
620 // 2. addition of annotation
621 // 3. future replacement by a real sequence
622 // current pattern is to create SequenceDummy objects - a convenience
623 // constructor for a Sequence.
624 // problem is that when promoted to a real sequence, all references
626 // to be updated somehow.
627 ((SequenceDummy) dummyseq).become(mseq);
628 includedseqs.set(p, dummyseq); // template is no longer needed
632 // finally add sequences to the dataset
633 for (SequenceI seq : includedseqs)
635 align.addSequence(seq);
640 * take a sequence feature and examine its attributes to decide how it should
641 * be added to a sequence
644 * - the destination sequence constructed or discovered in the
647 * - the base feature with ATTRIBUTES property containing any
648 * additional attributes
650 * - true if we are processing a GFF annotation file
651 * @return true if sf was actually added to the sequence, false if it was
652 * processed in another way
654 public boolean processOrAddSeqFeature(AlignmentI align,
655 List<SequenceI> newseqs, SequenceI seq, SequenceFeature sf,
656 boolean gFFFile, boolean relaxedIdMatching)
658 String attr = (String) sf.getValue("ATTRIBUTES");
660 if (gFFFile && attr != null)
664 for (String attset : attr.split("\t"))
666 if (attset == null || attset.trim().length() == 0)
671 Map<String, List<String>> set = new HashMap<String, List<String>>();
672 // normally, only expect one column - 9 - in this field
673 // the attributes (Gff3) or groups (gff2) field
674 for (String pair : attset.trim().split(";"))
677 if (pair.length() == 0)
682 // expect either space seperated (gff2) or '=' separated (gff3)
683 // key/value pairs here
685 int eqpos = pair.indexOf('='), sppos = pair.indexOf(' ');
686 String key = null, value = null;
688 if (sppos > -1 && (eqpos == -1 || sppos < eqpos))
690 key = pair.substring(0, sppos);
691 value = pair.substring(sppos + 1);
695 if (eqpos > -1 && (sppos == -1 || eqpos < sppos))
697 key = pair.substring(0, eqpos);
698 value = pair.substring(eqpos + 1);
707 List<String> vals = set.get(key);
710 vals = new ArrayList<String>();
715 vals.add(value.trim());
721 add &= processGffKey(set, nattr, seq, sf, align, newseqs,
722 relaxedIdMatching); // process decides if
723 // feature is actually
725 } catch (InvalidGFF3FieldException ivfe)
727 System.err.println(ivfe);
733 seq.addSequenceFeature(sf);
738 public class InvalidGFF3FieldException extends Exception
742 public InvalidGFF3FieldException(String field,
743 Map<String, List<String>> set, String message)
745 super(message + " (Field was " + field + " and value was "
746 + set.get(field).toString());
748 this.value = set.get(field).toString();
754 * take a set of keys for a feature and interpret them
762 public boolean processGffKey(Map<String, List<String>> set, int nattr,
763 SequenceI seq, SequenceFeature sf, AlignmentI align,
764 List<SequenceI> newseqs, boolean relaxedIdMatching)
765 throws InvalidGFF3FieldException
768 // decide how to interpret according to type
769 if (sf.getType().equals("similarity"))
771 int strand = sf.getStrand();
772 // exonerate cdna/protein map
774 List<SequenceI> querySeq = findNames(align, newseqs,
775 relaxedIdMatching, set.get(attr = "Query"));
776 if (querySeq == null || querySeq.size() != 1)
778 throw new InvalidGFF3FieldException(attr, set,
779 "Expecting exactly one sequence in Query field (got "
780 + set.get(attr) + ")");
782 if (set.containsKey(attr = "Align"))
784 // process the align maps and create cdna/protein maps
785 // ideally, the query sequences are in the alignment, but maybe not...
787 AlignedCodonFrame alco = new AlignedCodonFrame();
788 MapList codonmapping = constructCodonMappingFromAlign(set, attr,
791 // add codon mapping, and hope!
792 alco.addMap(seq, querySeq.get(0), codonmapping);
793 align.addCodonFrame(alco);
794 // everything that's needed to be done is done
795 // no features to create here !
803 private MapList constructCodonMappingFromAlign(
804 Map<String, List<String>> set, String attr, int strand)
805 throws InvalidGFF3FieldException
809 throw new InvalidGFF3FieldException(attr, set,
810 "Invalid strand for a codon mapping (cannot be 0)");
812 List<Integer> fromrange = new ArrayList<Integer>(), torange = new ArrayList<Integer>();
813 int lastppos = 0, lastpframe = 0;
814 for (String range : set.get(attr))
816 List<Integer> ints = new ArrayList<Integer>();
817 StringTokenizer st = new StringTokenizer(range, " ");
818 while (st.hasMoreTokens())
820 String num = st.nextToken();
823 ints.add(new Integer(num));
824 } catch (NumberFormatException nfe)
826 throw new InvalidGFF3FieldException(attr, set,
827 "Invalid number in field " + num);
830 // Align positionInRef positionInQuery LengthInRef
831 // contig_1146 exonerate:protein2genome:local similarity 8534 11269
832 // 3652 - . alignment_id 0 ;
833 // Query DDB_G0269124
834 // Align 11270 143 120
835 // corresponds to : 120 bases align at pos 143 in protein to 11270 on
836 // dna in strand direction
837 // Align 11150 187 282
838 // corresponds to : 282 bases align at pos 187 in protein to 11150 on
839 // dna in strand direction
841 // Align 10865 281 888
842 // Align 9977 578 1068
843 // Align 8909 935 375
845 if (ints.size() != 3)
847 throw new InvalidGFF3FieldException(attr, set,
848 "Invalid number of fields for this attribute ("
849 + ints.size() + ")");
851 fromrange.add(new Integer(ints.get(0).intValue()));
852 fromrange.add(new Integer(ints.get(0).intValue() + strand
853 * ints.get(2).intValue()));
854 // how are intron/exon boundaries that do not align in codons
856 if (ints.get(1).equals(lastppos) && lastpframe > 0)
858 // extend existing to map
859 lastppos += ints.get(2) / 3;
860 lastpframe = ints.get(2) % 3;
861 torange.set(torange.size() - 1, new Integer(lastppos));
866 torange.add(ints.get(1));
867 lastppos = ints.get(1) + ints.get(2) / 3;
868 lastpframe = ints.get(2) % 3;
869 torange.add(new Integer(lastppos));
872 // from and to ranges must end up being a series of start/end intervals
873 if (fromrange.size() % 2 == 1)
875 throw new InvalidGFF3FieldException(attr, set,
876 "Couldn't parse the DNA alignment range correctly");
878 if (torange.size() % 2 == 1)
880 throw new InvalidGFF3FieldException(attr, set,
881 "Couldn't parse the protein alignment range correctly");
883 // finally, build the map
884 int[] frommap = new int[fromrange.size()], tomap = new int[torange
887 for (Integer ip : fromrange)
889 frommap[p++] = ip.intValue();
892 for (Integer ip : torange)
894 tomap[p++] = ip.intValue();
897 return new MapList(frommap, tomap, 3, 1);
900 private List<SequenceI> findNames(AlignmentI align,
901 List<SequenceI> newseqs, boolean relaxedIdMatching,
904 List<SequenceI> found = new ArrayList<SequenceI>();
905 for (String seqId : list)
907 SequenceI seq = findName(align, seqId, relaxedIdMatching, newseqs);
916 private AlignmentI lastmatchedAl = null;
918 private SequenceIdMatcher matcher = null;
921 * clear any temporary handles used to speed up ID matching
923 private void resetMatcher()
925 lastmatchedAl = null;
929 private SequenceI findName(AlignmentI align, String seqId,
930 boolean relaxedIdMatching, List<SequenceI> newseqs)
932 SequenceI match = null;
933 if (relaxedIdMatching)
935 if (lastmatchedAl != align)
937 matcher = new SequenceIdMatcher(
938 (lastmatchedAl = align).getSequencesArray());
941 matcher.addAll(newseqs);
944 match = matcher.findIdMatch(seqId);
948 match = align.findName(seqId, true);
949 if (match == null && newseqs != null)
951 for (SequenceI m : newseqs)
953 if (seqId.equals(m.getName()))
961 if (match == null && newseqs != null)
963 match = new SequenceDummy(seqId);
964 if (relaxedIdMatching)
966 matcher.addAll(Arrays.asList(new SequenceI[] { match }));
968 // add dummy sequence to the newseqs list
974 public void parseDescriptionHTML(SequenceFeature sf, boolean removeHTML)
976 if (sf.getDescription() == null)
980 jalview.util.ParseHtmlBodyAndLinks parsed = new jalview.util.ParseHtmlBodyAndLinks(
981 sf.getDescription(), removeHTML, newline);
983 sf.description = (removeHTML) ? parsed.getNonHtmlContent()
985 for (String link : parsed.getLinks())
993 * generate a features file for seqs includes non-pos features by default.
996 * source of sequence features
998 * hash of feature types and colours
999 * @return features file contents
1001 public String printJalviewFormat(SequenceI[] seqs,
1002 Map<String, FeatureColourI> map)
1004 return printJalviewFormat(seqs, map, true, true);
1008 * generate a features file for seqs with colours from visible (if any)
1011 * source of features
1013 * hash of Colours for each feature type
1015 * when true only feature types in 'visible' will be output
1017 * indicates if non-positional features should be output (regardless
1019 * @return features file contents
1021 public String printJalviewFormat(SequenceI[] sequences,
1022 Map<String, FeatureColourI> visible,
1023 boolean visOnly, boolean nonpos)
1025 if (visOnly && !nonpos && (visible == null || visible.size() < 1))
1027 // no point continuing.
1028 return "No Features Visible";
1030 StringBuilder out = new StringBuilder(128);
1031 SequenceFeature[] next;
1032 boolean featuresGen = false;
1034 if (visible != null && visOnly)
1036 // write feature colours only if we're given them and we are generating
1038 // TODO: decide if feature links should also be written here ?
1039 Iterator<String> en = visible.keySet().iterator();
1040 while (en.hasNext())
1042 String featureType = en.next();
1043 FeatureColourI colour = visible.get(featureType);
1044 out.append(colour.toJalviewFormat(featureType)).append(newline);
1047 // Work out which groups are both present and visible
1048 Vector groups = new Vector();
1050 boolean isnonpos = false;
1052 for (int i = 0; i < sequences.length; i++)
1054 next = sequences[i].getSequenceFeatures();
1057 for (int j = 0; j < next.length; j++)
1059 isnonpos = next[j].begin == 0 && next[j].end == 0;
1060 if ((!nonpos && isnonpos)
1061 || (!isnonpos && visOnly && !visible
1062 .containsKey(next[j].type)))
1067 if (next[j].featureGroup != null
1068 && !groups.contains(next[j].featureGroup))
1070 groups.addElement(next[j].featureGroup);
1076 String group = null;
1080 if (groups.size() > 0 && groupIndex < groups.size())
1082 group = groups.elementAt(groupIndex).toString();
1083 out.append(newline);
1084 out.append("STARTGROUP\t");
1086 out.append(newline);
1093 for (int i = 0; i < sequences.length; i++)
1095 next = sequences[i].getSequenceFeatures();
1098 for (int j = 0; j < next.length; j++)
1100 isnonpos = next[j].begin == 0 && next[j].end == 0;
1101 if ((!nonpos && isnonpos)
1102 || (!isnonpos && visOnly && !visible
1103 .containsKey(next[j].type)))
1105 // skip if feature is nonpos and we ignore them or if we only
1106 // output visible and it isn't non-pos and it's not visible
1111 && (next[j].featureGroup == null || !next[j].featureGroup
1117 if (group == null && next[j].featureGroup != null)
1121 // we have features to output
1123 if (next[j].description == null
1124 || next[j].description.equals(""))
1126 out.append(next[j].type + "\t");
1130 if (next[j].links != null
1131 && next[j].getDescription().indexOf("<html>") == -1)
1133 out.append("<html>");
1136 out.append(next[j].description + " ");
1137 if (next[j].links != null)
1139 for (int l = 0; l < next[j].links.size(); l++)
1141 String label = next[j].links.elementAt(l).toString();
1142 String href = label.substring(label.indexOf("|") + 1);
1143 label = label.substring(0, label.indexOf("|"));
1145 if (next[j].description.indexOf(href) == -1)
1147 out.append("<a href=\"" + href + "\">" + label + "</a>");
1151 if (next[j].getDescription().indexOf("</html>") == -1)
1153 out.append("</html>");
1159 out.append(sequences[i].getName());
1160 out.append("\t-1\t");
1161 out.append(next[j].begin);
1163 out.append(next[j].end);
1165 out.append(next[j].type);
1166 if (!Float.isNaN(next[j].score))
1169 out.append(next[j].score);
1171 out.append(newline);
1178 out.append("ENDGROUP\t");
1180 out.append(newline);
1188 } while (groupIndex < groups.size() + 1);
1192 return "No Features Visible";
1195 return out.toString();
1199 * generate a gff file for sequence features includes non-pos features by
1206 public String printGFFFormat(SequenceI[] seqs,
1207 Map<String, FeatureColourI> map)
1209 return printGFFFormat(seqs, map, true, true);
1212 public String printGFFFormat(SequenceI[] seqs,
1213 Map<String, FeatureColourI> map, boolean visOnly, boolean nonpos)
1215 StringBuffer out = new StringBuffer();
1216 SequenceFeature[] next;
1219 for (int i = 0; i < seqs.length; i++)
1221 if (seqs[i].getSequenceFeatures() != null)
1223 next = seqs[i].getSequenceFeatures();
1224 for (int j = 0; j < next.length; j++)
1226 isnonpos = next[j].begin == 0 && next[j].end == 0;
1227 if ((!nonpos && isnonpos)
1228 || (!isnonpos && visOnly && !map
1229 .containsKey(next[j].type)))
1234 source = next[j].featureGroup;
1237 source = next[j].getDescription();
1240 out.append(seqs[i].getName());
1244 out.append(next[j].type);
1246 out.append(next[j].begin);
1248 out.append(next[j].end);
1250 out.append(next[j].score);
1253 if (next[j].getValue("STRAND") != null)
1255 out.append(next[j].getValue("STRAND"));
1263 if (next[j].getValue("FRAME") != null)
1265 out.append(next[j].getValue("FRAME"));
1271 // TODO: verify/check GFF - should there be a /t here before attribute
1274 if (next[j].getValue("ATTRIBUTES") != null)
1276 out.append(next[j].getValue("ATTRIBUTES"));
1279 out.append(newline);
1285 return out.toString();
1289 * this is only for the benefit of object polymorphism - method does nothing.
1298 * this is only for the benefit of object polymorphism - method does nothing.
1300 * @return error message
1303 public String print()
1305 return "USE printGFFFormat() or printJalviewFormat()";