X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FGenBankFile.java;h=fbabab1cb13f86af8ca5a1a005f6560b3654e663;hb=faf491e024f9835435f5dd6c20a033250dd9297d;hp=798876453bdc183775e35ce89d4a73269bd6e112;hpb=da62703518a88707b9144bc51e50d6af7093a7c7;p=jalview.git diff --git a/src/jalview/io/GenBankFile.java b/src/jalview/io/GenBankFile.java index 7988764..fbabab1 100644 --- a/src/jalview/io/GenBankFile.java +++ b/src/jalview/io/GenBankFile.java @@ -1,9 +1,27 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.io; import java.io.IOException; -import jalview.bin.Cache; - /** * A class that provides selective parsing of the GenBank flatfile format. *

@@ -18,7 +36,7 @@ import jalview.bin.Cache; * @author gmcarstairs * @see https://www.ncbi.nlm.nih.gov/Sitemap/samplerecord.html */ -public class GenBankFile extends FlatFile +public class GenBankFile extends EMBLLikeFlatFile { private static final String DEFINITION = "DEFINITION"; @@ -47,7 +65,11 @@ public class GenBankFile extends FlatFile String line = nextLine(); while (line != null) { - if (line.startsWith(DEFINITION)) + if (line.startsWith("LOCUS")) + { + line = parseLocus(line); + } + else if (line.startsWith(DEFINITION)) { line = parseDefinition(line); } @@ -89,45 +111,25 @@ public class GenBankFile extends FlatFile */ String parseLocus(String line) throws IOException { - String[] tokens = line.substring(2).split(";"); + String[] tokens = line.split(WHITESPACE); /* - * first is primary accession + * first should be "LOCUS" */ - String token = tokens[0].trim(); - if (!token.isEmpty()) + if (tokens.length < 2 || !"LOCUS".equals(tokens[0])) { - this.accession = token; + return nextLine(); } - /* - * second token is 'SV versionNo' + * second is primary accession */ - if (tokens.length > 1) + String token = tokens[1].trim(); + if (!token.isEmpty()) { - token = tokens[1].trim(); - if (token.startsWith("SV")) - { - String[] bits = token.trim().split(WHITESPACE); - this.version = bits[bits.length - 1]; - } + this.accession = token; } - /* - * seventh token is 'length BP' - */ - if (tokens.length > 6) - { - token = tokens[6].trim(); - String[] bits = token.trim().split(WHITESPACE); - try - { - this.length = Integer.valueOf(bits[0]); - } catch (NumberFormatException e) - { - Cache.log.error("bad length read in flatfile, line: " + line); - } - } + // not going to guess the rest just yet, but third is length with unit (bp) return nextLine(); }