| Class | Line # | Actions | |||
|---|---|---|---|---|---|
| GffHelperFactory | 26 | 18 | 11 |
| 1 | /* | |
| 2 | * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) | |
| 3 | * Copyright (C) $$Year-Rel$$ The Jalview Authors | |
| 4 | * | |
| 5 | * This file is part of Jalview. | |
| 6 | * | |
| 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. | |
| 11 | * | |
| 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. | |
| 16 | * | |
| 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. | |
| 20 | */ | |
| 21 | package jalview.io.gff; | |
| 22 | ||
| 23 | /** | |
| 24 | * A factory to serve instances of GFF helper classes | |
| 25 | */ | |
| 26 | public class GffHelperFactory | |
| 27 | { | |
| 28 | ||
| 29 | /** | |
| 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. | |
| 33 | * | |
| 34 | * @param gff | |
| 35 | * @return | |
| 36 | */ | |
| 37 | 39 | public static GffHelperI getHelper(String[] gff) |
| 38 | { | |
| 39 | 39 | if (gff == null || gff.length < 6) |
| 40 | { | |
| 41 | 1 | return null; |
| 42 | } | |
| 43 | ||
| 44 | 38 | GffHelperI result = null; |
| 45 | 38 | if (ExonerateHelper.recognises(gff)) |
| 46 | { | |
| 47 | 14 | result = new ExonerateHelper(); |
| 48 | } | |
| 49 | 24 | else if (InterProScanHelper.recognises(gff)) |
| 50 | { | |
| 51 | 1 | result = new InterProScanHelper(); |
| 52 | } | |
| 53 | 23 | else if (looksLikeGff3(gff)) |
| 54 | { | |
| 55 | 4 | result = new Gff3Helper(); |
| 56 | } | |
| 57 | else | |
| 58 | { | |
| 59 | 19 | result = new Gff2Helper(); |
| 60 | } | |
| 61 | ||
| 62 | 38 | return result; |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 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 ' '. | |
| 68 | * | |
| 69 | * @param gff | |
| 70 | * @return | |
| 71 | */ | |
| 72 | 23 | protected static boolean looksLikeGff3(String[] gff) |
| 73 | { | |
| 74 | 23 | if (gff.length >= 9) |
| 75 | { | |
| 76 | 16 | String attributes = gff[8].trim(); |
| 77 | 16 | int pos1 = attributes.indexOf(';'); |
| 78 | 16 | int pos2 = attributes.indexOf('='); |
| 79 | 16 | if (pos2 != -1 && (pos1 == -1 || pos2 < pos1)) |
| 80 | { | |
| 81 | // there is an '=' before the first ';' (if any) | |
| 82 | // not foolproof as theoretically GFF2 could be like "Name Value=123;" | |
| 83 | 4 | return true; |
| 84 | } | |
| 85 | } | |
| 86 | 19 | return false; |
| 87 | } | |
| 88 | ||
| 89 | } |