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.util.ColorUtils;
39 import jalview.util.MapList;
40 import jalview.util.ParseHtmlBodyAndLinks;
41 import jalview.util.StringUtils;
43 import java.awt.Color;
44 import java.io.IOException;
45 import java.util.ArrayList;
46 import java.util.Arrays;
47 import java.util.Collections;
48 import java.util.Comparator;
49 import java.util.HashMap;
50 import java.util.HashSet;
51 import java.util.List;
53 import java.util.Map.Entry;
57 * Parses and writes features files, which may be in Jalview, GFF2 or GFF3
58 * format. These are tab-delimited formats but with differences in the use of
61 * A Jalview feature file may define feature colours and then declare that the
62 * remainder of the file is in GFF format with the line 'GFF'.
64 * GFF3 files may include alignment mappings for features, which Jalview will
65 * attempt to model, and may include sequence data following a ##FASTA line.
72 public class FeaturesFile extends AlignFile implements FeaturesSourceI
74 private static final String ID_NOT_SPECIFIED = "ID_NOT_SPECIFIED";
76 private static final String NOTE = "Note";
78 protected static final String TAB = "\t";
80 protected static final String GFF_VERSION = "##gff-version";
82 private static final Comparator<String> SORT_NULL_LAST = new Comparator<String>()
85 public int compare(String o1, String o2)
89 return o2 == null ? 0 : 1;
91 return (o2 == null ? -1 : o1.compareTo(o2));
95 private AlignmentI lastmatchedAl = null;
97 private SequenceIdMatcher matcher = null;
99 protected AlignmentI dataset;
101 protected int gffVersion;
104 * Creates a new FeaturesFile object.
106 public FeaturesFile()
111 * Constructor which does not parse the file immediately
115 * @throws IOException
117 public FeaturesFile(String inFile, DataSourceType paste)
120 super(false, inFile, paste);
125 * @throws IOException
127 public FeaturesFile(FileParse source) throws IOException
133 * Constructor that optionally parses the file immediately
135 * @param parseImmediately
138 * @throws IOException
140 public FeaturesFile(boolean parseImmediately, String inFile,
144 super(parseImmediately, inFile, type);
148 * Parse GFF or sequence features file using case-independent matching,
152 * - alignment/dataset containing sequences that are to be annotated
154 * - hashtable to store feature colour definitions
156 * - process html strings into plain text
157 * @return true if features were added
159 public boolean parse(AlignmentI align,
160 Map<String, FeatureColourI> colours, boolean removeHTML)
162 return parse(align, colours, removeHTML, false);
166 * Extends the default addProperties by also adding peptide-to-cDNA mappings
167 * (if any) derived while parsing a GFF file
170 public void addProperties(AlignmentI al)
172 super.addProperties(al);
173 if (dataset != null && dataset.getCodonFrames() != null)
175 AlignmentI ds = (al.getDataset() == null) ? al : al.getDataset();
176 for (AlignedCodonFrame codons : dataset.getCodonFrames())
178 ds.addCodonFrame(codons);
184 * Parse GFF or Jalview format sequence features file
187 * - alignment/dataset containing sequences that are to be annotated
189 * - hashtable to store feature colour definitions
191 * - process html strings into plain text
192 * @param relaxedIdmatching
193 * - when true, ID matches to compound sequence IDs are allowed
194 * @return true if features were added
196 public boolean parse(AlignmentI align,
197 Map<String, FeatureColourI> colours, boolean removeHTML,
198 boolean relaxedIdmatching)
200 Map<String, String> gffProps = new HashMap<String, String>();
202 * keep track of any sequences we try to create from the data
204 List<SequenceI> newseqs = new ArrayList<SequenceI>();
210 String featureGroup = null;
212 while ((line = nextLine()) != null)
214 // skip comments/process pragmas
215 if (line.length() == 0 || line.startsWith("#"))
217 if (line.toLowerCase().startsWith("##"))
219 processGffPragma(line, gffProps, align, newseqs);
224 gffColumns = line.split("\\t"); // tab as regex
225 if (gffColumns.length == 1)
227 if (line.trim().equalsIgnoreCase("GFF"))
230 * Jalview features file with appended GFF
231 * assume GFF2 (though it may declare ##gff-version 3)
238 if (gffColumns.length > 1 && gffColumns.length < 4)
241 * if 2 or 3 tokens, we anticipate either 'startgroup', 'endgroup' or
242 * a feature type colour specification
244 String ft = gffColumns[0];
245 if (ft.equalsIgnoreCase("startgroup"))
247 featureGroup = gffColumns[1];
249 else if (ft.equalsIgnoreCase("endgroup"))
251 // We should check whether this is the current group,
252 // but at present there's no way of showing more than 1 group
257 String colscheme = gffColumns[1];
258 FeatureColourI colour = FeatureColour
259 .parseJalviewFeatureColour(colscheme);
262 colours.put(ft, colour);
269 * if not a comment, GFF pragma, startgroup, endgroup or feature
270 * colour specification, that just leaves a feature details line
271 * in either Jalview or GFF format
275 parseJalviewFeature(line, gffColumns, align, colours, removeHTML,
276 relaxedIdmatching, featureGroup);
280 parseGff(gffColumns, align, relaxedIdmatching, newseqs);
284 } catch (Exception ex)
286 // should report somewhere useful for UI if necessary
287 warningMessage = ((warningMessage == null) ? "" : warningMessage)
288 + "Parsing error at\n" + line;
289 System.out.println("Error parsing feature file: " + ex + "\n" + line);
290 ex.printStackTrace(System.err);
296 * experimental - add any dummy sequences with features to the alignment
297 * - we need them for Ensembl feature extraction - though maybe not otherwise
299 for (SequenceI newseq : newseqs)
301 if (newseq.getFeatures().hasFeatures())
303 align.addSequence(newseq);
310 * Try to parse a Jalview format feature specification and add it as a
311 * sequence feature to any matching sequences in the alignment. Returns true
312 * if successful (a feature was added), or false if not.
317 * @param featureColours
319 * @param relaxedIdmatching
320 * @param featureGroup
322 protected boolean parseJalviewFeature(String line, String[] gffColumns,
323 AlignmentI alignment, Map<String, FeatureColourI> featureColours,
324 boolean removeHTML, boolean relaxedIdMatching, String featureGroup)
327 * tokens: description seqid seqIndex start end type [score]
329 if (gffColumns.length < 6)
331 System.err.println("Ignoring feature line '" + line
332 + "' with too few columns (" + gffColumns.length + ")");
335 String desc = gffColumns[0];
336 String seqId = gffColumns[1];
337 SequenceI seq = findSequence(seqId, alignment, null, relaxedIdMatching);
339 if (!ID_NOT_SPECIFIED.equals(seqId))
341 seq = findSequence(seqId, alignment, null, relaxedIdMatching);
347 String seqIndex = gffColumns[2];
350 int idx = Integer.parseInt(seqIndex);
351 seq = alignment.getSequenceAt(idx);
352 } catch (NumberFormatException ex)
354 System.err.println("Invalid sequence index: " + seqIndex);
360 System.out.println("Sequence not found: " + line);
364 int startPos = Integer.parseInt(gffColumns[3]);
365 int endPos = Integer.parseInt(gffColumns[4]);
367 String ft = gffColumns[5];
369 if (!featureColours.containsKey(ft))
372 * Perhaps an old style groups file with no colours -
373 * synthesize a colour from the feature type
375 Color colour = ColorUtils.createColourFromName(ft);
376 featureColours.put(ft, new FeatureColour(colour));
378 SequenceFeature sf = new SequenceFeature(ft, desc, "", startPos,
379 endPos, featureGroup);
380 if (gffColumns.length > 6)
382 float score = Float.NaN;
385 score = new Float(gffColumns[6]).floatValue();
386 // update colourgradient bounds if allowed to
387 } catch (NumberFormatException ex)
394 parseDescriptionHTML(sf, removeHTML);
396 seq.addSequenceFeature(sf);
399 && (seq = alignment.findName(seq, seqId, false)) != null)
401 seq.addSequenceFeature(new SequenceFeature(sf));
407 * clear any temporary handles used to speed up ID matching
409 protected void resetMatcher()
411 lastmatchedAl = null;
416 * Returns a sequence matching the given id, as follows
418 * <li>strict matching is on exact sequence name</li>
419 * <li>relaxed matching allows matching on a token within the sequence name,
421 * <li>first tries to find a match in the alignment sequences</li>
422 * <li>else tries to find a match in the new sequences already generated while
423 * parsing the features file</li>
424 * <li>else creates a new placeholder sequence, adds it to the new sequences
425 * list, and returns it</li>
431 * @param relaxedIdMatching
435 protected SequenceI findSequence(String seqId, AlignmentI align,
436 List<SequenceI> newseqs, boolean relaxedIdMatching)
438 // TODO encapsulate in SequenceIdMatcher, share the matcher
439 // with the GffHelper (removing code duplication)
440 SequenceI match = null;
441 if (relaxedIdMatching)
443 if (lastmatchedAl != align)
445 lastmatchedAl = align;
446 matcher = new SequenceIdMatcher(align.getSequencesArray());
449 matcher.addAll(newseqs);
452 match = matcher.findIdMatch(seqId);
456 match = align.findName(seqId, true);
457 if (match == null && newseqs != null)
459 for (SequenceI m : newseqs)
461 if (seqId.equals(m.getName()))
469 if (match == null && newseqs != null)
471 match = new SequenceDummy(seqId);
472 if (relaxedIdMatching)
474 matcher.addAll(Arrays.asList(new SequenceI[] { match }));
476 // add dummy sequence to the newseqs list
482 public void parseDescriptionHTML(SequenceFeature sf, boolean removeHTML)
484 if (sf.getDescription() == null)
488 ParseHtmlBodyAndLinks parsed = new ParseHtmlBodyAndLinks(
489 sf.getDescription(), removeHTML, newline);
493 sf.setDescription(parsed.getNonHtmlContent());
496 for (String link : parsed.getLinks())
504 * generate a features file for seqs includes non-pos features by default.
507 * source of sequence features
509 * hash of feature types and colours
510 * @return features file contents
512 public String printJalviewFormat(SequenceI[] sequences,
513 Map<String, FeatureColourI> visible)
515 return printJalviewFormat(sequences, visible, true, true);
519 * generate a features file for seqs with colours from visible (if any)
524 * hash of Colours for each feature type
526 * when true only feature types in 'visible' will be output
528 * indicates if non-positional features should be output (regardless
530 * @return features file contents
532 public String printJalviewFormat(SequenceI[] sequences,
533 Map<String, FeatureColourI> visible, boolean visOnly,
536 if (visOnly && !nonpos && (visible == null || visible.isEmpty()))
538 // no point continuing.
539 return "No Features Visible";
543 * write out feature colours (if we know them)
545 // TODO: decide if feature links should also be written here ?
546 StringBuilder out = new StringBuilder(256);
547 if (visible != null && visOnly) // todo why visOnly test?
549 for (Entry<String, FeatureColourI> featureColour : visible.entrySet())
551 FeatureColourI colour = featureColour.getValue();
552 out.append(colour.toJalviewFormat(featureColour.getKey())).append(
557 // Work out which groups are both present and visible
558 Set<String> groups = new HashSet<String>();
559 String[] types = visible == null ? null : visible.keySet().toArray(
560 new String[visible.keySet().size()]);
562 for (int i = 0; i < sequences.length; i++)
564 groups.addAll(sequences[i].getFeatures()
565 .getFeatureGroups(true, types));
568 groups.addAll(sequences[i].getFeatures().getFeatureGroups(false,
574 * sort distinct groups so null group is output last
576 List<String> sortedGroups = new ArrayList<String>(groups);
577 Collections.sort(sortedGroups, SORT_NULL_LAST);
579 // TODO check where null group should be output
580 boolean foundSome = false;
581 for (String group : sortedGroups)
586 out.append("STARTGROUP").append(TAB);
592 * output features within groups (non-positional first if wanted)
594 for (int i = 0; i < sequences.length; i++)
596 List<SequenceFeature> features = new ArrayList<SequenceFeature>();
599 features.addAll(sequences[i].getFeatures().getFeaturesForGroup(
600 false, group, types));
602 features.addAll(sequences[i].getFeatures().getFeaturesForGroup(
603 true, group, types));
605 for (SequenceFeature sequenceFeature : features)
607 // we have features to output
609 if (sequenceFeature.description == null
610 || sequenceFeature.description.equals(""))
612 out.append(sequenceFeature.type).append(TAB);
616 if (sequenceFeature.links != null
617 && sequenceFeature.getDescription().indexOf("<html>") == -1)
619 out.append("<html>");
622 out.append(sequenceFeature.description);
623 if (sequenceFeature.links != null)
625 for (int l = 0; l < sequenceFeature.links.size(); l++)
627 String label = sequenceFeature.links.elementAt(l);
628 String href = label.substring(label.indexOf("|") + 1);
629 label = label.substring(0, label.indexOf("|"));
631 if (sequenceFeature.description.indexOf(href) == -1)
633 out.append(" <a href=\"" + href + "\">" + label + "</a>");
637 if (sequenceFeature.getDescription().indexOf("</html>") == -1)
639 out.append("</html>");
645 out.append(sequences[i].getName());
646 out.append("\t-1\t");
647 out.append(sequenceFeature.begin);
649 out.append(sequenceFeature.end);
651 out.append(sequenceFeature.type);
652 if (!Float.isNaN(sequenceFeature.score))
655 out.append(sequenceFeature.score);
663 out.append("ENDGROUP").append(TAB);
669 return foundSome ? out.toString() : "No Features Visible";
673 * Parse method that is called when a GFF file is dragged to the desktop
678 AlignViewportI av = getViewport();
681 if (av.getAlignment() != null)
683 dataset = av.getAlignment().getDataset();
687 // working in the applet context ?
688 dataset = av.getAlignment();
693 dataset = new Alignment(new SequenceI[] {});
696 Map<String, FeatureColourI> featureColours = new HashMap<String, FeatureColourI>();
697 boolean parseResult = parse(dataset, featureColours, false, true);
700 // pass error up somehow
704 // update viewport with the dataset data ?
708 setSeqs(dataset.getSequencesArray());
713 * Implementation of unused abstract method
715 * @return error message
718 public String print(SequenceI[] sqs, boolean jvsuffix)
720 System.out.println("Use printGffFormat() or printJalviewFormat()");
725 * Returns features output in GFF2 format, including hidden and non-positional
729 * the sequences whose features are to be output
731 * a map whose keys are the type names of visible features
734 public String printGffFormat(SequenceI[] sequences,
735 Map<String, FeatureColourI> visible)
737 return printGffFormat(sequences, visible, true, true);
741 * Returns features output in GFF2 format
744 * the sequences whose features are to be output
746 * a map whose keys are the type names of visible features
747 * @param outputVisibleOnly
748 * @param includeNonPositionalFeatures
751 public String printGffFormat(SequenceI[] sequences,
752 Map<String, FeatureColourI> visible, boolean outputVisibleOnly,
753 boolean includeNonPositionalFeatures)
755 StringBuilder out = new StringBuilder(256);
756 int version = gffVersion == 0 ? 2 : gffVersion;
757 out.append(String.format("%s %d\n", GFF_VERSION, version));
760 for (SequenceI seq : sequences)
762 SequenceFeature[] features = seq.getSequenceFeatures();
763 if (features != null)
765 for (SequenceFeature sf : features)
767 isnonpos = sf.begin == 0 && sf.end == 0;
768 if (!includeNonPositionalFeatures && isnonpos)
771 * ignore non-positional features if not wanted
775 // TODO why the test !isnonpos here?
776 // what about not visible non-positional features?
777 if (!isnonpos && outputVisibleOnly
778 && !visible.containsKey(sf.type))
781 * ignore not visible features if not wanted
786 source = sf.featureGroup;
789 source = sf.getDescription();
792 out.append(seq.getName());
798 out.append(sf.begin);
802 out.append(sf.score);
805 int strand = sf.getStrand();
806 out.append(strand == 1 ? "+" : (strand == -1 ? "-" : "."));
809 String phase = sf.getPhase();
810 out.append(phase == null ? "." : phase);
812 // miscellaneous key-values (GFF column 9)
813 String attributes = sf.getAttributes();
814 if (attributes != null)
816 out.append(TAB).append(attributes);
824 return out.toString();
828 * Returns a mapping given list of one or more Align descriptors (exonerate
831 * @param alignedRegions
832 * a list of "Align fromStart toStart fromCount"
833 * @param mapIsFromCdna
834 * if true, 'from' is dna, else 'from' is protein
836 * either 1 (forward) or -1 (reverse)
838 * @throws IOException
840 protected MapList constructCodonMappingFromAlign(
841 List<String> alignedRegions, boolean mapIsFromCdna, int strand)
846 throw new IOException(
847 "Invalid strand for a codon mapping (cannot be 0)");
849 int regions = alignedRegions.size();
850 // arrays to hold [start, end] for each aligned region
851 int[] fromRanges = new int[regions * 2]; // from dna
852 int[] toRanges = new int[regions * 2]; // to protein
853 int fromRangesIndex = 0;
854 int toRangesIndex = 0;
856 for (String range : alignedRegions)
859 * Align mapFromStart mapToStart mapFromCount
860 * e.g. if mapIsFromCdna
861 * Align 11270 143 120
863 * 120 bases from pos 11270 align to pos 143 in peptide
864 * if !mapIsFromCdna this would instead be
867 String[] tokens = range.split(" ");
868 if (tokens.length != 3)
870 throw new IOException("Wrong number of fields for Align");
877 fromStart = Integer.parseInt(tokens[0]);
878 toStart = Integer.parseInt(tokens[1]);
879 fromCount = Integer.parseInt(tokens[2]);
880 } catch (NumberFormatException nfe)
882 throw new IOException("Invalid number in Align field: "
887 * Jalview always models from dna to protein, so adjust values if the
888 * GFF mapping is from protein to dna
893 int temp = fromStart;
897 fromRanges[fromRangesIndex++] = fromStart;
898 fromRanges[fromRangesIndex++] = fromStart + strand * (fromCount - 1);
901 * If a codon has an intron gap, there will be contiguous 'toRanges';
902 * this is handled for us by the MapList constructor.
903 * (It is not clear that exonerate ever generates this case)
905 toRanges[toRangesIndex++] = toStart;
906 toRanges[toRangesIndex++] = toStart + (fromCount - 1) / 3;
909 return new MapList(fromRanges, toRanges, 3, 1);
913 * Parse a GFF format feature. This may include creating a 'dummy' sequence to
914 * hold the feature, or for its mapped sequence, or both, to be resolved
915 * either later in the GFF file (##FASTA section), or when the user loads
916 * additional sequences.
920 * @param relaxedIdMatching
924 protected SequenceI parseGff(String[] gffColumns, AlignmentI alignment,
925 boolean relaxedIdMatching, List<SequenceI> newseqs)
928 * GFF: seqid source type start end score strand phase [attributes]
930 if (gffColumns.length < 5)
932 System.err.println("Ignoring GFF feature line with too few columns ("
933 + gffColumns.length + ")");
938 * locate referenced sequence in alignment _or_
939 * as a forward or external reference (SequenceDummy)
941 String seqId = gffColumns[0];
942 SequenceI seq = findSequence(seqId, alignment, newseqs,
945 SequenceFeature sf = null;
946 GffHelperI helper = GffHelperFactory.getHelper(gffColumns);
951 sf = helper.processGff(seq, gffColumns, alignment, newseqs,
955 seq.addSequenceFeature(sf);
956 while ((seq = alignment.findName(seq, seqId, true)) != null)
958 seq.addSequenceFeature(new SequenceFeature(sf));
961 } catch (IOException e)
963 System.err.println("GFF parsing failed with: " + e.getMessage());
972 * Process the 'column 9' data of the GFF file. This is less formally defined,
973 * and its interpretation will vary depending on the tool that has generated
979 protected void processGffColumnNine(String attributes, SequenceFeature sf)
981 sf.setAttributes(attributes);
984 * Parse attributes in column 9 and add them to the sequence feature's
985 * 'otherData' table; use Note as a best proxy for description
987 char nameValueSeparator = gffVersion == 3 ? '=' : ' ';
988 // TODO check we don't break GFF2 values which include commas here
989 Map<String, List<String>> nameValues = GffHelperBase
990 .parseNameValuePairs(attributes, ";", nameValueSeparator, ",");
991 for (Entry<String, List<String>> attr : nameValues.entrySet())
993 String values = StringUtils.listToDelimitedString(attr.getValue(),
995 sf.setValue(attr.getKey(), values);
996 if (NOTE.equals(attr.getKey()))
998 sf.setDescription(values);
1004 * After encountering ##fasta in a GFF3 file, process the remainder of the
1005 * file as FAST sequence data. Any placeholder sequences created during
1006 * feature parsing are updated with the actual sequences.
1010 * @throws IOException
1012 protected void processAsFasta(AlignmentI align, List<SequenceI> newseqs)
1018 } catch (IOException q)
1021 FastaFile parser = new FastaFile(this);
1022 List<SequenceI> includedseqs = parser.getSeqs();
1024 SequenceIdMatcher smatcher = new SequenceIdMatcher(newseqs);
1027 * iterate over includedseqs, and replacing matching ones with newseqs
1028 * sequences. Generic iterator not used here because we modify
1029 * includedseqs as we go
1031 for (int p = 0, pSize = includedseqs.size(); p < pSize; p++)
1033 // search for any dummy seqs that this sequence can be used to update
1034 SequenceI includedSeq = includedseqs.get(p);
1035 SequenceI dummyseq = smatcher.findIdMatch(includedSeq);
1036 if (dummyseq != null && dummyseq instanceof SequenceDummy)
1038 // probably have the pattern wrong
1039 // idea is that a flyweight proxy for a sequence ID can be created for
1040 // 1. stable reference creation
1041 // 2. addition of annotation
1042 // 3. future replacement by a real sequence
1043 // current pattern is to create SequenceDummy objects - a convenience
1044 // constructor for a Sequence.
1045 // problem is that when promoted to a real sequence, all references
1046 // need to be updated somehow. We avoid that by keeping the same object.
1047 ((SequenceDummy) dummyseq).become(includedSeq);
1048 dummyseq.createDatasetSequence();
1051 * Update mappings so they are now to the dataset sequence
1053 for (AlignedCodonFrame mapping : align.getCodonFrames())
1055 mapping.updateToDataset(dummyseq);
1059 * replace parsed sequence with the realised forward reference
1061 includedseqs.set(p, dummyseq);
1064 * and remove from the newseqs list
1066 newseqs.remove(dummyseq);
1071 * finally add sequences to the dataset
1073 for (SequenceI seq : includedseqs)
1075 // experimental: mapping-based 'alignment' to query sequence
1076 AlignmentUtils.alignSequenceAs(seq, align,
1077 String.valueOf(align.getGapCharacter()), false, true);
1079 // rename sequences if GFF handler requested this
1080 // TODO a more elegant way e.g. gffHelper.postProcess(newseqs) ?
1081 SequenceFeature[] sfs = seq.getSequenceFeatures();
1084 String newName = (String) sfs[0].getValue(GffHelperI.RENAME_TOKEN);
1085 if (newName != null)
1087 seq.setName(newName);
1090 align.addSequence(seq);
1095 * Process a ## directive
1101 * @throws IOException
1103 protected void processGffPragma(String line,
1104 Map<String, String> gffProps, AlignmentI align,
1105 List<SequenceI> newseqs) throws IOException
1108 if ("###".equals(line))
1110 // close off any open 'forward references'
1114 String[] tokens = line.substring(2).split(" ");
1115 String pragma = tokens[0];
1116 String value = tokens.length == 1 ? null : tokens[1];
1118 if ("gff-version".equalsIgnoreCase(pragma))
1124 // value may be e.g. "3.1.2"
1125 gffVersion = Integer.parseInt(value.split("\\.")[0]);
1126 } catch (NumberFormatException e)
1132 else if ("sequence-region".equalsIgnoreCase(pragma))
1134 // could capture <seqid start end> if wanted here
1136 else if ("feature-ontology".equalsIgnoreCase(pragma))
1138 // should resolve against the specified feature ontology URI
1140 else if ("attribute-ontology".equalsIgnoreCase(pragma))
1142 // URI of attribute ontology - not currently used in GFF3
1144 else if ("source-ontology".equalsIgnoreCase(pragma))
1146 // URI of source ontology - not currently used in GFF3
1148 else if ("species-build".equalsIgnoreCase(pragma))
1150 // save URI of specific NCBI taxon version of annotations
1151 gffProps.put("species-build", value);
1153 else if ("fasta".equalsIgnoreCase(pragma))
1155 // process the rest of the file as a fasta file and replace any dummy
1157 processAsFasta(align, newseqs);
1161 System.err.println("Ignoring unknown pragma: " + line);