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.List;
52 import java.util.Map.Entry;
55 * Parses and writes features files, which may be in Jalview, GFF2 or GFF3
56 * format. These are tab-delimited formats but with differences in the use of
59 * A Jalview feature file may define feature colours and then declare that the
60 * remainder of the file is in GFF format with the line 'GFF'.
62 * GFF3 files may include alignment mappings for features, which Jalview will
63 * attempt to model, and may include sequence data following a ##FASTA line.
70 public class FeaturesFile extends AlignFile implements FeaturesSourceI
72 private static final String ID_NOT_SPECIFIED = "ID_NOT_SPECIFIED";
74 private static final String NOTE = "Note";
76 protected static final String TAB = "\t";
78 protected static final String GFF_VERSION = "##gff-version";
80 private static final Comparator<String> SORT_NULL_LAST = new Comparator<String>()
83 public int compare(String o1, String o2)
87 return o2 == null ? 0 : 1;
89 return (o2 == null ? -1 : o1.compareTo(o2));
93 private AlignmentI lastmatchedAl = null;
95 private SequenceIdMatcher matcher = null;
97 protected AlignmentI dataset;
99 protected int gffVersion;
102 * Creates a new FeaturesFile object.
104 public FeaturesFile()
109 * Constructor which does not parse the file immediately
113 * @throws IOException
115 public FeaturesFile(String inFile, DataSourceType paste)
118 super(false, inFile, paste);
123 * @throws IOException
125 public FeaturesFile(FileParse source) throws IOException
131 * Constructor that optionally parses the file immediately
133 * @param parseImmediately
136 * @throws IOException
138 public FeaturesFile(boolean parseImmediately, String inFile,
142 super(parseImmediately, inFile, type);
146 * Parse GFF or sequence features file using case-independent matching,
150 * - alignment/dataset containing sequences that are to be annotated
152 * - hashtable to store feature colour definitions
154 * - process html strings into plain text
155 * @return true if features were added
157 public boolean parse(AlignmentI align,
158 Map<String, FeatureColourI> colours, boolean removeHTML)
160 return parse(align, colours, removeHTML, false);
164 * Extends the default addProperties by also adding peptide-to-cDNA mappings
165 * (if any) derived while parsing a GFF file
168 public void addProperties(AlignmentI al)
170 super.addProperties(al);
171 if (dataset != null && dataset.getCodonFrames() != null)
173 AlignmentI ds = (al.getDataset() == null) ? al : al.getDataset();
174 for (AlignedCodonFrame codons : dataset.getCodonFrames())
176 ds.addCodonFrame(codons);
182 * Parse GFF or Jalview format sequence features file
185 * - alignment/dataset containing sequences that are to be annotated
187 * - hashtable to store feature colour definitions
189 * - process html strings into plain text
190 * @param relaxedIdmatching
191 * - when true, ID matches to compound sequence IDs are allowed
192 * @return true if features were added
194 public boolean parse(AlignmentI align,
195 Map<String, FeatureColourI> colours, boolean removeHTML,
196 boolean relaxedIdmatching)
198 Map<String, String> gffProps = new HashMap<String, String>();
200 * keep track of any sequences we try to create from the data
202 List<SequenceI> newseqs = new ArrayList<SequenceI>();
208 String featureGroup = null;
210 while ((line = nextLine()) != null)
212 // skip comments/process pragmas
213 if (line.length() == 0 || line.startsWith("#"))
215 if (line.toLowerCase().startsWith("##"))
217 processGffPragma(line, gffProps, align, newseqs);
222 gffColumns = line.split("\\t"); // tab as regex
223 if (gffColumns.length == 1)
225 if (line.trim().equalsIgnoreCase("GFF"))
228 * Jalview features file with appended GFF
229 * assume GFF2 (though it may declare ##gff-version 3)
236 if (gffColumns.length > 1 && gffColumns.length < 4)
239 * if 2 or 3 tokens, we anticipate either 'startgroup', 'endgroup' or
240 * a feature type colour specification
242 String ft = gffColumns[0];
243 if (ft.equalsIgnoreCase("startgroup"))
245 featureGroup = gffColumns[1];
247 else if (ft.equalsIgnoreCase("endgroup"))
249 // We should check whether this is the current group,
250 // but at present there's no way of showing more than 1 group
255 String colscheme = gffColumns[1];
256 FeatureColourI colour = FeatureColour
257 .parseJalviewFeatureColour(colscheme);
260 colours.put(ft, colour);
267 * if not a comment, GFF pragma, startgroup, endgroup or feature
268 * colour specification, that just leaves a feature details line
269 * in either Jalview or GFF format
273 parseJalviewFeature(line, gffColumns, align, colours, removeHTML,
274 relaxedIdmatching, featureGroup);
278 parseGff(gffColumns, align, relaxedIdmatching, newseqs);
282 } catch (Exception ex)
284 // should report somewhere useful for UI if necessary
285 warningMessage = ((warningMessage == null) ? "" : warningMessage)
286 + "Parsing error at\n" + line;
287 System.out.println("Error parsing feature file: " + ex + "\n" + line);
288 ex.printStackTrace(System.err);
294 * experimental - add any dummy sequences with features to the alignment
295 * - we need them for Ensembl feature extraction - though maybe not otherwise
297 for (SequenceI newseq : newseqs)
299 if (newseq.getFeatures().hasFeatures())
301 align.addSequence(newseq);
308 * Try to parse a Jalview format feature specification and add it as a
309 * sequence feature to any matching sequences in the alignment. Returns true
310 * if successful (a feature was added), or false if not.
315 * @param featureColours
317 * @param relaxedIdmatching
318 * @param featureGroup
320 protected boolean parseJalviewFeature(String line, String[] gffColumns,
321 AlignmentI alignment, Map<String, FeatureColourI> featureColours,
322 boolean removeHTML, boolean relaxedIdMatching, String featureGroup)
325 * tokens: description seqid seqIndex start end type [score]
327 if (gffColumns.length < 6)
329 System.err.println("Ignoring feature line '" + line
330 + "' with too few columns (" + gffColumns.length + ")");
333 String desc = gffColumns[0];
334 String seqId = gffColumns[1];
335 SequenceI seq = findSequence(seqId, alignment, null, relaxedIdMatching);
337 if (!ID_NOT_SPECIFIED.equals(seqId))
339 seq = findSequence(seqId, alignment, null, relaxedIdMatching);
345 String seqIndex = gffColumns[2];
348 int idx = Integer.parseInt(seqIndex);
349 seq = alignment.getSequenceAt(idx);
350 } catch (NumberFormatException ex)
352 System.err.println("Invalid sequence index: " + seqIndex);
358 System.out.println("Sequence not found: " + line);
362 int startPos = Integer.parseInt(gffColumns[3]);
363 int endPos = Integer.parseInt(gffColumns[4]);
365 String ft = gffColumns[5];
367 if (!featureColours.containsKey(ft))
370 * Perhaps an old style groups file with no colours -
371 * synthesize a colour from the feature type
373 Color colour = ColorUtils.createColourFromName(ft);
374 featureColours.put(ft, new FeatureColour(colour));
376 SequenceFeature sf = null;
377 if (gffColumns.length > 6)
379 float score = Float.NaN;
382 score = new Float(gffColumns[6]).floatValue();
383 } catch (NumberFormatException ex)
385 sf = new SequenceFeature(ft, desc, startPos, endPos, featureGroup);
387 sf = new SequenceFeature(ft, desc, startPos, endPos, score,
392 sf = new SequenceFeature(ft, desc, startPos, endPos, featureGroup);
395 parseDescriptionHTML(sf, removeHTML);
397 seq.addSequenceFeature(sf);
400 && (seq = alignment.findName(seq, seqId, false)) != null)
402 seq.addSequenceFeature(new SequenceFeature(sf));
408 * clear any temporary handles used to speed up ID matching
410 protected void resetMatcher()
412 lastmatchedAl = null;
417 * Returns a sequence matching the given id, as follows
419 * <li>strict matching is on exact sequence name</li>
420 * <li>relaxed matching allows matching on a token within the sequence name,
422 * <li>first tries to find a match in the alignment sequences</li>
423 * <li>else tries to find a match in the new sequences already generated while
424 * parsing the features file</li>
425 * <li>else creates a new placeholder sequence, adds it to the new sequences
426 * list, and returns it</li>
432 * @param relaxedIdMatching
436 protected SequenceI findSequence(String seqId, AlignmentI align,
437 List<SequenceI> newseqs, boolean relaxedIdMatching)
439 // TODO encapsulate in SequenceIdMatcher, share the matcher
440 // with the GffHelper (removing code duplication)
441 SequenceI match = null;
442 if (relaxedIdMatching)
444 if (lastmatchedAl != align)
446 lastmatchedAl = align;
447 matcher = new SequenceIdMatcher(align.getSequencesArray());
450 matcher.addAll(newseqs);
453 match = matcher.findIdMatch(seqId);
457 match = align.findName(seqId, true);
458 if (match == null && newseqs != null)
460 for (SequenceI m : newseqs)
462 if (seqId.equals(m.getName()))
470 if (match == null && newseqs != null)
472 match = new SequenceDummy(seqId);
473 if (relaxedIdMatching)
475 matcher.addAll(Arrays.asList(new SequenceI[] { match }));
477 // add dummy sequence to the newseqs list
483 public void parseDescriptionHTML(SequenceFeature sf, boolean removeHTML)
485 if (sf.getDescription() == null)
489 ParseHtmlBodyAndLinks parsed = new ParseHtmlBodyAndLinks(
490 sf.getDescription(), removeHTML, newline);
494 sf.setDescription(parsed.getNonHtmlContent());
497 for (String link : parsed.getLinks())
504 * Returns contents of a Jalview format features file, for visible features,
505 * as filtered by type and group. Features with a null group are displayed if
506 * their feature type is visible. Non-positional features may optionally be
507 * included (with no check on type or group).
512 * map of colour for each visible feature type
513 * @param visibleFeatureGroups
514 * @param includeNonPositional
515 * if true, include non-positional features (regardless of group or
519 public String printJalviewFormat(SequenceI[] sequences,
520 Map<String, FeatureColourI> visible,
521 List<String> visibleFeatureGroups, boolean includeNonPositional)
523 if (!includeNonPositional && (visible == null || visible.isEmpty()))
525 // no point continuing.
526 return "No Features Visible";
530 * write out feature colours (if we know them)
532 // TODO: decide if feature links should also be written here ?
533 StringBuilder out = new StringBuilder(256);
536 for (Entry<String, FeatureColourI> featureColour : visible.entrySet())
538 FeatureColourI colour = featureColour.getValue();
539 out.append(colour.toJalviewFormat(featureColour.getKey())).append(
544 String[] types = visible == null ? new String[0] : visible.keySet()
545 .toArray(new String[visible.keySet().size()]);
548 * sort groups alphabetically, and ensure that features with a
549 * null or empty group are output after those in named groups
551 List<String> sortedGroups = new ArrayList<String>(visibleFeatureGroups);
552 sortedGroups.remove(null);
553 sortedGroups.remove("");
554 Collections.sort(sortedGroups);
555 sortedGroups.add(null);
556 sortedGroups.add("");
558 boolean foundSome = false;
561 * first output any non-positional features
563 if (includeNonPositional)
565 for (int i = 0; i < sequences.length; i++)
567 String sequenceName = sequences[i].getName();
568 for (SequenceFeature feature : sequences[i].getFeatures()
569 .getNonPositionalFeatures())
572 out.append(formatJalviewFeature(sequenceName, feature));
577 for (String group : sortedGroups)
579 boolean isNamedGroup = (group != null && !"".equals(group));
583 out.append("STARTGROUP").append(TAB);
589 * output positional features within groups
591 for (int i = 0; i < sequences.length; i++)
593 String sequenceName = sequences[i].getName();
594 List<SequenceFeature> features = new ArrayList<SequenceFeature>();
595 if (types.length > 0)
597 features.addAll(sequences[i].getFeatures().getFeaturesForGroup(
598 true, group, types));
601 for (SequenceFeature sequenceFeature : features)
604 out.append(formatJalviewFeature(sequenceName, sequenceFeature));
610 out.append("ENDGROUP").append(TAB);
616 return foundSome ? out.toString() : "No Features Visible";
621 * @param sequenceName
622 * @param sequenceFeature
624 protected String formatJalviewFeature(
625 String sequenceName, SequenceFeature sequenceFeature)
627 StringBuilder out = new StringBuilder(64);
628 if (sequenceFeature.description == null
629 || sequenceFeature.description.equals(""))
631 out.append(sequenceFeature.type).append(TAB);
635 if (sequenceFeature.links != null
636 && sequenceFeature.getDescription().indexOf("<html>") == -1)
638 out.append("<html>");
641 out.append(sequenceFeature.description);
642 if (sequenceFeature.links != null)
644 for (int l = 0; l < sequenceFeature.links.size(); l++)
646 String label = sequenceFeature.links.elementAt(l);
647 String href = label.substring(label.indexOf("|") + 1);
648 label = label.substring(0, label.indexOf("|"));
650 if (sequenceFeature.description.indexOf(href) == -1)
652 out.append(" <a href=\"" + href + "\">" + label + "</a>");
656 if (sequenceFeature.getDescription().indexOf("</html>") == -1)
658 out.append("</html>");
664 out.append(sequenceName);
665 out.append("\t-1\t");
666 out.append(sequenceFeature.begin);
668 out.append(sequenceFeature.end);
670 out.append(sequenceFeature.type);
671 if (!Float.isNaN(sequenceFeature.score))
674 out.append(sequenceFeature.score);
678 return out.toString();
682 * Parse method that is called when a GFF file is dragged to the desktop
687 AlignViewportI av = getViewport();
690 if (av.getAlignment() != null)
692 dataset = av.getAlignment().getDataset();
696 // working in the applet context ?
697 dataset = av.getAlignment();
702 dataset = new Alignment(new SequenceI[] {});
705 Map<String, FeatureColourI> featureColours = new HashMap<String, FeatureColourI>();
706 boolean parseResult = parse(dataset, featureColours, false, true);
709 // pass error up somehow
713 // update viewport with the dataset data ?
717 setSeqs(dataset.getSequencesArray());
722 * Implementation of unused abstract method
724 * @return error message
727 public String print(SequenceI[] sqs, boolean jvsuffix)
729 System.out.println("Use printGffFormat() or printJalviewFormat()");
734 * Returns features output in GFF2 format
737 * the sequences whose features are to be output
739 * a map whose keys are the type names of visible features
740 * @param visibleFeatureGroups
741 * @param includeNonPositionalFeatures
744 public String printGffFormat(SequenceI[] sequences,
745 Map<String, FeatureColourI> visible,
746 List<String> visibleFeatureGroups,
747 boolean includeNonPositionalFeatures)
749 StringBuilder out = new StringBuilder(256);
751 out.append(String.format("%s %d\n", GFF_VERSION, gffVersion == 0 ? 2 : gffVersion));
753 if (!includeNonPositionalFeatures
754 && (visible == null || visible.isEmpty()))
756 return out.toString();
759 String[] types = visible == null ? new String[0] : visible.keySet()
761 new String[visible.keySet().size()]);
763 for (SequenceI seq : sequences)
765 List<SequenceFeature> features = new ArrayList<SequenceFeature>();
766 if (includeNonPositionalFeatures)
768 features.addAll(seq.getFeatures().getNonPositionalFeatures());
770 if (visible != null && !visible.isEmpty())
772 features.addAll(seq.getFeatures().getPositionalFeatures(types));
775 for (SequenceFeature sf : features)
777 String source = sf.featureGroup;
778 if (!sf.isNonPositional() && source != null
779 && !visibleFeatureGroups.contains(source))
781 // group is not visible
787 source = sf.getDescription();
790 out.append(seq.getName());
796 out.append(sf.begin);
800 out.append(sf.score);
803 int strand = sf.getStrand();
804 out.append(strand == 1 ? "+" : (strand == -1 ? "-" : "."));
807 String phase = sf.getPhase();
808 out.append(phase == null ? "." : phase);
810 // miscellaneous key-values (GFF column 9)
811 String attributes = sf.getAttributes();
812 if (attributes != null)
814 out.append(TAB).append(attributes);
821 return out.toString();
825 * Returns a mapping given list of one or more Align descriptors (exonerate
828 * @param alignedRegions
829 * a list of "Align fromStart toStart fromCount"
830 * @param mapIsFromCdna
831 * if true, 'from' is dna, else 'from' is protein
833 * either 1 (forward) or -1 (reverse)
835 * @throws IOException
837 protected MapList constructCodonMappingFromAlign(
838 List<String> alignedRegions, boolean mapIsFromCdna, int strand)
843 throw new IOException(
844 "Invalid strand for a codon mapping (cannot be 0)");
846 int regions = alignedRegions.size();
847 // arrays to hold [start, end] for each aligned region
848 int[] fromRanges = new int[regions * 2]; // from dna
849 int[] toRanges = new int[regions * 2]; // to protein
850 int fromRangesIndex = 0;
851 int toRangesIndex = 0;
853 for (String range : alignedRegions)
856 * Align mapFromStart mapToStart mapFromCount
857 * e.g. if mapIsFromCdna
858 * Align 11270 143 120
860 * 120 bases from pos 11270 align to pos 143 in peptide
861 * if !mapIsFromCdna this would instead be
864 String[] tokens = range.split(" ");
865 if (tokens.length != 3)
867 throw new IOException("Wrong number of fields for Align");
874 fromStart = Integer.parseInt(tokens[0]);
875 toStart = Integer.parseInt(tokens[1]);
876 fromCount = Integer.parseInt(tokens[2]);
877 } catch (NumberFormatException nfe)
879 throw new IOException("Invalid number in Align field: "
884 * Jalview always models from dna to protein, so adjust values if the
885 * GFF mapping is from protein to dna
890 int temp = fromStart;
894 fromRanges[fromRangesIndex++] = fromStart;
895 fromRanges[fromRangesIndex++] = fromStart + strand * (fromCount - 1);
898 * If a codon has an intron gap, there will be contiguous 'toRanges';
899 * this is handled for us by the MapList constructor.
900 * (It is not clear that exonerate ever generates this case)
902 toRanges[toRangesIndex++] = toStart;
903 toRanges[toRangesIndex++] = toStart + (fromCount - 1) / 3;
906 return new MapList(fromRanges, toRanges, 3, 1);
910 * Parse a GFF format feature. This may include creating a 'dummy' sequence to
911 * hold the feature, or for its mapped sequence, or both, to be resolved
912 * either later in the GFF file (##FASTA section), or when the user loads
913 * additional sequences.
917 * @param relaxedIdMatching
921 protected SequenceI parseGff(String[] gffColumns, AlignmentI alignment,
922 boolean relaxedIdMatching, List<SequenceI> newseqs)
925 * GFF: seqid source type start end score strand phase [attributes]
927 if (gffColumns.length < 5)
929 System.err.println("Ignoring GFF feature line with too few columns ("
930 + gffColumns.length + ")");
935 * locate referenced sequence in alignment _or_
936 * as a forward or external reference (SequenceDummy)
938 String seqId = gffColumns[0];
939 SequenceI seq = findSequence(seqId, alignment, newseqs,
942 SequenceFeature sf = null;
943 GffHelperI helper = GffHelperFactory.getHelper(gffColumns);
948 sf = helper.processGff(seq, gffColumns, alignment, newseqs,
952 seq.addSequenceFeature(sf);
953 while ((seq = alignment.findName(seq, seqId, true)) != null)
955 seq.addSequenceFeature(new SequenceFeature(sf));
958 } catch (IOException e)
960 System.err.println("GFF parsing failed with: " + e.getMessage());
969 * Process the 'column 9' data of the GFF file. This is less formally defined,
970 * and its interpretation will vary depending on the tool that has generated
976 protected void processGffColumnNine(String attributes, SequenceFeature sf)
978 sf.setAttributes(attributes);
981 * Parse attributes in column 9 and add them to the sequence feature's
982 * 'otherData' table; use Note as a best proxy for description
984 char nameValueSeparator = gffVersion == 3 ? '=' : ' ';
985 // TODO check we don't break GFF2 values which include commas here
986 Map<String, List<String>> nameValues = GffHelperBase
987 .parseNameValuePairs(attributes, ";", nameValueSeparator, ",");
988 for (Entry<String, List<String>> attr : nameValues.entrySet())
990 String values = StringUtils.listToDelimitedString(attr.getValue(),
992 sf.setValue(attr.getKey(), values);
993 if (NOTE.equals(attr.getKey()))
995 sf.setDescription(values);
1001 * After encountering ##fasta in a GFF3 file, process the remainder of the
1002 * file as FAST sequence data. Any placeholder sequences created during
1003 * feature parsing are updated with the actual sequences.
1007 * @throws IOException
1009 protected void processAsFasta(AlignmentI align, List<SequenceI> newseqs)
1015 } catch (IOException q)
1018 FastaFile parser = new FastaFile(this);
1019 List<SequenceI> includedseqs = parser.getSeqs();
1021 SequenceIdMatcher smatcher = new SequenceIdMatcher(newseqs);
1024 * iterate over includedseqs, and replacing matching ones with newseqs
1025 * sequences. Generic iterator not used here because we modify
1026 * includedseqs as we go
1028 for (int p = 0, pSize = includedseqs.size(); p < pSize; p++)
1030 // search for any dummy seqs that this sequence can be used to update
1031 SequenceI includedSeq = includedseqs.get(p);
1032 SequenceI dummyseq = smatcher.findIdMatch(includedSeq);
1033 if (dummyseq != null && dummyseq instanceof SequenceDummy)
1035 // probably have the pattern wrong
1036 // idea is that a flyweight proxy for a sequence ID can be created for
1037 // 1. stable reference creation
1038 // 2. addition of annotation
1039 // 3. future replacement by a real sequence
1040 // current pattern is to create SequenceDummy objects - a convenience
1041 // constructor for a Sequence.
1042 // problem is that when promoted to a real sequence, all references
1043 // need to be updated somehow. We avoid that by keeping the same object.
1044 ((SequenceDummy) dummyseq).become(includedSeq);
1045 dummyseq.createDatasetSequence();
1048 * Update mappings so they are now to the dataset sequence
1050 for (AlignedCodonFrame mapping : align.getCodonFrames())
1052 mapping.updateToDataset(dummyseq);
1056 * replace parsed sequence with the realised forward reference
1058 includedseqs.set(p, dummyseq);
1061 * and remove from the newseqs list
1063 newseqs.remove(dummyseq);
1068 * finally add sequences to the dataset
1070 for (SequenceI seq : includedseqs)
1072 // experimental: mapping-based 'alignment' to query sequence
1073 AlignmentUtils.alignSequenceAs(seq, align,
1074 String.valueOf(align.getGapCharacter()), false, true);
1076 // rename sequences if GFF handler requested this
1077 // TODO a more elegant way e.g. gffHelper.postProcess(newseqs) ?
1078 List<SequenceFeature> sfs = seq.getFeatures().getPositionalFeatures();
1081 String newName = (String) sfs.get(0).getValue(
1082 GffHelperI.RENAME_TOKEN);
1083 if (newName != null)
1085 seq.setName(newName);
1088 align.addSequence(seq);
1093 * Process a ## directive
1099 * @throws IOException
1101 protected void processGffPragma(String line,
1102 Map<String, String> gffProps, AlignmentI align,
1103 List<SequenceI> newseqs) throws IOException
1106 if ("###".equals(line))
1108 // close off any open 'forward references'
1112 String[] tokens = line.substring(2).split(" ");
1113 String pragma = tokens[0];
1114 String value = tokens.length == 1 ? null : tokens[1];
1116 if ("gff-version".equalsIgnoreCase(pragma))
1122 // value may be e.g. "3.1.2"
1123 gffVersion = Integer.parseInt(value.split("\\.")[0]);
1124 } catch (NumberFormatException e)
1130 else if ("sequence-region".equalsIgnoreCase(pragma))
1132 // could capture <seqid start end> if wanted here
1134 else if ("feature-ontology".equalsIgnoreCase(pragma))
1136 // should resolve against the specified feature ontology URI
1138 else if ("attribute-ontology".equalsIgnoreCase(pragma))
1140 // URI of attribute ontology - not currently used in GFF3
1142 else if ("source-ontology".equalsIgnoreCase(pragma))
1144 // URI of source ontology - not currently used in GFF3
1146 else if ("species-build".equalsIgnoreCase(pragma))
1148 // save URI of specific NCBI taxon version of annotations
1149 gffProps.put("species-build", value);
1151 else if ("fasta".equalsIgnoreCase(pragma))
1153 // process the rest of the file as a fasta file and replace any dummy
1155 processAsFasta(align, newseqs);
1159 System.err.println("Ignoring unknown pragma: " + line);