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.HashMap;
49 import java.util.List;
51 import java.util.Map.Entry;
54 * Parses and writes features files, which may be in Jalview, GFF2 or GFF3
55 * format. These are tab-delimited formats but with differences in the use of
58 * A Jalview feature file may define feature colours and then declare that the
59 * remainder of the file is in GFF format with the line 'GFF'.
61 * GFF3 files may include alignment mappings for features, which Jalview will
62 * attempt to model, and may include sequence data following a ##FASTA line.
69 public class FeaturesFile extends AlignFile implements FeaturesSourceI
71 private static final String ID_NOT_SPECIFIED = "ID_NOT_SPECIFIED";
73 private static final String NOTE = "Note";
75 protected static final String TAB = "\t";
77 protected static final String GFF_VERSION = "##gff-version";
79 private AlignmentI lastmatchedAl = null;
81 private SequenceIdMatcher matcher = null;
83 protected AlignmentI dataset;
85 protected int gffVersion;
88 * Creates a new FeaturesFile object.
95 * Constructor which does not parse the file immediately
101 public FeaturesFile(String file, DataSourceType paste)
104 super(false, file, paste);
109 * @throws IOException
111 public FeaturesFile(FileParse source) throws IOException
117 * Constructor that optionally parses the file immediately
119 * @param parseImmediately
122 * @throws IOException
124 public FeaturesFile(boolean parseImmediately, String file,
125 DataSourceType type) throws IOException
127 super(parseImmediately, file, type);
131 * Parse GFF or sequence features file using case-independent matching,
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 * @return true if features were added
142 public boolean parse(AlignmentI align,
143 Map<String, FeatureColourI> colours, boolean removeHTML)
145 return parse(align, colours, removeHTML, false);
149 * Extends the default addProperties by also adding peptide-to-cDNA mappings
150 * (if any) derived while parsing a GFF file
153 public void addProperties(AlignmentI al)
155 super.addProperties(al);
156 if (dataset != null && dataset.getCodonFrames() != null)
158 AlignmentI ds = (al.getDataset() == null) ? al : al.getDataset();
159 for (AlignedCodonFrame codons : dataset.getCodonFrames())
161 ds.addCodonFrame(codons);
167 * Parse GFF or Jalview format sequence features file
170 * - alignment/dataset containing sequences that are to be annotated
172 * - hashtable to store feature colour definitions
174 * - process html strings into plain text
175 * @param relaxedIdmatching
176 * - when true, ID matches to compound sequence IDs are allowed
177 * @return true if features were added
179 public boolean parse(AlignmentI align,
180 Map<String, FeatureColourI> colours, boolean removeHTML,
181 boolean relaxedIdmatching)
183 Map<String, String> gffProps = new HashMap<String, String>();
185 * keep track of any sequences we try to create from the data
187 List<SequenceI> newseqs = new ArrayList<SequenceI>();
193 String featureGroup = null;
195 while ((line = nextLine()) != null)
197 // skip comments/process pragmas
198 if (line.length() == 0 || line.startsWith("#"))
200 if (line.toLowerCase().startsWith("##")
201 || line.indexOf("gff-version") > -1)
203 processGffPragma(line, gffProps, align, newseqs);
208 gffColumns = line.split("\\t"); // tab as regex
209 if (gffColumns.length == 1)
211 if (line.trim().equalsIgnoreCase("GFF"))
214 * Jalview features file with appended GFF
215 * assume GFF2 (though it may declare ##gff-version 3)
222 if (gffColumns.length > 1 && gffColumns.length < 4)
225 * if 2 or 3 tokens, we anticipate either 'startgroup', 'endgroup' or
226 * a feature type colour specification
228 String ft = gffColumns[0];
229 if (ft.equalsIgnoreCase("startgroup"))
231 featureGroup = gffColumns[1];
233 else if (ft.equalsIgnoreCase("endgroup"))
235 // We should check whether this is the current group,
236 // but at present there's no way of showing more than 1 group
241 String colscheme = gffColumns[1];
242 FeatureColourI colour = FeatureColour
243 .parseJalviewFeatureColour(colscheme);
246 colours.put(ft, colour);
253 * if not a comment, GFF pragma, startgroup, endgroup or feature
254 * colour specification, that just leaves a feature details line
255 * in either Jalview or GFF format
259 parseJalviewFeature(line, gffColumns, align, colours, removeHTML,
260 relaxedIdmatching, featureGroup);
264 parseGff(gffColumns, align, relaxedIdmatching, newseqs);
268 } catch (Exception ex)
270 // should report somewhere useful for UI if necessary
271 warningMessage = ((warningMessage == null) ? "" : warningMessage)
272 + "Parsing error at\n" + line;
273 System.out.println("Error parsing feature file: " + ex + "\n" + line);
274 ex.printStackTrace(System.err);
280 * experimental - add any dummy sequences with features to the alignment
281 * - we need them for Ensembl feature extraction - though maybe not otherwise
283 for (SequenceI newseq : newseqs)
285 if (newseq.getFeatures().hasFeatures())
287 align.addSequence(newseq);
294 * Try to parse a Jalview format feature specification and add it as a
295 * sequence feature to any matching sequences in the alignment. Returns true
296 * if successful (a feature was added), or false if not.
301 * @param featureColours
303 * @param relaxedIdmatching
304 * @param featureGroup
306 protected boolean parseJalviewFeature(String line, String[] gffColumns,
307 AlignmentI alignment, Map<String, FeatureColourI> featureColours,
308 boolean removeHTML, boolean relaxedIdMatching,
312 * tokens: description seqid seqIndex start end type [score]
314 if (gffColumns.length < 6)
316 System.err.println("Ignoring feature line '" + line
317 + "' with too few columns (" + gffColumns.length + ")");
320 String desc = gffColumns[0];
321 String seqId = gffColumns[1];
322 SequenceI seq = findSequence(seqId, alignment, null, relaxedIdMatching);
324 if (!ID_NOT_SPECIFIED.equals(seqId))
326 seq = findSequence(seqId, alignment, null, relaxedIdMatching);
332 String seqIndex = gffColumns[2];
335 int idx = Integer.parseInt(seqIndex);
336 seq = alignment.getSequenceAt(idx);
337 } catch (NumberFormatException ex)
339 System.err.println("Invalid sequence index: " + seqIndex);
345 System.out.println("Sequence not found: " + line);
349 int startPos = Integer.parseInt(gffColumns[3]);
350 int endPos = Integer.parseInt(gffColumns[4]);
352 String ft = gffColumns[5];
354 if (!featureColours.containsKey(ft))
357 * Perhaps an old style groups file with no colours -
358 * synthesize a colour from the feature type
360 Color colour = ColorUtils.createColourFromName(ft);
361 featureColours.put(ft, new FeatureColour(colour));
363 SequenceFeature sf = null;
364 if (gffColumns.length > 6)
366 float score = Float.NaN;
369 score = new Float(gffColumns[6]).floatValue();
370 } catch (NumberFormatException ex)
372 sf = new SequenceFeature(ft, desc, startPos, endPos, featureGroup);
374 sf = new SequenceFeature(ft, desc, startPos, endPos, score,
379 sf = new SequenceFeature(ft, desc, startPos, endPos, featureGroup);
382 parseDescriptionHTML(sf, removeHTML);
384 seq.addSequenceFeature(sf);
387 && (seq = alignment.findName(seq, seqId, false)) != null)
389 seq.addSequenceFeature(new SequenceFeature(sf));
395 * clear any temporary handles used to speed up ID matching
397 protected void resetMatcher()
399 lastmatchedAl = null;
404 * Returns a sequence matching the given id, as follows
406 * <li>strict matching is on exact sequence name</li>
407 * <li>relaxed matching allows matching on a token within the sequence name,
409 * <li>first tries to find a match in the alignment sequences</li>
410 * <li>else tries to find a match in the new sequences already generated while
411 * parsing the features file</li>
412 * <li>else creates a new placeholder sequence, adds it to the new sequences
413 * list, and returns it</li>
419 * @param relaxedIdMatching
423 protected SequenceI findSequence(String seqId, AlignmentI align,
424 List<SequenceI> newseqs, boolean relaxedIdMatching)
426 // TODO encapsulate in SequenceIdMatcher, share the matcher
427 // with the GffHelper (removing code duplication)
428 SequenceI match = null;
429 if (relaxedIdMatching)
431 if (lastmatchedAl != align)
433 lastmatchedAl = align;
434 matcher = new SequenceIdMatcher(align.getSequencesArray());
437 matcher.addAll(newseqs);
440 match = matcher.findIdMatch(seqId);
444 match = align.findName(seqId, true);
445 if (match == null && newseqs != null)
447 for (SequenceI m : newseqs)
449 if (seqId.equals(m.getName()))
457 if (match == null && newseqs != null)
459 match = new SequenceDummy(seqId);
460 if (relaxedIdMatching)
462 matcher.addAll(Arrays.asList(new SequenceI[] { match }));
464 // add dummy sequence to the newseqs list
470 public void parseDescriptionHTML(SequenceFeature sf, boolean removeHTML)
472 if (sf.getDescription() == null)
476 ParseHtmlBodyAndLinks parsed = new ParseHtmlBodyAndLinks(
477 sf.getDescription(), removeHTML, newline);
481 sf.setDescription(parsed.getNonHtmlContent());
484 for (String link : parsed.getLinks())
491 * Returns contents of a Jalview format features file, for visible features,
492 * as filtered by type and group. Features with a null group are displayed if
493 * their feature type is visible. Non-positional features may optionally be
494 * included (with no check on type or group).
499 * map of colour for each visible feature type
500 * @param visibleFeatureGroups
501 * @param includeNonPositional
502 * if true, include non-positional features (regardless of group or
506 public String printJalviewFormat(SequenceI[] sequences,
507 Map<String, FeatureColourI> visible,
508 List<String> visibleFeatureGroups, boolean includeNonPositional)
510 if (!includeNonPositional && (visible == null || visible.isEmpty()))
512 // no point continuing.
513 return "No Features Visible";
517 * write out feature colours (if we know them)
519 // TODO: decide if feature links should also be written here ?
520 StringBuilder out = new StringBuilder(256);
523 for (Entry<String, FeatureColourI> featureColour : visible.entrySet())
525 FeatureColourI colour = featureColour.getValue();
526 out.append(colour.toJalviewFormat(featureColour.getKey())).append(
531 String[] types = visible == null ? new String[0] : visible.keySet()
532 .toArray(new String[visible.keySet().size()]);
535 * sort groups alphabetically, and ensure that features with a
536 * null or empty group are output after those in named groups
538 List<String> sortedGroups = new ArrayList<String>(visibleFeatureGroups);
539 sortedGroups.remove(null);
540 sortedGroups.remove("");
541 Collections.sort(sortedGroups);
542 sortedGroups.add(null);
543 sortedGroups.add("");
545 boolean foundSome = false;
548 * first output any non-positional features
550 if (includeNonPositional)
552 for (int i = 0; i < sequences.length; i++)
554 String sequenceName = sequences[i].getName();
555 for (SequenceFeature feature : sequences[i].getFeatures()
556 .getNonPositionalFeatures())
559 out.append(formatJalviewFeature(sequenceName, feature));
564 for (String group : sortedGroups)
566 boolean isNamedGroup = (group != null && !"".equals(group));
570 out.append("STARTGROUP").append(TAB);
576 * output positional features within groups
578 for (int i = 0; i < sequences.length; i++)
580 String sequenceName = sequences[i].getName();
581 List<SequenceFeature> features = new ArrayList<SequenceFeature>();
582 if (types.length > 0)
584 features.addAll(sequences[i].getFeatures().getFeaturesForGroup(
585 true, group, types));
588 for (SequenceFeature sequenceFeature : features)
591 out.append(formatJalviewFeature(sequenceName, sequenceFeature));
597 out.append("ENDGROUP").append(TAB);
603 return foundSome ? out.toString() : "No Features Visible";
608 * @param sequenceName
609 * @param sequenceFeature
611 protected String formatJalviewFeature(
612 String sequenceName, SequenceFeature sequenceFeature)
614 StringBuilder out = new StringBuilder(64);
615 if (sequenceFeature.description == null
616 || sequenceFeature.description.equals(""))
618 out.append(sequenceFeature.type).append(TAB);
622 if (sequenceFeature.links != null
623 && sequenceFeature.getDescription().indexOf("<html>") == -1)
625 out.append("<html>");
628 out.append(sequenceFeature.description);
629 if (sequenceFeature.links != null)
631 for (int l = 0; l < sequenceFeature.links.size(); l++)
633 String label = sequenceFeature.links.elementAt(l);
634 String href = label.substring(label.indexOf("|") + 1);
635 label = label.substring(0, label.indexOf("|"));
637 if (sequenceFeature.description.indexOf(href) == -1)
639 out.append(" <a href=\"" + href + "\">" + label + "</a>");
643 if (sequenceFeature.getDescription().indexOf("</html>") == -1)
645 out.append("</html>");
651 out.append(sequenceName);
652 out.append("\t-1\t");
653 out.append(sequenceFeature.begin);
655 out.append(sequenceFeature.end);
657 out.append(sequenceFeature.type);
658 if (!Float.isNaN(sequenceFeature.score))
661 out.append(sequenceFeature.score);
665 return out.toString();
669 * Parse method that is called when a GFF file is dragged to the desktop
674 AlignViewportI av = getViewport();
677 if (av.getAlignment() != null)
679 dataset = av.getAlignment().getDataset();
683 // working in the applet context ?
684 dataset = av.getAlignment();
689 dataset = new Alignment(new SequenceI[] {});
692 Map<String, FeatureColourI> featureColours = new HashMap<String, FeatureColourI>();
693 boolean parseResult = parse(dataset, featureColours, false, true);
696 // pass error up somehow
700 // update viewport with the dataset data ?
704 setSeqs(dataset.getSequencesArray());
709 * Implementation of unused abstract method
711 * @return error message
714 public String print(SequenceI[] sqs, boolean jvsuffix)
716 System.out.println("Use printGffFormat() or printJalviewFormat()");
721 * Returns features output in GFF2 format
724 * the sequences whose features are to be output
726 * a map whose keys are the type names of visible features
727 * @param visibleFeatureGroups
728 * @param includeNonPositionalFeatures
731 public String printGffFormat(SequenceI[] sequences,
732 Map<String, FeatureColourI> visible,
733 List<String> visibleFeatureGroups,
734 boolean includeNonPositionalFeatures)
736 StringBuilder out = new StringBuilder(256);
738 out.append(String.format("%s %d\n", GFF_VERSION, gffVersion == 0 ? 2 : gffVersion));
740 if (!includeNonPositionalFeatures
741 && (visible == null || visible.isEmpty()))
743 return out.toString();
746 String[] types = visible == null ? new String[0] : visible.keySet()
748 new String[visible.keySet().size()]);
750 for (SequenceI seq : sequences)
752 List<SequenceFeature> features = new ArrayList<SequenceFeature>();
753 if (includeNonPositionalFeatures)
755 features.addAll(seq.getFeatures().getNonPositionalFeatures());
757 if (visible != null && !visible.isEmpty())
759 features.addAll(seq.getFeatures().getPositionalFeatures(types));
762 for (SequenceFeature sf : features)
764 String source = sf.featureGroup;
765 if (!sf.isNonPositional() && source != null
766 && !visibleFeatureGroups.contains(source))
768 // group is not visible
774 source = sf.getDescription();
777 out.append(seq.getName());
783 out.append(sf.begin);
787 out.append(sf.score);
790 int strand = sf.getStrand();
791 out.append(strand == 1 ? "+" : (strand == -1 ? "-" : "."));
794 String phase = sf.getPhase();
795 out.append(phase == null ? "." : phase);
797 // miscellaneous key-values (GFF column 9)
798 String attributes = sf.getAttributes();
799 if (attributes != null)
801 out.append(TAB).append(attributes);
808 return out.toString();
812 * Returns a mapping given list of one or more Align descriptors (exonerate
815 * @param alignedRegions
816 * a list of "Align fromStart toStart fromCount"
817 * @param mapIsFromCdna
818 * if true, 'from' is dna, else 'from' is protein
820 * either 1 (forward) or -1 (reverse)
822 * @throws IOException
824 protected MapList constructCodonMappingFromAlign(
825 List<String> alignedRegions, boolean mapIsFromCdna, int strand)
830 throw new IOException(
831 "Invalid strand for a codon mapping (cannot be 0)");
833 int regions = alignedRegions.size();
834 // arrays to hold [start, end] for each aligned region
835 int[] fromRanges = new int[regions * 2]; // from dna
836 int[] toRanges = new int[regions * 2]; // to protein
837 int fromRangesIndex = 0;
838 int toRangesIndex = 0;
840 for (String range : alignedRegions)
843 * Align mapFromStart mapToStart mapFromCount
844 * e.g. if mapIsFromCdna
845 * Align 11270 143 120
847 * 120 bases from pos 11270 align to pos 143 in peptide
848 * if !mapIsFromCdna this would instead be
851 String[] tokens = range.split(" ");
852 if (tokens.length != 3)
854 throw new IOException("Wrong number of fields for Align");
861 fromStart = Integer.parseInt(tokens[0]);
862 toStart = Integer.parseInt(tokens[1]);
863 fromCount = Integer.parseInt(tokens[2]);
864 } catch (NumberFormatException nfe)
866 throw new IOException(
867 "Invalid number in Align field: " + nfe.getMessage());
871 * Jalview always models from dna to protein, so adjust values if the
872 * GFF mapping is from protein to dna
877 int temp = fromStart;
881 fromRanges[fromRangesIndex++] = fromStart;
882 fromRanges[fromRangesIndex++] = fromStart + strand * (fromCount - 1);
885 * If a codon has an intron gap, there will be contiguous 'toRanges';
886 * this is handled for us by the MapList constructor.
887 * (It is not clear that exonerate ever generates this case)
889 toRanges[toRangesIndex++] = toStart;
890 toRanges[toRangesIndex++] = toStart + (fromCount - 1) / 3;
893 return new MapList(fromRanges, toRanges, 3, 1);
897 * Parse a GFF format feature. This may include creating a 'dummy' sequence to
898 * hold the feature, or for its mapped sequence, or both, to be resolved
899 * either later in the GFF file (##FASTA section), or when the user loads
900 * additional sequences.
904 * @param relaxedIdMatching
908 protected SequenceI parseGff(String[] gffColumns, AlignmentI alignment,
909 boolean relaxedIdMatching, List<SequenceI> newseqs)
912 * GFF: seqid source type start end score strand phase [attributes]
914 if (gffColumns.length < 5)
916 System.err.println("Ignoring GFF feature line with too few columns ("
917 + gffColumns.length + ")");
922 * locate referenced sequence in alignment _or_
923 * as a forward or external reference (SequenceDummy)
925 String seqId = gffColumns[0];
926 SequenceI seq = findSequence(seqId, alignment, newseqs,
929 SequenceFeature sf = null;
930 GffHelperI helper = GffHelperFactory.getHelper(gffColumns);
935 sf = helper.processGff(seq, gffColumns, alignment, newseqs,
939 seq.addSequenceFeature(sf);
940 while ((seq = alignment.findName(seq, seqId, true)) != null)
942 seq.addSequenceFeature(new SequenceFeature(sf));
945 } catch (IOException e)
947 System.err.println("GFF parsing failed with: " + e.getMessage());
956 * Process the 'column 9' data of the GFF file. This is less formally defined,
957 * and its interpretation will vary depending on the tool that has generated
963 protected void processGffColumnNine(String attributes, SequenceFeature sf)
965 sf.setAttributes(attributes);
968 * Parse attributes in column 9 and add them to the sequence feature's
969 * 'otherData' table; use Note as a best proxy for description
971 char nameValueSeparator = gffVersion == 3 ? '=' : ' ';
972 // TODO check we don't break GFF2 values which include commas here
973 Map<String, List<String>> nameValues = GffHelperBase
974 .parseNameValuePairs(attributes, ";", nameValueSeparator, ",");
975 for (Entry<String, List<String>> attr : nameValues.entrySet())
977 String values = StringUtils.listToDelimitedString(attr.getValue(),
979 sf.setValue(attr.getKey(), values);
980 if (NOTE.equals(attr.getKey()))
982 sf.setDescription(values);
988 * After encountering ##fasta in a GFF3 file, process the remainder of the
989 * file as FAST sequence data. Any placeholder sequences created during
990 * feature parsing are updated with the actual sequences.
994 * @throws IOException
996 protected void processAsFasta(AlignmentI align, List<SequenceI> newseqs)
1002 } catch (IOException q)
1005 FastaFile parser = new FastaFile(this);
1006 List<SequenceI> includedseqs = parser.getSeqs();
1008 SequenceIdMatcher smatcher = new SequenceIdMatcher(newseqs);
1011 * iterate over includedseqs, and replacing matching ones with newseqs
1012 * sequences. Generic iterator not used here because we modify
1013 * includedseqs as we go
1015 for (int p = 0, pSize = includedseqs.size(); p < pSize; p++)
1017 // search for any dummy seqs that this sequence can be used to update
1018 SequenceI includedSeq = includedseqs.get(p);
1019 SequenceI dummyseq = smatcher.findIdMatch(includedSeq);
1020 if (dummyseq != null && dummyseq instanceof SequenceDummy)
1022 // probably have the pattern wrong
1023 // idea is that a flyweight proxy for a sequence ID can be created for
1024 // 1. stable reference creation
1025 // 2. addition of annotation
1026 // 3. future replacement by a real sequence
1027 // current pattern is to create SequenceDummy objects - a convenience
1028 // constructor for a Sequence.
1029 // problem is that when promoted to a real sequence, all references
1030 // need to be updated somehow. We avoid that by keeping the same object.
1031 ((SequenceDummy) dummyseq).become(includedSeq);
1032 dummyseq.createDatasetSequence();
1035 * Update mappings so they are now to the dataset sequence
1037 for (AlignedCodonFrame mapping : align.getCodonFrames())
1039 mapping.updateToDataset(dummyseq);
1043 * replace parsed sequence with the realised forward reference
1045 includedseqs.set(p, dummyseq);
1048 * and remove from the newseqs list
1050 newseqs.remove(dummyseq);
1055 * finally add sequences to the dataset
1057 for (SequenceI seq : includedseqs)
1059 // experimental: mapping-based 'alignment' to query sequence
1060 AlignmentUtils.alignSequenceAs(seq, align,
1061 String.valueOf(align.getGapCharacter()), false, true);
1063 // rename sequences if GFF handler requested this
1064 // TODO a more elegant way e.g. gffHelper.postProcess(newseqs) ?
1065 List<SequenceFeature> sfs = seq.getFeatures().getPositionalFeatures();
1068 String newName = (String) sfs.get(0).getValue(
1069 GffHelperI.RENAME_TOKEN);
1070 if (newName != null)
1072 seq.setName(newName);
1075 align.addSequence(seq);
1080 * Process a ## directive
1086 * @throws IOException
1088 protected void processGffPragma(String line, Map<String, String> gffProps,
1089 AlignmentI align, List<SequenceI> newseqs) throws IOException
1092 if ("###".equals(line))
1094 // close off any open 'forward references'
1097 int startpragma = (line.charAt(1) == '#') ? 2 : 1; // lax
1098 String[] tokens = line.substring(startpragma).split(" ");
1099 String pragma = tokens[0];
1100 String value = tokens.length == 1 ? null : tokens[1];
1102 if ("gff-version".equalsIgnoreCase(pragma))
1108 // value may be e.g. "3.1.2"
1109 gffVersion = Integer.parseInt(value.split("\\.")[0]);
1110 } catch (NumberFormatException e)
1116 else if ("sequence-region".equalsIgnoreCase(pragma))
1118 // could capture <seqid start end> if wanted here
1120 else if ("feature-ontology".equalsIgnoreCase(pragma))
1122 // should resolve against the specified feature ontology URI
1124 else if ("attribute-ontology".equalsIgnoreCase(pragma))
1126 // URI of attribute ontology - not currently used in GFF3
1128 else if ("source-ontology".equalsIgnoreCase(pragma))
1130 // URI of source ontology - not currently used in GFF3
1132 else if ("species-build".equalsIgnoreCase(pragma))
1134 // save URI of specific NCBI taxon version of annotations
1135 gffProps.put("species-build", value);
1137 else if ("fasta".equalsIgnoreCase(pragma))
1139 // process the rest of the file as a fasta file and replace any dummy
1141 processAsFasta(align, newseqs);
1145 if (startpragma == 2)
1147 // only complain if it was a genuine pragma line starting with ##
1148 System.err.println("Ignoring unknown pragma: " + line);