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, DataSourceType paste)
103 super(false, inFile, paste);
108 * @throws IOException
110 public FeaturesFile(FileParse source) throws IOException
116 * Constructor that optionally parses the file immediately
118 * @param parseImmediately
121 * @throws IOException
123 public FeaturesFile(boolean parseImmediately, String inFile,
127 super(parseImmediately, inFile, 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("##"))
202 processGffPragma(line, gffProps, align, newseqs);
207 gffColumns = line.split("\\t"); // tab as regex
208 if (gffColumns.length == 1)
210 if (line.trim().equalsIgnoreCase("GFF"))
213 * Jalview features file with appended GFF
214 * assume GFF2 (though it may declare ##gff-version 3)
221 if (gffColumns.length > 1 && gffColumns.length < 4)
224 * if 2 or 3 tokens, we anticipate either 'startgroup', 'endgroup' or
225 * a feature type colour specification
227 String ft = gffColumns[0];
228 if (ft.equalsIgnoreCase("startgroup"))
230 featureGroup = gffColumns[1];
232 else if (ft.equalsIgnoreCase("endgroup"))
234 // We should check whether this is the current group,
235 // but at present there's no way of showing more than 1 group
240 String colscheme = gffColumns[1];
241 FeatureColourI colour = FeatureColour
242 .parseJalviewFeatureColour(colscheme);
245 colours.put(ft, colour);
252 * if not a comment, GFF pragma, startgroup, endgroup or feature
253 * colour specification, that just leaves a feature details line
254 * in either Jalview or GFF format
258 parseJalviewFeature(line, gffColumns, align, colours, removeHTML,
259 relaxedIdmatching, featureGroup);
263 parseGff(gffColumns, align, relaxedIdmatching, newseqs);
267 } catch (Exception ex)
269 // should report somewhere useful for UI if necessary
270 warningMessage = ((warningMessage == null) ? "" : warningMessage)
271 + "Parsing error at\n" + line;
272 System.out.println("Error parsing feature file: " + ex + "\n" + line);
273 ex.printStackTrace(System.err);
279 * experimental - add any dummy sequences with features to the alignment
280 * - we need them for Ensembl feature extraction - though maybe not otherwise
282 for (SequenceI newseq : newseqs)
284 if (newseq.getSequenceFeatures() != null)
286 align.addSequence(newseq);
293 * Try to parse a Jalview format feature specification and add it as a
294 * sequence feature to any matching sequences in the alignment. Returns true
295 * if successful (a feature was added), or false if not.
300 * @param featureColours
302 * @param relaxedIdmatching
303 * @param featureGroup
305 protected boolean parseJalviewFeature(String line, String[] gffColumns,
306 AlignmentI alignment, Map<String, FeatureColourI> featureColours,
307 boolean removeHTML, boolean relaxedIdMatching, String featureGroup)
310 * tokens: description seqid seqIndex start end type [score]
312 if (gffColumns.length < 6)
314 System.err.println("Ignoring feature line '" + line
315 + "' with too few columns (" + gffColumns.length + ")");
318 String desc = gffColumns[0];
319 String seqId = gffColumns[1];
320 SequenceI seq = findSequence(seqId, alignment, null, relaxedIdMatching);
322 if (!ID_NOT_SPECIFIED.equals(seqId))
324 seq = findSequence(seqId, alignment, null, relaxedIdMatching);
330 String seqIndex = gffColumns[2];
333 int idx = Integer.parseInt(seqIndex);
334 seq = alignment.getSequenceAt(idx);
335 } catch (NumberFormatException ex)
337 System.err.println("Invalid sequence index: " + seqIndex);
343 System.out.println("Sequence not found: " + line);
347 int startPos = Integer.parseInt(gffColumns[3]);
348 int endPos = Integer.parseInt(gffColumns[4]);
350 String ft = gffColumns[5];
352 if (!featureColours.containsKey(ft))
355 * Perhaps an old style groups file with no colours -
356 * synthesize a colour from the feature type
358 UserColourScheme ucs = new UserColourScheme(ft);
359 featureColours.put(ft, new FeatureColour(ucs.findColour('A')));
361 SequenceFeature sf = new SequenceFeature(ft, desc, "", startPos,
362 endPos, featureGroup);
363 if (gffColumns.length > 6)
365 float score = Float.NaN;
368 score = new Float(gffColumns[6]).floatValue();
369 // update colourgradient bounds if allowed to
370 } catch (NumberFormatException ex)
377 parseDescriptionHTML(sf, removeHTML);
379 seq.addSequenceFeature(sf);
382 && (seq = alignment.findName(seq, seqId, false)) != null)
384 seq.addSequenceFeature(new SequenceFeature(sf));
390 * clear any temporary handles used to speed up ID matching
392 protected void resetMatcher()
394 lastmatchedAl = null;
399 * Returns a sequence matching the given id, as follows
401 * <li>strict matching is on exact sequence name</li>
402 * <li>relaxed matching allows matching on a token within the sequence name,
404 * <li>first tries to find a match in the alignment sequences</li>
405 * <li>else tries to find a match in the new sequences already generated while
406 * parsing the features file</li>
407 * <li>else creates a new placeholder sequence, adds it to the new sequences
408 * list, and returns it</li>
414 * @param relaxedIdMatching
418 protected SequenceI findSequence(String seqId, AlignmentI align,
419 List<SequenceI> newseqs, boolean relaxedIdMatching)
421 // TODO encapsulate in SequenceIdMatcher, share the matcher
422 // with the GffHelper (removing code duplication)
423 SequenceI match = null;
424 if (relaxedIdMatching)
426 if (lastmatchedAl != align)
428 lastmatchedAl = align;
429 matcher = new SequenceIdMatcher(align.getSequencesArray());
432 matcher.addAll(newseqs);
435 match = matcher.findIdMatch(seqId);
439 match = align.findName(seqId, true);
440 if (match == null && newseqs != null)
442 for (SequenceI m : newseqs)
444 if (seqId.equals(m.getName()))
452 if (match == null && newseqs != null)
454 match = new SequenceDummy(seqId);
455 if (relaxedIdMatching)
457 matcher.addAll(Arrays.asList(new SequenceI[] { match }));
459 // add dummy sequence to the newseqs list
465 public void parseDescriptionHTML(SequenceFeature sf, boolean removeHTML)
467 if (sf.getDescription() == null)
471 ParseHtmlBodyAndLinks parsed = new ParseHtmlBodyAndLinks(
472 sf.getDescription(), removeHTML, newline);
474 sf.description = (removeHTML) ? parsed.getNonHtmlContent()
476 for (String link : parsed.getLinks())
484 * generate a features file for seqs includes non-pos features by default.
487 * source of sequence features
489 * hash of feature types and colours
490 * @return features file contents
492 public String printJalviewFormat(SequenceI[] sequences,
493 Map<String, FeatureColourI> visible)
495 return printJalviewFormat(sequences, visible, true, true);
499 * generate a features file for seqs with colours from visible (if any)
504 * hash of Colours for each feature type
506 * when true only feature types in 'visible' will be output
508 * indicates if non-positional features should be output (regardless
510 * @return features file contents
512 public String printJalviewFormat(SequenceI[] sequences,
513 Map<String, FeatureColourI> visible, boolean visOnly,
516 StringBuilder out = new StringBuilder(256);
517 boolean featuresGen = false;
518 if (visOnly && !nonpos && (visible == null || visible.size() < 1))
520 // no point continuing.
521 return "No Features Visible";
524 if (visible != null && visOnly)
526 // write feature colours only if we're given them and we are generating
528 // TODO: decide if feature links should also be written here ?
529 Iterator<String> en = visible.keySet().iterator();
532 String featureType = en.next().toString();
533 FeatureColourI colour = visible.get(featureType);
534 out.append(colour.toJalviewFormat(featureType)).append(newline);
538 // Work out which groups are both present and visible
539 List<String> groups = new ArrayList<String>();
541 boolean isnonpos = false;
543 SequenceFeature[] features;
544 for (int i = 0; i < sequences.length; i++)
546 features = sequences[i].getSequenceFeatures();
547 if (features != null)
549 for (int j = 0; j < features.length; j++)
551 isnonpos = features[j].begin == 0 && features[j].end == 0;
552 if ((!nonpos && isnonpos)
553 || (!isnonpos && visOnly && !visible
554 .containsKey(features[j].type)))
559 if (features[j].featureGroup != null
560 && !groups.contains(features[j].featureGroup))
562 groups.add(features[j].featureGroup);
571 if (groups.size() > 0 && groupIndex < groups.size())
573 group = groups.get(groupIndex);
575 out.append("STARTGROUP").append(TAB);
584 for (int i = 0; i < sequences.length; i++)
586 features = sequences[i].getSequenceFeatures();
587 if (features != null)
589 for (SequenceFeature sequenceFeature : features)
591 isnonpos = sequenceFeature.begin == 0
592 && sequenceFeature.end == 0;
593 if ((!nonpos && isnonpos)
594 || (!isnonpos && visOnly && !visible
595 .containsKey(sequenceFeature.type)))
597 // skip if feature is nonpos and we ignore them or if we only
598 // output visible and it isn't non-pos and it's not visible
603 && (sequenceFeature.featureGroup == null || !sequenceFeature.featureGroup
609 if (group == null && sequenceFeature.featureGroup != null)
613 // we have features to output
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
644 if (sequenceFeature.getDescription().indexOf("</html>") == -1)
646 out.append("</html>");
652 out.append(sequences[i].getName());
653 out.append("\t-1\t");
654 out.append(sequenceFeature.begin);
656 out.append(sequenceFeature.end);
658 out.append(sequenceFeature.type);
659 if (!Float.isNaN(sequenceFeature.score))
662 out.append(sequenceFeature.score);
671 out.append("ENDGROUP").append(TAB);
681 } while (groupIndex < groups.size() + 1);
685 return "No Features Visible";
688 return out.toString();
692 * Parse method that is called when a GFF file is dragged to the desktop
697 AlignViewportI av = getViewport();
700 if (av.getAlignment() != null)
702 dataset = av.getAlignment().getDataset();
706 // working in the applet context ?
707 dataset = av.getAlignment();
712 dataset = new Alignment(new SequenceI[] {});
715 Map<String, FeatureColourI> featureColours = new HashMap<String, FeatureColourI>();
716 boolean parseResult = parse(dataset, featureColours, false, true);
719 // pass error up somehow
723 // update viewport with the dataset data ?
727 setSeqs(dataset.getSequencesArray());
732 * Implementation of unused abstract method
734 * @return error message
737 public String print(SequenceI[] sqs, boolean jvsuffix)
739 System.out.println("Use printGffFormat() or printJalviewFormat()");
744 * Returns features output in GFF2 format, including hidden and non-positional
748 * the sequences whose features are to be output
750 * a map whose keys are the type names of visible features
753 public String printGffFormat(SequenceI[] sequences,
754 Map<String, FeatureColourI> visible)
756 return printGffFormat(sequences, visible, true, true);
760 * Returns features output in GFF2 format
763 * the sequences whose features are to be output
765 * a map whose keys are the type names of visible features
766 * @param outputVisibleOnly
767 * @param includeNonPositionalFeatures
770 public String printGffFormat(SequenceI[] sequences,
771 Map<String, FeatureColourI> visible, boolean outputVisibleOnly,
772 boolean includeNonPositionalFeatures)
774 StringBuilder out = new StringBuilder(256);
775 int version = gffVersion == 0 ? 2 : gffVersion;
776 out.append(String.format("%s %d\n", GFF_VERSION, version));
779 for (SequenceI seq : sequences)
781 SequenceFeature[] features = seq.getSequenceFeatures();
782 if (features != null)
784 for (SequenceFeature sf : features)
786 isnonpos = sf.begin == 0 && sf.end == 0;
787 if (!includeNonPositionalFeatures && isnonpos)
790 * ignore non-positional features if not wanted
794 // TODO why the test !isnonpos here?
795 // what about not visible non-positional features?
796 if (!isnonpos && outputVisibleOnly
797 && !visible.containsKey(sf.type))
800 * ignore not visible features if not wanted
805 source = sf.featureGroup;
808 source = sf.getDescription();
811 out.append(seq.getName());
817 out.append(sf.begin);
821 out.append(sf.score);
824 int strand = sf.getStrand();
825 out.append(strand == 1 ? "+" : (strand == -1 ? "-" : "."));
828 String phase = sf.getPhase();
829 out.append(phase == null ? "." : phase);
831 // miscellaneous key-values (GFF column 9)
832 String attributes = sf.getAttributes();
833 if (attributes != null)
835 out.append(TAB).append(attributes);
843 return out.toString();
847 * Returns a mapping given list of one or more Align descriptors (exonerate
850 * @param alignedRegions
851 * a list of "Align fromStart toStart fromCount"
852 * @param mapIsFromCdna
853 * if true, 'from' is dna, else 'from' is protein
855 * either 1 (forward) or -1 (reverse)
857 * @throws IOException
859 protected MapList constructCodonMappingFromAlign(
860 List<String> alignedRegions, boolean mapIsFromCdna, int strand)
865 throw new IOException(
866 "Invalid strand for a codon mapping (cannot be 0)");
868 int regions = alignedRegions.size();
869 // arrays to hold [start, end] for each aligned region
870 int[] fromRanges = new int[regions * 2]; // from dna
871 int[] toRanges = new int[regions * 2]; // to protein
872 int fromRangesIndex = 0;
873 int toRangesIndex = 0;
875 for (String range : alignedRegions)
878 * Align mapFromStart mapToStart mapFromCount
879 * e.g. if mapIsFromCdna
880 * Align 11270 143 120
882 * 120 bases from pos 11270 align to pos 143 in peptide
883 * if !mapIsFromCdna this would instead be
886 String[] tokens = range.split(" ");
887 if (tokens.length != 3)
889 throw new IOException("Wrong number of fields for Align");
896 fromStart = Integer.parseInt(tokens[0]);
897 toStart = Integer.parseInt(tokens[1]);
898 fromCount = Integer.parseInt(tokens[2]);
899 } catch (NumberFormatException nfe)
901 throw new IOException("Invalid number in Align field: "
906 * Jalview always models from dna to protein, so adjust values if the
907 * GFF mapping is from protein to dna
912 int temp = fromStart;
916 fromRanges[fromRangesIndex++] = fromStart;
917 fromRanges[fromRangesIndex++] = fromStart + strand * (fromCount - 1);
920 * If a codon has an intron gap, there will be contiguous 'toRanges';
921 * this is handled for us by the MapList constructor.
922 * (It is not clear that exonerate ever generates this case)
924 toRanges[toRangesIndex++] = toStart;
925 toRanges[toRangesIndex++] = toStart + (fromCount - 1) / 3;
928 return new MapList(fromRanges, toRanges, 3, 1);
932 * Parse a GFF format feature. This may include creating a 'dummy' sequence to
933 * hold the feature, or for its mapped sequence, or both, to be resolved
934 * either later in the GFF file (##FASTA section), or when the user loads
935 * additional sequences.
939 * @param relaxedIdMatching
943 protected SequenceI parseGff(String[] gffColumns, AlignmentI alignment,
944 boolean relaxedIdMatching, List<SequenceI> newseqs)
947 * GFF: seqid source type start end score strand phase [attributes]
949 if (gffColumns.length < 5)
951 System.err.println("Ignoring GFF feature line with too few columns ("
952 + gffColumns.length + ")");
957 * locate referenced sequence in alignment _or_
958 * as a forward or external reference (SequenceDummy)
960 String seqId = gffColumns[0];
961 SequenceI seq = findSequence(seqId, alignment, newseqs,
964 SequenceFeature sf = null;
965 GffHelperI helper = GffHelperFactory.getHelper(gffColumns);
970 sf = helper.processGff(seq, gffColumns, alignment, newseqs,
974 seq.addSequenceFeature(sf);
975 while ((seq = alignment.findName(seq, seqId, true)) != null)
977 seq.addSequenceFeature(new SequenceFeature(sf));
980 } catch (IOException e)
982 System.err.println("GFF parsing failed with: " + e.getMessage());
991 * Process the 'column 9' data of the GFF file. This is less formally defined,
992 * and its interpretation will vary depending on the tool that has generated
998 protected void processGffColumnNine(String attributes, SequenceFeature sf)
1000 sf.setAttributes(attributes);
1003 * Parse attributes in column 9 and add them to the sequence feature's
1004 * 'otherData' table; use Note as a best proxy for description
1006 char nameValueSeparator = gffVersion == 3 ? '=' : ' ';
1007 // TODO check we don't break GFF2 values which include commas here
1008 Map<String, List<String>> nameValues = GffHelperBase
1009 .parseNameValuePairs(attributes, ";", nameValueSeparator, ",");
1010 for (Entry<String, List<String>> attr : nameValues.entrySet())
1012 String values = StringUtils.listToDelimitedString(attr.getValue(),
1014 sf.setValue(attr.getKey(), values);
1015 if (NOTE.equals(attr.getKey()))
1017 sf.setDescription(values);
1023 * After encountering ##fasta in a GFF3 file, process the remainder of the
1024 * file as FAST sequence data. Any placeholder sequences created during
1025 * feature parsing are updated with the actual sequences.
1029 * @throws IOException
1031 protected void processAsFasta(AlignmentI align, List<SequenceI> newseqs)
1037 } catch (IOException q)
1040 FastaFile parser = new FastaFile(this);
1041 List<SequenceI> includedseqs = parser.getSeqs();
1043 SequenceIdMatcher smatcher = new SequenceIdMatcher(newseqs);
1046 * iterate over includedseqs, and replacing matching ones with newseqs
1047 * sequences. Generic iterator not used here because we modify
1048 * includedseqs as we go
1050 for (int p = 0, pSize = includedseqs.size(); p < pSize; p++)
1052 // search for any dummy seqs that this sequence can be used to update
1053 SequenceI includedSeq = includedseqs.get(p);
1054 SequenceI dummyseq = smatcher.findIdMatch(includedSeq);
1055 if (dummyseq != null && dummyseq instanceof SequenceDummy)
1057 // probably have the pattern wrong
1058 // idea is that a flyweight proxy for a sequence ID can be created for
1059 // 1. stable reference creation
1060 // 2. addition of annotation
1061 // 3. future replacement by a real sequence
1062 // current pattern is to create SequenceDummy objects - a convenience
1063 // constructor for a Sequence.
1064 // problem is that when promoted to a real sequence, all references
1065 // need to be updated somehow. We avoid that by keeping the same object.
1066 ((SequenceDummy) dummyseq).become(includedSeq);
1067 dummyseq.createDatasetSequence();
1070 * Update mappings so they are now to the dataset sequence
1072 for (AlignedCodonFrame mapping : align.getCodonFrames())
1074 mapping.updateToDataset(dummyseq);
1078 * replace parsed sequence with the realised forward reference
1080 includedseqs.set(p, dummyseq);
1083 * and remove from the newseqs list
1085 newseqs.remove(dummyseq);
1090 * finally add sequences to the dataset
1092 for (SequenceI seq : includedseqs)
1094 // experimental: mapping-based 'alignment' to query sequence
1095 AlignmentUtils.alignSequenceAs(seq, align,
1096 String.valueOf(align.getGapCharacter()), false, true);
1098 // rename sequences if GFF handler requested this
1099 // TODO a more elegant way e.g. gffHelper.postProcess(newseqs) ?
1100 SequenceFeature[] sfs = seq.getSequenceFeatures();
1103 String newName = (String) sfs[0].getValue(GffHelperI.RENAME_TOKEN);
1104 if (newName != null)
1106 seq.setName(newName);
1109 align.addSequence(seq);
1114 * Process a ## directive
1120 * @throws IOException
1122 protected void processGffPragma(String line,
1123 Map<String, String> gffProps, AlignmentI align,
1124 List<SequenceI> newseqs) throws IOException
1127 if ("###".equals(line))
1129 // close off any open 'forward references'
1133 String[] tokens = line.substring(2).split(" ");
1134 String pragma = tokens[0];
1135 String value = tokens.length == 1 ? null : tokens[1];
1137 if ("gff-version".equalsIgnoreCase(pragma))
1143 // value may be e.g. "3.1.2"
1144 gffVersion = Integer.parseInt(value.split("\\.")[0]);
1145 } catch (NumberFormatException e)
1151 else if ("sequence-region".equalsIgnoreCase(pragma))
1153 // could capture <seqid start end> if wanted here
1155 else if ("feature-ontology".equalsIgnoreCase(pragma))
1157 // should resolve against the specified feature ontology URI
1159 else if ("attribute-ontology".equalsIgnoreCase(pragma))
1161 // URI of attribute ontology - not currently used in GFF3
1163 else if ("source-ontology".equalsIgnoreCase(pragma))
1165 // URI of source ontology - not currently used in GFF3
1167 else if ("species-build".equalsIgnoreCase(pragma))
1169 // save URI of specific NCBI taxon version of annotations
1170 gffProps.put("species-build", value);
1172 else if ("fasta".equalsIgnoreCase(pragma))
1174 // process the rest of the file as a fasta file and replace any dummy
1176 processAsFasta(align, newseqs);
1180 System.err.println("Ignoring unknown pragma: " + line);