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.
21 package jalview.io.gff;
24 * A factory to serve instances of GFF helper classes
26 public class GffHelperFactory
30 * Returns a class to process the GFF line based on inspecting its column
31 * data. This may return a general-purpose GFF2 or GFF3 helper, or a
32 * specialisation for a flavour of GFF generated by a particular tool.
37 public static GffHelperI getHelper(String[] gff)
39 if (gff == null || gff.length < 6)
44 GffHelperI result = null;
45 if (ExonerateHelper.recognises(gff))
47 result = new ExonerateHelper();
49 else if (InterProScanHelper.recognises(gff))
51 result = new InterProScanHelper();
53 else if (looksLikeGff3(gff))
55 result = new Gff3Helper();
59 result = new Gff2Helper();
66 * Heuristic rule: if column 9 seems to have Name=Value entries, assume this
67 * is GFF3. GFF3 uses '=' as name-value separator, GFF2 uses space ' '.
72 protected static boolean looksLikeGff3(String[] gff)
76 String attributes = gff[8].trim();
77 int pos1 = attributes.indexOf(';');
78 int pos2 = attributes.indexOf('=');
79 if (pos2 != -1 && (pos1 == -1 || pos2 < pos1))
81 // there is an '=' before the first ';' (if any)
82 // not foolproof as theoretically GFF2 could be like "Name Value=123;"