gnLocation.h Source File

Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members

# gnLocation.h

Go to the documentation of this file.

    00001 /////////////////////////////////////////////////////////////////////////////
    00002 // File:            gnLocation.h
    00003 // Purpose:         Standard Location for Feature
    00004 // Description:     Feature location
    00005 // Changes:
    00006 // Version:         libGenome 0.5.1
    00007 // Author:          Aaron Darling
    00008 // Modified by:
    00009 // Copyright:       (c) Aaron Darling
    00010 // Licenses:        See COPYING file for details
    00011 /////////////////////////////////////////////////////////////////////////////
    00012 #ifndef _gnLocation_h_
    00013 #define _gnLocation_h_
    00014
    00015 #include "gn/gnDefs.h"
    00016 #include <string>
    00017 #include <iostream>
    00018 #include "gn/gnClone.h"
    00019
    00020 /**
    00021  * This class is used to store sequence locations.  gnBaseFeature uses it
    00022  * to track feature locations.  gnLocation is capable of representing any
    00023  * GenBank style location qualifier.  gnLocation stores the start coordinate
    00024  * and a startLength value which represents the length of an undetermined
    00025  * region of sequence prior to the starting coordinate.  A startLength of
    00026  * GNSEQI_END represents an unknown start, whereas a startLength of 0
    00027  * implies that the start coordinate is unambiguous.  Any value other value
    00028  * indicates a range of coordinates for the starting position.  The range is
    00029  * bounded by the given start coordinate and extends startLength characters
    00030  * upstream.  Likewise, an endLength of GNSEQI_END represents an unknown
    00031  * ambiguous end coordinate, and an endLength of 0 implies that the end
    00032  * coordinate is unambiguous.  Any other value for endLength denotes a range
    00033  * of ending coordinates starting at end and continuing for endLength characters.
    00034  */
    00035
    00036 class GNDLLEXPORT gnLocation : public gnClone
    00037 {
    00038 public:
    00039         enum intersectRestriction{
    00040                 determinedRegions,
    00041                 undeterminedRegions,
    00042                 allRegions
    00043         };
    00044
    00045         enum gnLocationType{
    00046                 LT_Standard,    //standard == join multiple locations.
    00047                 LT_BetweenBases,
    00048                 LT_Complement,
    00049                 LT_Order,
    00050                 LT_Group,
    00051                 LT_OneOf,
    00052                 LT_Nothing
    00053         };
    00054
    00055         static const gnSeqI Defined = 0;
    00056         static const gnSeqI Unknown = GNSEQI_END;
    00057
    00058 public:
    00059         /**
    00060          *      Empty constructor, does nothing.
    00061          */
    00062         gnLocation();
    00063         /**
    00064          *      Copy constructor, copies a gnLocation.
    00065          * @param s the location to copy.
    00066          */
    00067         gnLocation( const gnLocation& s);
    00068         /**
    00069          *      Constructor, creates a gnLocation.
    00070          * @param start The start position within the sequence.
    00071          * @param end The end position within the sequence.
    00072          * @param type The type of the location, LT_Standard by default.
    00073          * @param contigName The name of the contig associated with this location, empty by default.
    00074          * @see gnLocationType
    00075          */
    00076         gnLocation( const gnSeqI start, const gnSeqI end, const gnLocationType type = LT_Standard, string contigName = "");
    00077         /**
    00078          *      Constructor, creates a gnLocation.
    00079          * @param start The start position within the sequence.
    00080          * @param startLength GNSEQI_END if the starting location is unbounded to the left, 0 if defined, otherwise it specifies a range
    00081          * @param end The end position within the sequence.
    00082          * @param endLength 0 if defined, GNSEQI_END if unbounded to the right, otherwise specifies a range
    00083          * @param type The type of the location, LT_Standard by default.
    00084          * @param contigName The name of the contig associated with this location, empty by default.
    00085          * @see gnLocationType
    00086          */
    00087         gnLocation( const gnSeqI start, const gnSeqI startLength, const gnSeqI end, gnSeqI endLength, const gnLocationType type = LT_Standard, string contigName = "");
    00088
    00089         gnLocation* Clone() const;
    00090
    00091         /**
    00092          * Resets this location to default values
    00093          */
    00094         void Clear();
    00095         /**
    00096          * Crops this location to fit within the specified location boundaries.
    00097          * @param l The location boundaries.
    00098          * @return True if the location still exists, false if the crop amount is larger than the location.
    00099          */
    00100         boolean CropTo( const gnLocation &l );
    00101         /**
    00102          * Crops the start location by the specified amount.
    00103          * @param start The amount to crop.
    00104          * @return True if the location still exists, false if the crop amount is larger than the location.
    00105          */
    00106         boolean CropStart( const gnSeqI start );
    00107         /**
    00108          * Crops the end location by the specified amount.
    00109          * @param end The amount to crop.
    00110          * @return True if the location still exists, false if the crop amount is larger than the location.
    00111          */
    00112         boolean CropEnd( const gnSeqI end );
    00113
    00114         /**
    00115          * Returns true if the given location intersects this location in the region specified by the parameter "ir".
    00116          * @param l The location to check for intersection.
    00117          * @param ir The region to check for intersection.  This can be either determinedRegions, undeterminedRegions, or allRegions
    00118          * @see intersectRestriction
    00119          * @return True if the location still exists, false if the crop amount is larger than the location.
    00120          */
    00121         boolean Intersects( const gnLocation &l, const intersectRestriction ir = allRegions ) const;
    00122         /**
    00123          * Checks wether another gnLocation is contained by this one.
    00124          * @param l The gnLocation to be checked.
    00125          * @param cr A specification of the type of intersection to be checked.
    00126          * @see intersectRestriction
    00127          * @return True if the location still exists, false if the crop amount is larger than the location.
    00128          */
    00129         boolean Contains( const gnLocation& l, const intersectRestriction cr = allRegions ) const;
    00130         /**
    00131          * Increases the location start and end.
    00132          * @param diff The amount to increase the location start and end.
    00133          */
    00134         boolean MovePositive( const gnSeqI diff );
    00135         /**
    00136          * Decreases the location start and end.
    00137          * @param diff The amount to decrease the location start and end.
    00138          */
    00139         boolean MoveNegative( const gnSeqI diff );
    00140         /**
    00141          * Moves the location start and end.
    00142          * @param direction Negative integer will decrease start and end, positive will increase them.
    00143          * @param diff The amount to move the location start and end.
    00144          */
    00145         boolean MoveTo( const int direction, const gnSeqI diff );
    00146
    00147         /**
    00148          * Gets the ending base pair.
    00149          * @return The ending base pair.
    00150          */
    00151         gnSeqI GetEnd() const;
    00152         /**
    00153          * Gets the ending base pair's definition value.
    00154          * @return -1 if the ending location is unbounded to the left, 0 if defined, 1 if unbounded to the right
    00155          */
    00156         gnSeqI GetEndLength() const;
    00157         gnSeqI GetLast() const;
    00158         /**
    00159          * Gets the starting base pair.
    00160          * @return The starting base pair.
    00161          */
    00162         gnSeqI GetStart() const;
    00163         /**
    00164          * Gets the starting base pair's definition value.
    00165          * @return -1 if the starting location is unbounded to the left, 0 if defined, 1 if unbounded to the right
    00166          */
    00167         gnSeqI GetStartLength() const;
    00168         gnSeqI GetFirst() const;
    00169
    00170         /**
    00171          * Gets the location type.
    00172          * @return the location type.
    00173          * @see gnLocationType
    00174          */
    00175         gnLocationType GetType() const;
    00176
    00177         /**
    00178          * Gets the location's boundaries.
    00179          * @param s The start index.
    00180          * @param sl The start length.
    00181          * @param e The end index.
    00182          * @param el The end length.
    00183          */
    00184         void GetBounds( gnSeqI &s, gnSeqI &sl, gnSeqI &e, gnSeqI &el ) const;
    00185
    00186         /**
    00187          * Returns true if the end is unbounded to the right.
    00188          * @return True if the end is unbounded to the right.
    00189          */
    00190         bool IsEndBoundLonger() const;
    00191         /**
    00192          * Returns true if the start is unbounded to the right.
    00193          * @return True if the start is unbounded to the right.
    00194          */
    00195         bool IsStartBoundLonger() const;
    00196         /**
    00197          * Returns true if the end is unbounded to the left.
    00198          * @return True if the end is unbounded to the left.
    00199          */
    00200         bool IsEndBoundShorter() const;
    00201         /**
    00202          * Returns true if the start is unbounded to the left.
    00203          * @return True if the start is unbounded to the left.
    00204          */
    00205         bool IsStartBoundShorter() const;
    00206
    00207         /**
    00208          * Sets the end location.
    00209          * @param end The end location.
    00210          */
    00211         void SetEnd( const gnSeqI end );
    00212         /**
    00213          * Sets the end location and definition.
    00214          * @param end The end location.
    00215          * @param endLength -1 if the ending location is unbounded to the left, 0 if defined, 1 if unbounded to the right
    00216          */
    00217         void SetEnd( const gnSeqI end, const gnSeqI endLength );
    00218         /**
    00219          * Sets the end definition.
    00220          * @param endLength -1 if the ending location is unbounded to the left, 0 if defined, 1 if unbounded to the right
    00221          */
    00222         void SetEndLength( const gnSeqI endLength );
    00223
    00224         /**
    00225          * Sets the start location/
    00226          * @param start The start location.
    00227          */
    00228         void SetStart( const gnSeqI start );
    00229         /**
    00230          * Sets the start location and definition.
    00231          * @param start The end location.
    00232          * @param startLength -1 if the ending location is unbounded to the left, 0 if defined, 1 if unbounded to the right
    00233          */
    00234         void SetStart( const gnSeqI start, const gnSeqI startLength );
    00235         /**
    00236          * Sets the start definition.
    00237          * @param startLength -1 if the ending location is unbounded to the left, 0 if defined, 1 if unbounded to the right
    00238          */
    00239         void SetStartLength( const gnSeqI startLength );
    00240         /**
    00241          * Sets the location type.
    00242          * @param lt The location type.
    00243          */
    00244         void SetType( const gnLocationType lt );
    00245         /**
    00246          * Sets the location's boundaries.
    00247          * @param start The start index.
    00248          * @param startLength -1 if the ending location is unbounded to the left, 0 if defined, 1 if unbounded to the right
    00249          * @param end The end index.
    00250          * @param endLength -1 if the ending location is unbounded to the left, 0 if defined, 1 if unbounded to the right
    00251          */
    00252         void SetBounds( const gnSeqI start, const gnSeqI startLength, const gnSeqI end, const gnSeqI endLength);
    00253         /**
    00254          * Sets the location's boundaries.
    00255          * @param start The start index.
    00256          * @param end The end index.
    00257          */
    00258         void SetBounds( const gnSeqI start, const gnSeqI end);
    00259
    00260         gnLocation GetUnion( const gnLocation &l ) const;
    00261
    00262         gnLocation GetIntersection( const gnLocation &l, const intersectRestriction ir ) const;
    00263
    00264 private:
    00265         string m_name;
    00266         gnSeqI m_start;
    00267         gnSeqI m_startLength;
    00268         gnSeqI m_end;
    00269         gnSeqI m_endLength;
    00270
    00271         gnLocationType m_type;
    00272
    00273 }; // class gnLocation
    00274
    00275 // GET END
    00276 inline
    00277 gnSeqI gnLocation::GetEnd() const
    00278 {
    00279         return m_end;
    00280 }
    00281 inline
    00282 gnSeqI gnLocation::GetEndLength() const
    00283 {
    00284         return m_endLength;
    00285 }
    00286 inline
    00287 gnSeqI gnLocation::GetLast() const
    00288 {
    00289         return m_end + m_endLength;
    00290 }
    00291 // GET START
    00292 inline
    00293 gnSeqI gnLocation::GetStart() const
    00294 {
    00295         return m_start;
    00296 }
    00297 inline
    00298 gnSeqI gnLocation::GetStartLength() const
    00299 {
    00300         return m_startLength;
    00301 }
    00302 inline
    00303 gnSeqI gnLocation::GetFirst() const
    00304 {
    00305         return m_start > m_startLength ? m_start - m_startLength : 0;
    00306 }
    00307
    00308 inline
    00309 gnLocation::gnLocationType gnLocation::GetType() const
    00310 {
    00311         return m_type;
    00312 }
    00313
    00314 inline
    00315 bool gnLocation::IsEndBoundLonger() const
    00316 {
    00317         return m_endLength > 0;
    00318 }
    00319 inline
    00320 bool gnLocation::IsStartBoundLonger() const
    00321 {
    00322         return m_startLength > 0;
    00323 }
    00324 inline
    00325 bool gnLocation::IsEndBoundShorter() const
    00326 {
    00327         return m_endLength < 0;
    00328 }
    00329 inline
    00330 bool gnLocation::IsStartBoundShorter() const
    00331 {
    00332         return m_startLength < 0;
    00333 }
    00334
    00335 inline
    00336 void gnLocation::SetEnd( const gnSeqI end )
    00337 {
    00338         m_end = end;
    00339 }
    00340 inline
    00341 void gnLocation::SetEnd( const gnSeqI end, const gnSeqI endLength )
    00342 {
    00343         m_end = end;
    00344         m_endLength = endLength;
    00345 }
    00346 inline
    00347 void gnLocation::SetEndLength( const gnSeqI endLength )
    00348 {
    00349         m_endLength = endLength;
    00350 }
    00351 inline
    00352 void gnLocation::SetStart( const gnSeqI start )
    00353 {
    00354         m_start = start;
    00355 }
    00356 inline
    00357 void gnLocation::SetStart( const gnSeqI start, const gnSeqI startLength )
    00358 {
    00359         m_start = start;
    00360         m_startLength = startLength;
    00361 }
    00362 inline
    00363 void gnLocation::SetStartLength( const gnSeqI startLength )
    00364 {
    00365         m_startLength = startLength;
    00366 }
    00367
    00368 inline
    00369 void gnLocation::SetType( const gnLocationType lt )
    00370 {
    00371         m_type = lt;
    00372 }
    00373
    00374
    00375 #endif
    00376         // _gnLocation_h_