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.AlignmentUtils;
24 import jalview.analysis.SequenceIdMatcher;
25 import jalview.api.AlignViewportI;
26 import jalview.api.FeatureColourI;
27 import jalview.api.FeaturesSourceI;
28 import jalview.datamodel.AlignedCodonFrame;
29 import jalview.datamodel.Alignment;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.SequenceDummy;
32 import jalview.datamodel.SequenceFeature;
33 import jalview.datamodel.SequenceI;
34 import jalview.io.gff.GffHelperBase;
35 import jalview.io.gff.GffHelperFactory;
36 import jalview.io.gff.GffHelperI;
37 import jalview.schemes.FeatureColour;
38 import jalview.schemes.UserColourScheme;
39 import jalview.util.MapList;
40 import jalview.util.ParseHtmlBodyAndLinks;
41 import jalview.util.StringUtils;
43 import java.io.IOException;
44 import java.util.ArrayList;
45 import java.util.Arrays;
46 import java.util.HashMap;
47 import java.util.Iterator;
48 import java.util.List;
50 import java.util.Map.Entry;
53 * Parses and writes features files, which may be in Jalview, GFF2 or GFF3
54 * format. These are tab-delimited formats but with differences in the use of
57 * A Jalview feature file may define feature colours and then declare that the
58 * remainder of the file is in GFF format with the line 'GFF'.
60 * GFF3 files may include alignment mappings for features, which Jalview will
61 * attempt to model, and may include sequence data following a ##FASTA line.
68 public class FeaturesFile extends AlignFile implements FeaturesSourceI
70 private static final String ID_NOT_SPECIFIED = "ID_NOT_SPECIFIED";
72 private static final String NOTE = "Note";
74 protected static final String TAB = "\t";
76 protected static final String GFF_VERSION = "##gff-version";
78 private AlignmentI lastmatchedAl = null;
80 private SequenceIdMatcher matcher = null;
82 protected AlignmentI dataset;
84 protected int gffVersion;
87 * Creates a new FeaturesFile object.
94 * Constructor which does not parse the file immediately
100 public FeaturesFile(String inFile, String type) throws IOException
102 super(false, inFile, type);
107 * @throws IOException
109 public FeaturesFile(FileParse source) throws IOException
115 * Constructor that optionally parses the file immediately
117 * @param parseImmediately
120 * @throws IOException
122 public FeaturesFile(boolean parseImmediately, String inFile, String type)
125 super(parseImmediately, inFile, type);
129 * Parse GFF or sequence features file using case-independent matching,
133 * - alignment/dataset containing sequences that are to be annotated
135 * - hashtable to store feature colour definitions
137 * - process html strings into plain text
138 * @return true if features were added
140 public boolean parse(AlignmentI align,
141 Map<String, FeatureColourI> colours, boolean removeHTML)
143 return parse(align, colours, removeHTML, false);
147 * Extends the default addProperties by also adding peptide-to-cDNA mappings
148 * (if any) derived while parsing a GFF file
151 public void addProperties(AlignmentI al)
153 super.addProperties(al);
154 if (dataset != null && dataset.getCodonFrames() != null)
156 AlignmentI ds = (al.getDataset() == null) ? al : al.getDataset();
157 for (AlignedCodonFrame codons : dataset.getCodonFrames())
159 ds.addCodonFrame(codons);
165 * Parse GFF or Jalview format sequence features file
168 * - alignment/dataset containing sequences that are to be annotated
170 * - hashtable to store feature colour definitions
172 * - process html strings into plain text
173 * @param relaxedIdmatching
174 * - when true, ID matches to compound sequence IDs are allowed
175 * @return true if features were added
177 public boolean parse(AlignmentI align,
178 Map<String, FeatureColourI> colours, boolean removeHTML,
179 boolean relaxedIdmatching)
181 Map<String, String> gffProps = new HashMap<String, String>();
183 * keep track of any sequences we try to create from the data
185 List<SequenceI> newseqs = new ArrayList<SequenceI>();
191 String featureGroup = null;
193 while ((line = nextLine()) != null)
195 // skip comments/process pragmas
196 if (line.length() == 0 || line.startsWith("#"))
198 if (line.toLowerCase().startsWith("##"))
200 processGffPragma(line, gffProps, align, newseqs);
205 gffColumns = line.split("\\t"); // tab as regex
206 if (gffColumns.length == 1)
208 if (line.trim().equalsIgnoreCase("GFF"))
211 * Jalview features file with appended GFF
212 * assume GFF2 (though it may declare ##gff-version 3)
219 if (gffColumns.length > 1 && gffColumns.length < 4)
222 * if 2 or 3 tokens, we anticipate either 'startgroup', 'endgroup' or
223 * a feature type colour specification
225 String ft = gffColumns[0];
226 if (ft.equalsIgnoreCase("startgroup"))
228 featureGroup = gffColumns[1];
230 else if (ft.equalsIgnoreCase("endgroup"))
232 // We should check whether this is the current group,
233 // but at present there's no way of showing more than 1 group
238 String colscheme = gffColumns[1];
239 FeatureColourI colour = FeatureColour
240 .parseJalviewFeatureColour(colscheme);
243 colours.put(ft, colour);
250 * if not a comment, GFF pragma, startgroup, endgroup or feature
251 * colour specification, that just leaves a feature details line
252 * in either Jalview or GFF format
256 parseJalviewFeature(line, gffColumns, align, colours, removeHTML,
257 relaxedIdmatching, featureGroup);
261 parseGff(gffColumns, align, relaxedIdmatching, newseqs);
265 } catch (Exception ex)
267 // should report somewhere useful for UI if necessary
268 warningMessage = ((warningMessage == null) ? "" : warningMessage)
269 + "Parsing error at\n" + line;
270 System.out.println("Error parsing feature file: " + ex + "\n" + line);
271 ex.printStackTrace(System.err);
277 * experimental - add any dummy sequences with features to the alignment
278 * - we need them for Ensembl feature extraction - though maybe not otherwise
280 for (SequenceI newseq : newseqs)
282 if (newseq.getSequenceFeatures() != null)
284 align.addSequence(newseq);
291 * Try to parse a Jalview format feature specification and add it as a
292 * sequence feature to any matching sequences in the alignment. Returns true
293 * if successful (a feature was added), or false if not.
298 * @param featureColours
300 * @param relaxedIdmatching
301 * @param featureGroup
303 protected boolean parseJalviewFeature(String line, String[] gffColumns,
304 AlignmentI alignment, Map<String, FeatureColourI> featureColours,
305 boolean removeHTML, boolean relaxedIdMatching, String featureGroup)
308 * tokens: description seqid seqIndex start end type [score]
310 if (gffColumns.length < 6)
312 System.err.println("Ignoring feature line '" + line
313 + "' with too few columns (" + gffColumns.length + ")");
316 String desc = gffColumns[0];
317 String seqId = gffColumns[1];
318 SequenceI seq = findSequence(seqId, alignment, null, relaxedIdMatching);
320 if (!ID_NOT_SPECIFIED.equals(seqId))
322 seq = findSequence(seqId, alignment, null, relaxedIdMatching);
328 String seqIndex = gffColumns[2];
331 int idx = Integer.parseInt(seqIndex);
332 seq = alignment.getSequenceAt(idx);
333 } catch (NumberFormatException ex)
335 System.err.println("Invalid sequence index: " + seqIndex);
341 System.out.println("Sequence not found: " + line);
345 int startPos = Integer.parseInt(gffColumns[3]);
346 int endPos = Integer.parseInt(gffColumns[4]);
348 String ft = gffColumns[5];
350 if (!featureColours.containsKey(ft))
353 * Perhaps an old style groups file with no colours -
354 * synthesize a colour from the feature type
356 UserColourScheme ucs = new UserColourScheme(ft);
357 featureColours.put(ft, new FeatureColour(ucs.findColour('A')));
359 SequenceFeature sf = new SequenceFeature(ft, desc, "", startPos,
360 endPos, featureGroup);
361 if (gffColumns.length > 6)
363 float score = Float.NaN;
366 score = new Float(gffColumns[6]).floatValue();
367 // update colourgradient bounds if allowed to
368 } catch (NumberFormatException ex)
375 parseDescriptionHTML(sf, removeHTML);
377 seq.addSequenceFeature(sf);
380 && (seq = alignment.findName(seq, seqId, false)) != null)
382 seq.addSequenceFeature(new SequenceFeature(sf));
388 * clear any temporary handles used to speed up ID matching
390 protected void resetMatcher()
392 lastmatchedAl = null;
397 * Returns a sequence matching the given id, as follows
399 * <li>strict matching is on exact sequence name</li>
400 * <li>relaxed matching allows matching on a token within the sequence name,
402 * <li>first tries to find a match in the alignment sequences</li>
403 * <li>else tries to find a match in the new sequences already generated while
404 * parsing the features file</li>
405 * <li>else creates a new placeholder sequence, adds it to the new sequences
406 * list, and returns it</li>
412 * @param relaxedIdMatching
416 protected SequenceI findSequence(String seqId, AlignmentI align,
417 List<SequenceI> newseqs, boolean relaxedIdMatching)
419 // TODO encapsulate in SequenceIdMatcher, share the matcher
420 // with the GffHelper (removing code duplication)
421 SequenceI match = null;
422 if (relaxedIdMatching)
424 if (lastmatchedAl != align)
426 lastmatchedAl = align;
427 matcher = new SequenceIdMatcher(align.getSequencesArray());
430 matcher.addAll(newseqs);
433 match = matcher.findIdMatch(seqId);
437 match = align.findName(seqId, true);
438 if (match == null && newseqs != null)
440 for (SequenceI m : newseqs)
442 if (seqId.equals(m.getName()))
450 if (match == null && newseqs != null)
452 match = new SequenceDummy(seqId);
453 if (relaxedIdMatching)
455 matcher.addAll(Arrays.asList(new SequenceI[] { match }));
457 // add dummy sequence to the newseqs list
463 public void parseDescriptionHTML(SequenceFeature sf, boolean removeHTML)
465 if (sf.getDescription() == null)
469 ParseHtmlBodyAndLinks parsed = new ParseHtmlBodyAndLinks(
470 sf.getDescription(), removeHTML, newline);
472 sf.description = (removeHTML) ? parsed.getNonHtmlContent()
474 for (String link : parsed.getLinks())
482 * generate a features file for seqs includes non-pos features by default.
485 * source of sequence features
487 * hash of feature types and colours
488 * @return features file contents
490 public String printJalviewFormat(SequenceI[] sequences,
491 Map<String, FeatureColourI> visible)
493 return printJalviewFormat(sequences, visible, true, true);
497 * generate a features file for seqs with colours from visible (if any)
502 * hash of Colours for each feature type
504 * when true only feature types in 'visible' will be output
506 * indicates if non-positional features should be output (regardless
508 * @return features file contents
510 public String printJalviewFormat(SequenceI[] sequences,
511 Map<String, FeatureColourI> visible, boolean visOnly,
514 StringBuilder out = new StringBuilder(256);
515 boolean featuresGen = false;
516 if (visOnly && !nonpos && (visible == null || visible.size() < 1))
518 // no point continuing.
519 return "No Features Visible";
522 if (visible != null && visOnly)
524 // write feature colours only if we're given them and we are generating
526 // TODO: decide if feature links should also be written here ?
527 Iterator<String> en = visible.keySet().iterator();
530 String featureType = en.next().toString();
531 FeatureColourI colour = visible.get(featureType);
532 out.append(colour.toJalviewFormat(featureType)).append(newline);
536 // Work out which groups are both present and visible
537 List<String> groups = new ArrayList<String>();
539 boolean isnonpos = false;
541 SequenceFeature[] features;
542 for (int i = 0; i < sequences.length; i++)
544 features = sequences[i].getSequenceFeatures();
545 if (features != null)
547 for (int j = 0; j < features.length; j++)
549 isnonpos = features[j].begin == 0 && features[j].end == 0;
550 if ((!nonpos && isnonpos)
551 || (!isnonpos && visOnly && !visible
552 .containsKey(features[j].type)))
557 if (features[j].featureGroup != null
558 && !groups.contains(features[j].featureGroup))
560 groups.add(features[j].featureGroup);
569 if (groups.size() > 0 && groupIndex < groups.size())
571 group = groups.get(groupIndex);
573 out.append("STARTGROUP").append(TAB);
582 for (int i = 0; i < sequences.length; i++)
584 features = sequences[i].getSequenceFeatures();
585 if (features != null)
587 for (SequenceFeature sequenceFeature : features)
589 isnonpos = sequenceFeature.begin == 0
590 && sequenceFeature.end == 0;
591 if ((!nonpos && isnonpos)
592 || (!isnonpos && visOnly && !visible
593 .containsKey(sequenceFeature.type)))
595 // skip if feature is nonpos and we ignore them or if we only
596 // output visible and it isn't non-pos and it's not visible
601 && (sequenceFeature.featureGroup == null || !sequenceFeature.featureGroup
607 if (group == null && sequenceFeature.featureGroup != null)
611 // we have features to output
613 if (sequenceFeature.description == null
614 || sequenceFeature.description.equals(""))
616 out.append(sequenceFeature.type).append(TAB);
620 if (sequenceFeature.links != null
621 && sequenceFeature.getDescription().indexOf("<html>") == -1)
623 out.append("<html>");
626 out.append(sequenceFeature.description);
627 if (sequenceFeature.links != null)
629 for (int l = 0; l < sequenceFeature.links.size(); l++)
631 String label = sequenceFeature.links.elementAt(l);
632 String href = label.substring(label.indexOf("|") + 1);
633 label = label.substring(0, label.indexOf("|"));
635 if (sequenceFeature.description.indexOf(href) == -1)
637 out.append(" <a href=\"" + href + "\">" + label
642 if (sequenceFeature.getDescription().indexOf("</html>") == -1)
644 out.append("</html>");
650 out.append(sequences[i].getName());
651 out.append("\t-1\t");
652 out.append(sequenceFeature.begin);
654 out.append(sequenceFeature.end);
656 out.append(sequenceFeature.type);
657 if (!Float.isNaN(sequenceFeature.score))
660 out.append(sequenceFeature.score);
669 out.append("ENDGROUP").append(TAB);
679 } while (groupIndex < groups.size() + 1);
683 return "No Features Visible";
686 return out.toString();
690 * Parse method that is called when a GFF file is dragged to the desktop
695 AlignViewportI av = getViewport();
698 if (av.getAlignment() != null)
700 dataset = av.getAlignment().getDataset();
704 // working in the applet context ?
705 dataset = av.getAlignment();
710 dataset = new Alignment(new SequenceI[] {});
713 boolean parseResult = parse(dataset, null, false, true);
716 // pass error up somehow
720 // update viewport with the dataset data ?
724 setSeqs(dataset.getSequencesArray());
729 * Implementation of unused abstract method
731 * @return error message
734 public String print()
736 return "Use printGffFormat() or printJalviewFormat()";
740 * Returns features output in GFF2 format, including hidden and non-positional
744 * the sequences whose features are to be output
746 * a map whose keys are the type names of visible features
749 public String printGffFormat(SequenceI[] sequences,
750 Map<String, FeatureColourI> visible)
752 return printGffFormat(sequences, visible, true, true);
756 * Returns features output in GFF2 format
759 * the sequences whose features are to be output
761 * a map whose keys are the type names of visible features
762 * @param outputVisibleOnly
763 * @param includeNonPositionalFeatures
766 public String printGffFormat(SequenceI[] sequences,
767 Map<String, FeatureColourI> visible, boolean outputVisibleOnly,
768 boolean includeNonPositionalFeatures)
770 StringBuilder out = new StringBuilder(256);
771 int version = gffVersion == 0 ? 2 : gffVersion;
772 out.append(String.format("%s %d\n", GFF_VERSION, version));
775 for (SequenceI seq : sequences)
777 SequenceFeature[] features = seq.getSequenceFeatures();
778 if (features != null)
780 for (SequenceFeature sf : features)
782 isnonpos = sf.begin == 0 && sf.end == 0;
783 if (!includeNonPositionalFeatures && isnonpos)
786 * ignore non-positional features if not wanted
790 // TODO why the test !isnonpos here?
791 // what about not visible non-positional features?
792 if (!isnonpos && outputVisibleOnly
793 && !visible.containsKey(sf.type))
796 * ignore not visible features if not wanted
801 source = sf.featureGroup;
804 source = sf.getDescription();
807 out.append(seq.getName());
813 out.append(sf.begin);
817 out.append(sf.score);
820 int strand = sf.getStrand();
821 out.append(strand == 1 ? "+" : (strand == -1 ? "-" : "."));
824 String phase = sf.getPhase();
825 out.append(phase == null ? "." : phase);
827 // miscellaneous key-values (GFF column 9)
828 String attributes = sf.getAttributes();
829 if (attributes != null)
831 out.append(TAB).append(attributes);
839 return out.toString();
843 * Returns a mapping given list of one or more Align descriptors (exonerate
846 * @param alignedRegions
847 * a list of "Align fromStart toStart fromCount"
848 * @param mapIsFromCdna
849 * if true, 'from' is dna, else 'from' is protein
851 * either 1 (forward) or -1 (reverse)
853 * @throws IOException
855 protected MapList constructCodonMappingFromAlign(
856 List<String> alignedRegions, boolean mapIsFromCdna, int strand)
861 throw new IOException(
862 "Invalid strand for a codon mapping (cannot be 0)");
864 int regions = alignedRegions.size();
865 // arrays to hold [start, end] for each aligned region
866 int[] fromRanges = new int[regions * 2]; // from dna
867 int[] toRanges = new int[regions * 2]; // to protein
868 int fromRangesIndex = 0;
869 int toRangesIndex = 0;
871 for (String range : alignedRegions)
874 * Align mapFromStart mapToStart mapFromCount
875 * e.g. if mapIsFromCdna
876 * Align 11270 143 120
878 * 120 bases from pos 11270 align to pos 143 in peptide
879 * if !mapIsFromCdna this would instead be
882 String[] tokens = range.split(" ");
883 if (tokens.length != 3)
885 throw new IOException("Wrong number of fields for Align");
892 fromStart = Integer.parseInt(tokens[0]);
893 toStart = Integer.parseInt(tokens[1]);
894 fromCount = Integer.parseInt(tokens[2]);
895 } catch (NumberFormatException nfe)
897 throw new IOException("Invalid number in Align field: "
902 * Jalview always models from dna to protein, so adjust values if the
903 * GFF mapping is from protein to dna
908 int temp = fromStart;
912 fromRanges[fromRangesIndex++] = fromStart;
913 fromRanges[fromRangesIndex++] = fromStart + strand * (fromCount - 1);
916 * If a codon has an intron gap, there will be contiguous 'toRanges';
917 * this is handled for us by the MapList constructor.
918 * (It is not clear that exonerate ever generates this case)
920 toRanges[toRangesIndex++] = toStart;
921 toRanges[toRangesIndex++] = toStart + (fromCount - 1) / 3;
924 return new MapList(fromRanges, toRanges, 3, 1);
928 * Parse a GFF format feature. This may include creating a 'dummy' sequence to
929 * hold the feature, or for its mapped sequence, or both, to be resolved
930 * either later in the GFF file (##FASTA section), or when the user loads
931 * additional sequences.
935 * @param relaxedIdMatching
939 protected SequenceI parseGff(String[] gffColumns, AlignmentI alignment,
940 boolean relaxedIdMatching, List<SequenceI> newseqs)
943 * GFF: seqid source type start end score strand phase [attributes]
945 if (gffColumns.length < 5)
947 System.err.println("Ignoring GFF feature line with too few columns ("
948 + gffColumns.length + ")");
953 * locate referenced sequence in alignment _or_
954 * as a forward or external reference (SequenceDummy)
956 String seqId = gffColumns[0];
957 SequenceI seq = findSequence(seqId, alignment, newseqs,
960 SequenceFeature sf = null;
961 GffHelperI helper = GffHelperFactory.getHelper(gffColumns);
966 sf = helper.processGff(seq, gffColumns, alignment, newseqs,
970 seq.addSequenceFeature(sf);
971 while ((seq = alignment.findName(seq, seqId, true)) != null)
973 seq.addSequenceFeature(new SequenceFeature(sf));
976 } catch (IOException e)
978 System.err.println("GFF parsing failed with: " + e.getMessage());
987 * Process the 'column 9' data of the GFF file. This is less formally defined,
988 * and its interpretation will vary depending on the tool that has generated
994 protected void processGffColumnNine(String attributes, SequenceFeature sf)
996 sf.setAttributes(attributes);
999 * Parse attributes in column 9 and add them to the sequence feature's
1000 * 'otherData' table; use Note as a best proxy for description
1002 char nameValueSeparator = gffVersion == 3 ? '=' : ' ';
1003 // TODO check we don't break GFF2 values which include commas here
1004 Map<String, List<String>> nameValues = GffHelperBase
1005 .parseNameValuePairs(attributes, ";", nameValueSeparator, ",");
1006 for (Entry<String, List<String>> attr : nameValues.entrySet())
1008 String values = StringUtils.listToDelimitedString(attr.getValue(),
1010 sf.setValue(attr.getKey(), values);
1011 if (NOTE.equals(attr.getKey()))
1013 sf.setDescription(values);
1019 * After encountering ##fasta in a GFF3 file, process the remainder of the
1020 * file as FAST sequence data. Any placeholder sequences created during
1021 * feature parsing are updated with the actual sequences.
1025 * @throws IOException
1027 protected void processAsFasta(AlignmentI align, List<SequenceI> newseqs)
1033 } catch (IOException q)
1036 FastaFile parser = new FastaFile(this);
1037 List<SequenceI> includedseqs = parser.getSeqs();
1039 SequenceIdMatcher smatcher = new SequenceIdMatcher(newseqs);
1042 * iterate over includedseqs, and replacing matching ones with newseqs
1043 * sequences. Generic iterator not used here because we modify
1044 * includedseqs as we go
1046 for (int p = 0, pSize = includedseqs.size(); p < pSize; p++)
1048 // search for any dummy seqs that this sequence can be used to update
1049 SequenceI includedSeq = includedseqs.get(p);
1050 SequenceI dummyseq = smatcher.findIdMatch(includedSeq);
1051 if (dummyseq != null && dummyseq instanceof SequenceDummy)
1053 // probably have the pattern wrong
1054 // idea is that a flyweight proxy for a sequence ID can be created for
1055 // 1. stable reference creation
1056 // 2. addition of annotation
1057 // 3. future replacement by a real sequence
1058 // current pattern is to create SequenceDummy objects - a convenience
1059 // constructor for a Sequence.
1060 // problem is that when promoted to a real sequence, all references
1061 // need to be updated somehow. We avoid that by keeping the same object.
1062 ((SequenceDummy) dummyseq).become(includedSeq);
1063 dummyseq.createDatasetSequence();
1066 * Update mappings so they are now to the dataset sequence
1068 for (AlignedCodonFrame mapping : align.getCodonFrames())
1070 mapping.updateToDataset(dummyseq);
1074 * replace parsed sequence with the realised forward reference
1076 includedseqs.set(p, dummyseq);
1079 * and remove from the newseqs list
1081 newseqs.remove(dummyseq);
1086 * finally add sequences to the dataset
1088 for (SequenceI seq : includedseqs)
1090 // experimental: mapping-based 'alignment' to query sequence
1091 AlignmentUtils.alignSequenceAs(seq, align,
1092 String.valueOf(align.getGapCharacter()), false, true);
1094 // rename sequences if GFF handler requested this
1095 // TODO a more elegant way e.g. gffHelper.postProcess(newseqs) ?
1096 SequenceFeature[] sfs = seq.getSequenceFeatures();
1099 String newName = (String) sfs[0].getValue(GffHelperI.RENAME_TOKEN);
1100 if (newName != null)
1102 seq.setName(newName);
1105 align.addSequence(seq);
1110 * Process a ## directive
1116 * @throws IOException
1118 protected void processGffPragma(String line,
1119 Map<String, String> gffProps, AlignmentI align,
1120 List<SequenceI> newseqs) throws IOException
1123 if ("###".equals(line))
1125 // close off any open 'forward references'
1129 String[] tokens = line.substring(2).split(" ");
1130 String pragma = tokens[0];
1131 String value = tokens.length == 1 ? null : tokens[1];
1133 if ("gff-version".equalsIgnoreCase(pragma))
1139 // value may be e.g. "3.1.2"
1140 gffVersion = Integer.parseInt(value.split("\\.")[0]);
1141 } catch (NumberFormatException e)
1147 else if ("sequence-region".equalsIgnoreCase(pragma))
1149 // could capture <seqid start end> if wanted here
1151 else if ("feature-ontology".equalsIgnoreCase(pragma))
1153 // should resolve against the specified feature ontology URI
1155 else if ("attribute-ontology".equalsIgnoreCase(pragma))
1157 // URI of attribute ontology - not currently used in GFF3
1159 else if ("source-ontology".equalsIgnoreCase(pragma))
1161 // URI of source ontology - not currently used in GFF3
1163 else if ("species-build".equalsIgnoreCase(pragma))
1165 // save URI of specific NCBI taxon version of annotations
1166 gffProps.put("species-build", value);
1168 else if ("fasta".equalsIgnoreCase(pragma))
1170 // process the rest of the file as a fasta file and replace any dummy
1172 processAsFasta(align, newseqs);
1176 System.err.println("Ignoring unknown pragma: " + line);