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 = new SequenceFeature(ft, desc, "", startPos,
377 endPos, featureGroup);
378 if (gffColumns.length > 6)
380 float score = Float.NaN;
383 score = new Float(gffColumns[6]).floatValue();
384 // update colourgradient bounds if allowed to
385 } catch (NumberFormatException ex)
392 parseDescriptionHTML(sf, removeHTML);
394 seq.addSequenceFeature(sf);
397 && (seq = alignment.findName(seq, seqId, false)) != null)
399 seq.addSequenceFeature(new SequenceFeature(sf));
405 * clear any temporary handles used to speed up ID matching
407 protected void resetMatcher()
409 lastmatchedAl = null;
414 * Returns a sequence matching the given id, as follows
416 * <li>strict matching is on exact sequence name</li>
417 * <li>relaxed matching allows matching on a token within the sequence name,
419 * <li>first tries to find a match in the alignment sequences</li>
420 * <li>else tries to find a match in the new sequences already generated while
421 * parsing the features file</li>
422 * <li>else creates a new placeholder sequence, adds it to the new sequences
423 * list, and returns it</li>
429 * @param relaxedIdMatching
433 protected SequenceI findSequence(String seqId, AlignmentI align,
434 List<SequenceI> newseqs, boolean relaxedIdMatching)
436 // TODO encapsulate in SequenceIdMatcher, share the matcher
437 // with the GffHelper (removing code duplication)
438 SequenceI match = null;
439 if (relaxedIdMatching)
441 if (lastmatchedAl != align)
443 lastmatchedAl = align;
444 matcher = new SequenceIdMatcher(align.getSequencesArray());
447 matcher.addAll(newseqs);
450 match = matcher.findIdMatch(seqId);
454 match = align.findName(seqId, true);
455 if (match == null && newseqs != null)
457 for (SequenceI m : newseqs)
459 if (seqId.equals(m.getName()))
467 if (match == null && newseqs != null)
469 match = new SequenceDummy(seqId);
470 if (relaxedIdMatching)
472 matcher.addAll(Arrays.asList(new SequenceI[] { match }));
474 // add dummy sequence to the newseqs list
480 public void parseDescriptionHTML(SequenceFeature sf, boolean removeHTML)
482 if (sf.getDescription() == null)
486 ParseHtmlBodyAndLinks parsed = new ParseHtmlBodyAndLinks(
487 sf.getDescription(), removeHTML, newline);
491 sf.setDescription(parsed.getNonHtmlContent());
494 for (String link : parsed.getLinks())
501 * Returns contents of a Jalview format features file, for visible features,
502 * as filtered by type and group. Features with a null group are displayed if
503 * their feature type is visible. Non-positional features may optionally be
504 * included (with no check on type or group).
509 * map of colour for each visible feature type
510 * @param visibleFeatureGroups
511 * @param includeNonPositional
512 * if true, include non-positional features (regardless of group or
516 public String printJalviewFormat(SequenceI[] sequences,
517 Map<String, FeatureColourI> visible,
518 List<String> visibleFeatureGroups, boolean includeNonPositional)
520 if (!includeNonPositional && (visible == null || visible.isEmpty()))
522 // no point continuing.
523 return "No Features Visible";
527 * write out feature colours (if we know them)
529 // TODO: decide if feature links should also be written here ?
530 StringBuilder out = new StringBuilder(256);
533 for (Entry<String, FeatureColourI> featureColour : visible.entrySet())
535 FeatureColourI colour = featureColour.getValue();
536 out.append(colour.toJalviewFormat(featureColour.getKey())).append(
541 String[] types = visible == null ? new String[0] : visible.keySet()
542 .toArray(new String[visible.keySet().size()]);
545 * sort groups alphabetically, and ensure that features with a
546 * null or empty group are output after those in named groups
548 List<String> sortedGroups = new ArrayList<String>(visibleFeatureGroups);
549 sortedGroups.remove(null);
550 sortedGroups.remove("");
551 Collections.sort(sortedGroups);
552 sortedGroups.add(null);
553 sortedGroups.add("");
555 boolean foundSome = false;
558 * first output any non-positional features
560 if (includeNonPositional)
562 for (int i = 0; i < sequences.length; i++)
564 String sequenceName = sequences[i].getName();
565 for (SequenceFeature feature : sequences[i].getFeatures()
566 .getNonPositionalFeatures())
569 out.append(formatJalviewFeature(sequenceName, feature));
574 for (String group : sortedGroups)
576 boolean isNamedGroup = (group != null && !"".equals(group));
580 out.append("STARTGROUP").append(TAB);
586 * output positional features within groups
588 for (int i = 0; i < sequences.length; i++)
590 String sequenceName = sequences[i].getName();
591 List<SequenceFeature> features = new ArrayList<SequenceFeature>();
592 if (types.length > 0)
594 features.addAll(sequences[i].getFeatures().getFeaturesForGroup(
595 true, group, types));
598 for (SequenceFeature sequenceFeature : features)
601 out.append(formatJalviewFeature(sequenceName, sequenceFeature));
607 out.append("ENDGROUP").append(TAB);
613 return foundSome ? out.toString() : "No Features Visible";
618 * @param sequenceName
619 * @param sequenceFeature
621 protected String formatJalviewFeature(
622 String sequenceName, SequenceFeature sequenceFeature)
624 StringBuilder out = new StringBuilder(64);
625 if (sequenceFeature.description == null
626 || sequenceFeature.description.equals(""))
628 out.append(sequenceFeature.type).append(TAB);
632 if (sequenceFeature.links != null
633 && sequenceFeature.getDescription().indexOf("<html>") == -1)
635 out.append("<html>");
638 out.append(sequenceFeature.description);
639 if (sequenceFeature.links != null)
641 for (int l = 0; l < sequenceFeature.links.size(); l++)
643 String label = sequenceFeature.links.elementAt(l);
644 String href = label.substring(label.indexOf("|") + 1);
645 label = label.substring(0, label.indexOf("|"));
647 if (sequenceFeature.description.indexOf(href) == -1)
649 out.append(" <a href=\"" + href + "\">" + label + "</a>");
653 if (sequenceFeature.getDescription().indexOf("</html>") == -1)
655 out.append("</html>");
661 out.append(sequenceName);
662 out.append("\t-1\t");
663 out.append(sequenceFeature.begin);
665 out.append(sequenceFeature.end);
667 out.append(sequenceFeature.type);
668 if (!Float.isNaN(sequenceFeature.score))
671 out.append(sequenceFeature.score);
675 return out.toString();
679 * Parse method that is called when a GFF file is dragged to the desktop
684 AlignViewportI av = getViewport();
687 if (av.getAlignment() != null)
689 dataset = av.getAlignment().getDataset();
693 // working in the applet context ?
694 dataset = av.getAlignment();
699 dataset = new Alignment(new SequenceI[] {});
702 Map<String, FeatureColourI> featureColours = new HashMap<String, FeatureColourI>();
703 boolean parseResult = parse(dataset, featureColours, false, true);
706 // pass error up somehow
710 // update viewport with the dataset data ?
714 setSeqs(dataset.getSequencesArray());
719 * Implementation of unused abstract method
721 * @return error message
724 public String print(SequenceI[] sqs, boolean jvsuffix)
726 System.out.println("Use printGffFormat() or printJalviewFormat()");
731 * Returns features output in GFF2 format
734 * the sequences whose features are to be output
736 * a map whose keys are the type names of visible features
737 * @param visibleFeatureGroups
738 * @param includeNonPositionalFeatures
741 public String printGffFormat(SequenceI[] sequences,
742 Map<String, FeatureColourI> visible,
743 List<String> visibleFeatureGroups,
744 boolean includeNonPositionalFeatures)
746 StringBuilder out = new StringBuilder(256);
748 out.append(String.format("%s %d\n", GFF_VERSION, gffVersion == 0 ? 2 : gffVersion));
750 if (!includeNonPositionalFeatures
751 && (visible == null || visible.isEmpty()))
753 return out.toString();
756 String[] types = visible == null ? new String[0] : visible.keySet()
758 new String[visible.keySet().size()]);
760 for (SequenceI seq : sequences)
762 List<SequenceFeature> features = new ArrayList<SequenceFeature>();
763 if (includeNonPositionalFeatures)
765 features.addAll(seq.getFeatures().getNonPositionalFeatures());
767 if (visible != null && !visible.isEmpty())
769 features.addAll(seq.getFeatures().getPositionalFeatures(types));
772 for (SequenceFeature sf : features)
774 String source = sf.featureGroup;
775 if (!sf.isNonPositional() && source != null
776 && !visibleFeatureGroups.contains(source))
778 // group is not visible
784 source = sf.getDescription();
787 out.append(seq.getName());
793 out.append(sf.begin);
797 out.append(sf.score);
800 int strand = sf.getStrand();
801 out.append(strand == 1 ? "+" : (strand == -1 ? "-" : "."));
804 String phase = sf.getPhase();
805 out.append(phase == null ? "." : phase);
807 // miscellaneous key-values (GFF column 9)
808 String attributes = sf.getAttributes();
809 if (attributes != null)
811 out.append(TAB).append(attributes);
818 return out.toString();
822 * Returns a mapping given list of one or more Align descriptors (exonerate
825 * @param alignedRegions
826 * a list of "Align fromStart toStart fromCount"
827 * @param mapIsFromCdna
828 * if true, 'from' is dna, else 'from' is protein
830 * either 1 (forward) or -1 (reverse)
832 * @throws IOException
834 protected MapList constructCodonMappingFromAlign(
835 List<String> alignedRegions, boolean mapIsFromCdna, int strand)
840 throw new IOException(
841 "Invalid strand for a codon mapping (cannot be 0)");
843 int regions = alignedRegions.size();
844 // arrays to hold [start, end] for each aligned region
845 int[] fromRanges = new int[regions * 2]; // from dna
846 int[] toRanges = new int[regions * 2]; // to protein
847 int fromRangesIndex = 0;
848 int toRangesIndex = 0;
850 for (String range : alignedRegions)
853 * Align mapFromStart mapToStart mapFromCount
854 * e.g. if mapIsFromCdna
855 * Align 11270 143 120
857 * 120 bases from pos 11270 align to pos 143 in peptide
858 * if !mapIsFromCdna this would instead be
861 String[] tokens = range.split(" ");
862 if (tokens.length != 3)
864 throw new IOException("Wrong number of fields for Align");
871 fromStart = Integer.parseInt(tokens[0]);
872 toStart = Integer.parseInt(tokens[1]);
873 fromCount = Integer.parseInt(tokens[2]);
874 } catch (NumberFormatException nfe)
876 throw new IOException("Invalid number in Align field: "
881 * Jalview always models from dna to protein, so adjust values if the
882 * GFF mapping is from protein to dna
887 int temp = fromStart;
891 fromRanges[fromRangesIndex++] = fromStart;
892 fromRanges[fromRangesIndex++] = fromStart + strand * (fromCount - 1);
895 * If a codon has an intron gap, there will be contiguous 'toRanges';
896 * this is handled for us by the MapList constructor.
897 * (It is not clear that exonerate ever generates this case)
899 toRanges[toRangesIndex++] = toStart;
900 toRanges[toRangesIndex++] = toStart + (fromCount - 1) / 3;
903 return new MapList(fromRanges, toRanges, 3, 1);
907 * Parse a GFF format feature. This may include creating a 'dummy' sequence to
908 * hold the feature, or for its mapped sequence, or both, to be resolved
909 * either later in the GFF file (##FASTA section), or when the user loads
910 * additional sequences.
914 * @param relaxedIdMatching
918 protected SequenceI parseGff(String[] gffColumns, AlignmentI alignment,
919 boolean relaxedIdMatching, List<SequenceI> newseqs)
922 * GFF: seqid source type start end score strand phase [attributes]
924 if (gffColumns.length < 5)
926 System.err.println("Ignoring GFF feature line with too few columns ("
927 + gffColumns.length + ")");
932 * locate referenced sequence in alignment _or_
933 * as a forward or external reference (SequenceDummy)
935 String seqId = gffColumns[0];
936 SequenceI seq = findSequence(seqId, alignment, newseqs,
939 SequenceFeature sf = null;
940 GffHelperI helper = GffHelperFactory.getHelper(gffColumns);
945 sf = helper.processGff(seq, gffColumns, alignment, newseqs,
949 seq.addSequenceFeature(sf);
950 while ((seq = alignment.findName(seq, seqId, true)) != null)
952 seq.addSequenceFeature(new SequenceFeature(sf));
955 } catch (IOException e)
957 System.err.println("GFF parsing failed with: " + e.getMessage());
966 * Process the 'column 9' data of the GFF file. This is less formally defined,
967 * and its interpretation will vary depending on the tool that has generated
973 protected void processGffColumnNine(String attributes, SequenceFeature sf)
975 sf.setAttributes(attributes);
978 * Parse attributes in column 9 and add them to the sequence feature's
979 * 'otherData' table; use Note as a best proxy for description
981 char nameValueSeparator = gffVersion == 3 ? '=' : ' ';
982 // TODO check we don't break GFF2 values which include commas here
983 Map<String, List<String>> nameValues = GffHelperBase
984 .parseNameValuePairs(attributes, ";", nameValueSeparator, ",");
985 for (Entry<String, List<String>> attr : nameValues.entrySet())
987 String values = StringUtils.listToDelimitedString(attr.getValue(),
989 sf.setValue(attr.getKey(), values);
990 if (NOTE.equals(attr.getKey()))
992 sf.setDescription(values);
998 * After encountering ##fasta in a GFF3 file, process the remainder of the
999 * file as FAST sequence data. Any placeholder sequences created during
1000 * feature parsing are updated with the actual sequences.
1004 * @throws IOException
1006 protected void processAsFasta(AlignmentI align, List<SequenceI> newseqs)
1012 } catch (IOException q)
1015 FastaFile parser = new FastaFile(this);
1016 List<SequenceI> includedseqs = parser.getSeqs();
1018 SequenceIdMatcher smatcher = new SequenceIdMatcher(newseqs);
1021 * iterate over includedseqs, and replacing matching ones with newseqs
1022 * sequences. Generic iterator not used here because we modify
1023 * includedseqs as we go
1025 for (int p = 0, pSize = includedseqs.size(); p < pSize; p++)
1027 // search for any dummy seqs that this sequence can be used to update
1028 SequenceI includedSeq = includedseqs.get(p);
1029 SequenceI dummyseq = smatcher.findIdMatch(includedSeq);
1030 if (dummyseq != null && dummyseq instanceof SequenceDummy)
1032 // probably have the pattern wrong
1033 // idea is that a flyweight proxy for a sequence ID can be created for
1034 // 1. stable reference creation
1035 // 2. addition of annotation
1036 // 3. future replacement by a real sequence
1037 // current pattern is to create SequenceDummy objects - a convenience
1038 // constructor for a Sequence.
1039 // problem is that when promoted to a real sequence, all references
1040 // need to be updated somehow. We avoid that by keeping the same object.
1041 ((SequenceDummy) dummyseq).become(includedSeq);
1042 dummyseq.createDatasetSequence();
1045 * Update mappings so they are now to the dataset sequence
1047 for (AlignedCodonFrame mapping : align.getCodonFrames())
1049 mapping.updateToDataset(dummyseq);
1053 * replace parsed sequence with the realised forward reference
1055 includedseqs.set(p, dummyseq);
1058 * and remove from the newseqs list
1060 newseqs.remove(dummyseq);
1065 * finally add sequences to the dataset
1067 for (SequenceI seq : includedseqs)
1069 // experimental: mapping-based 'alignment' to query sequence
1070 AlignmentUtils.alignSequenceAs(seq, align,
1071 String.valueOf(align.getGapCharacter()), false, true);
1073 // rename sequences if GFF handler requested this
1074 // TODO a more elegant way e.g. gffHelper.postProcess(newseqs) ?
1075 List<SequenceFeature> sfs = seq.getFeatures().getPositionalFeatures();
1078 String newName = (String) sfs.get(0).getValue(
1079 GffHelperI.RENAME_TOKEN);
1080 if (newName != null)
1082 seq.setName(newName);
1085 align.addSequence(seq);
1090 * Process a ## directive
1096 * @throws IOException
1098 protected void processGffPragma(String line,
1099 Map<String, String> gffProps, AlignmentI align,
1100 List<SequenceI> newseqs) throws IOException
1103 if ("###".equals(line))
1105 // close off any open 'forward references'
1109 String[] tokens = line.substring(2).split(" ");
1110 String pragma = tokens[0];
1111 String value = tokens.length == 1 ? null : tokens[1];
1113 if ("gff-version".equalsIgnoreCase(pragma))
1119 // value may be e.g. "3.1.2"
1120 gffVersion = Integer.parseInt(value.split("\\.")[0]);
1121 } catch (NumberFormatException e)
1127 else if ("sequence-region".equalsIgnoreCase(pragma))
1129 // could capture <seqid start end> if wanted here
1131 else if ("feature-ontology".equalsIgnoreCase(pragma))
1133 // should resolve against the specified feature ontology URI
1135 else if ("attribute-ontology".equalsIgnoreCase(pragma))
1137 // URI of attribute ontology - not currently used in GFF3
1139 else if ("source-ontology".equalsIgnoreCase(pragma))
1141 // URI of source ontology - not currently used in GFF3
1143 else if ("species-build".equalsIgnoreCase(pragma))
1145 // save URI of specific NCBI taxon version of annotations
1146 gffProps.put("species-build", value);
1148 else if ("fasta".equalsIgnoreCase(pragma))
1150 // process the rest of the file as a fasta file and replace any dummy
1152 processAsFasta(align, newseqs);
1156 System.err.println("Ignoring unknown pragma: " + line);