Class Feature

  • All Implemented Interfaces:
    FeatureI

    public class Feature
    extends java.lang.Object
    implements FeatureI
    A Feature corresponds to a single row in a GFF file.
    Author:
    Hanno Hinsch
    • Constructor Summary

      Constructors 
      Constructor Description
      Feature​(java.lang.String seqname, java.lang.String source, java.lang.String type, Location location, java.lang.Double score, int frame, java.lang.String attributes)
      Construct a new Feature from raw data (usually a GFF row).
      Feature​(Feature feature)
      Make a copy of the specified feature.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String attributes()
      Get the string of key/value attributes.
      int frame()
      Get frame (aka phase).
      java.lang.String getAttribute​(java.lang.String key)
      Get value of specified attribute key.
      java.lang.String getAttributeOld​(java.lang.String key)  
      java.util.HashMap<java.lang.String,​java.lang.String> getAttributes()  
      java.lang.String group()
      Get the first item (everything before first semicolon, if it has one) in the attribute field, which is assumed to be a group identifer.
      boolean hasAttribute​(java.lang.String key)
      Check if the feature has a value defined for the specified key.
      boolean hasAttribute​(java.lang.String key, java.lang.String value)
      Check if the feature attributes include the specified key/value pair.
      Location location()
      Get location of feature.
      double score()
      Get score.
      java.lang.String seqname()
      Get the sequence name.
      java.lang.String source()
      Get source (aka method).
      java.lang.String toString()
      A string representation of the feature.
      java.lang.String type()
      Get feature type, such as "exon" or "CDS".
      java.util.HashMap<java.lang.String,​java.lang.String> userData()
      Get HashMap of user data.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Feature

        public Feature​(Feature feature)
        Make a copy of the specified feature. The mappings in the userMap() HashMap are copied, so each feature has independent user data. Note, however, that the actual objects in the HashMap are shared (not copied), so a change to such an object may affect multiple features.
        Parameters:
        feature - Feature to clone.
      • Feature

        public Feature​(java.lang.String seqname,
                       java.lang.String source,
                       java.lang.String type,
                       Location location,
                       java.lang.Double score,
                       int frame,
                       java.lang.String attributes)
        Construct a new Feature from raw data (usually a GFF row).
        Parameters:
        seqname - The sequence name field (field 1).
        source - The source or method field (field 2).
        type - The type of feature field (field 3).
        location - The location of the feature. (calculated from GFF start, end and strand fields).
        score - The score field (field 7).
        frame - The frame or phase field (field 8).
        attributes - A string of key/value pairs separated by semicolons (field 9).
    • Method Detail

      • seqname

        public java.lang.String seqname()
        Get the sequence name. (GFF field 1). Note that feature objects have no link or reference to the actual sequence object to which they refer; they are completely uncoupled.
        Specified by:
        seqname in interface FeatureI
        Returns:
        Sequence name.
      • source

        public java.lang.String source()
        Get source (aka method). (GFF field 2). This is often the name of the program or procedure that created the features.
        Returns:
        Source field.
      • type

        public java.lang.String type()
        Get feature type, such as "exon" or "CDS". (GFF field 3).
        Specified by:
        type in interface FeatureI
        Returns:
        Feature type.
      • location

        public Location location()
        Get location of feature. Note that feature objects have no link or reference to the actual sequence object to which they refer; they are completely uncoupled.
        Specified by:
        location in interface FeatureI
        Returns:
        Location of feature.
      • score

        public double score()
        Get score. (GFF field 7). The meaning of the score varies from file to file.
        Returns:
        Score value.
      • frame

        public int frame()
        Get frame (aka phase). (GFF field 8). Specifies the offset of the first nucleotide of the first in-frame codon, assuming this feature is a dna/rna sequence that codes for a protein. If you intend to use this field, you probably want to look it up on the web first.
        Returns:
        The frame (0, 1, 2).
      • attributes

        public java.lang.String attributes()
        Get the string of key/value attributes. (GFF field 9). The format and meaning of this field varies from flavor to flavor of GFF/GTF. This method simply returns the whole string. Other methods in this class make assumptions about its format and provide additional utility.
        Returns:
        The attribute string.
      • userData

        public java.util.HashMap<java.lang.String,​java.lang.String> userData()
        Get HashMap of user data. Each Feature object has a Java HashMap object which can be used to annotate the Feature. JavaGene does not use or interpret the keys or values. The values can be any subtype of the Java Object class.

        If a Feature is constructed from data fields, the initial HashMap has no mappings (is empty). If a Feature is constructed from another Feature, a copy of the mappings is made. Note that the Objects in the copied mapping are shared, even though the mapping itself is copied (not shared). Thus removing or adding a mapping to one Feature will not affect the other, but changing an Object which is part of an established mapping may affect both Features.
        Specified by:
        userData in interface FeatureI
        Returns:
        The user HashMap.
      • getAttribute

        public java.lang.String getAttribute​(java.lang.String key)
        Get value of specified attribute key. Returns null if the attribute key has no value (does not exist). Keys are case-sensitive. Assumes attributes are correctly formatted in GFF style. Known bug: a semicolon within a quoted value will cause parse failure.
        Specified by:
        getAttribute in interface FeatureI
        Parameters:
        key - The key.
        Returns:
        The corresponding value. Null if the key has no value defined.
      • getAttributeOld

        public java.lang.String getAttributeOld​(java.lang.String key)
      • hasAttribute

        public boolean hasAttribute​(java.lang.String key)
        Description copied from interface: FeatureI
        Check if the feature has a value defined for the specified key.
        Specified by:
        hasAttribute in interface FeatureI
        Parameters:
        key - The key.
        Returns:
        True if a value is defined for this key.
      • hasAttribute

        public boolean hasAttribute​(java.lang.String key,
                                    java.lang.String value)
        Description copied from interface: FeatureI
        Check if the feature attributes include the specified key/value pair.
        Specified by:
        hasAttribute in interface FeatureI
        Parameters:
        key - The key.
        value - The value.
        Returns:
        True if the feature's value for this key matches the specified value.
      • group

        public java.lang.String group()
        Get the first item (everything before first semicolon, if it has one) in the attribute field, which is assumed to be a group identifer. This is appropriate for GFF1 files and variants. It is not appropriate for GTF and GFF2 files, although they may use a named attribute key, such as "gene_id" or "transcript_id", for grouping.
        Specified by:
        group in interface FeatureI
        Returns:
        The group id. Everything before the first semicolon in the attributes string (minus trailing whitespace).
      • toString

        public java.lang.String toString()
        Description copied from interface: FeatureI
        A string representation of the feature.
        Specified by:
        toString in interface FeatureI
        Overrides:
        toString in class java.lang.Object
        Returns:
        The string.
      • getAttributes

        public java.util.HashMap<java.lang.String,​java.lang.String> getAttributes()
        Specified by:
        getAttributes in interface FeatureI