1 /* GenbankStreamFeature.java 2 * 3 * created: Mon Sep 13 1999 4 * 5 * This file is part of Artemis 6 * 7 * Copyright (C) 1999 Genome Research Limited 8 * 9 * This program is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU General Public License 11 * as published by the Free Software Foundation; either version 2 12 * of the License, or (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 * 23 * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/GenbankStreamFeature.java,v 1.1 2004-06-09 09:49:37 tjc Exp $ 24 */ 25 26 package uk.ac.sanger.artemis.io; 27 28 import uk.ac.sanger.artemis.util.LinePushBackReader; 29 30 import java.io.*; 31 32 /** 33 * A StreamFeature that thinks it is a GENBANK feature. 34 * 35 * @author Kim Rutherford 36 * @version $Id: GenbankStreamFeature.java,v 1.1 2004-06-09 09:49:37 tjc Exp $ 37 **/ 38 39 public class GenbankStreamFeature extends PublicDBStreamFeature { 40 /** 41 * Create a new GenbankStreamFeature object. 42 * @param key The new feature key 43 * @param location The Location object for the new feature 44 * @param qualifiers The qualifiers for the new feature 45 * @exception InvalidRelationException Thrown if this Feature cannot contain 46 * the given Qualifier. 47 **/ GenbankStreamFeature(Key key, Location location, QualifierVector qualifiers)48 public GenbankStreamFeature (Key key, 49 Location location, 50 QualifierVector qualifiers) 51 throws InvalidRelationException { 52 super (key, location, qualifiers); 53 } 54 55 /** 56 * Create a new GenbankStreamFeature with the same key, location and 57 * qualifiers as the given feature. The feature should be added to an 58 * Entry (with Entry.add ()). 59 * @param feature The feature to copy. 60 **/ GenbankStreamFeature(final Feature feature)61 public GenbankStreamFeature (final Feature feature) { 62 super (feature); 63 } 64 65 66 /** 67 * Create a new, blank GENBANK feature. It will have no qualifiers, a key 68 * of CDS and a location of 1. 69 **/ GenbankStreamFeature()70 public GenbankStreamFeature () { 71 super (makeBlankFeature ()); 72 } 73 74 /** 75 * Called by the constructor. 76 **/ makeBlankFeature()77 private static EmblStreamFeature makeBlankFeature () { 78 try { 79 return new EmblStreamFeature (Key.CDS, new Location ("1"), 80 new QualifierVector ()); 81 } catch (InvalidRelationException e) { 82 throw new Error ("internal error - unexpected exception: " + e); 83 } catch (LocationParseException e) { 84 throw new Error ("internal error - unexpected exception: " + e); 85 } 86 } 87 88 /** 89 * Read and return a GenbankStreamFeature from a stream. A feature must be 90 * the next thing in the stream. 91 * @param stream the Feature is read from this stream 92 * @exception IOException thrown if there is a problem reading the Feature - 93 * most likely ReadFormatException. 94 * @return null if in_stream is at the end of file when the method is called 95 * 96 **/ 97 public static GenbankStreamFeature readFromStream(final LinePushBackReader in_stream)98 readFromStream (final LinePushBackReader in_stream) 99 throws IOException { 100 return (GenbankStreamFeature) readFromStream (in_stream, 101 LineGroup.GENBANK_FEATURE); 102 } 103 104 /** 105 * Return the reference of a new copy of this Feature. 106 **/ copy()107 public Feature copy () { 108 final Feature return_value = new GenbankStreamFeature (this); 109 110 // System.out.println (return_value.getEntry ()); 111 112 return return_value; 113 } 114 } 115