]> git.donarmstrong.com Git - bamtools.git/blob - src/api/SamSequence.h
Brought API up to compliance with recent SAM Format Spec (v1.4-r962)
[bamtools.git] / src / api / SamSequence.h
1 // ***************************************************************************
2 // SamSequence.h (c) 2010 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 18 April 2011 (DB)
7 // ---------------------------------------------------------------------------
8 // Provides direct read/write access to the SAM sequence data fields.
9 // ***************************************************************************
10
11 #ifndef SAM_SEQUENCE_H
12 #define SAM_SEQUENCE_H
13
14 #include <api/api_global.h>
15 #include <string>
16
17 namespace BamTools {
18
19 struct API_EXPORT SamSequence {
20
21     // ctor & dtor
22     SamSequence(void);
23     SamSequence(const std::string& name, const int& length);
24     SamSequence(const std::string& name, const std::string& length);
25     SamSequence(const SamSequence& other);
26     ~SamSequence(void);
27
28     // query/modify entire sequence
29     void Clear(void);                   // clears all contents
30
31     // convenience query methods
32     bool HasAssemblyID(void) const;     // returns true if sequence has an assembly ID
33     bool HasChecksum(void) const;       // returns true if sequence has an MD5 checksum
34     bool HasLength(void) const;         // returns true if sequence has a length
35     bool HasName(void) const;           // returns true if sequence has a name
36     bool HasSpecies(void) const;        // returns true if sequence has a species ID
37     bool HasURI(void) const;            // returns true if sequence has a URI
38
39     // data members
40     std::string AssemblyID;             // AS:<AssemblyID>
41     std::string Checksum;               // M5:<Checksum>
42     std::string Length;                 // LN:<Length>      *Required for valid SAM header*
43     std::string Name;                   // SN:<Name>        *Required for valid SAM header*
44     std::string Species;                // SP:<Species>
45     std::string URI;                    // UR:<URI>
46 };
47
48 /*! \fn bool operator==(const SamSequence& lhs, const SamSequence& rhs)
49     \brief tests equality by comparing sequence names, lengths, & checksums (if available)
50 */
51 API_EXPORT inline bool operator==(const SamSequence& lhs, const SamSequence& rhs) {
52     if ( lhs.Name   != rhs.Name   ) return false;
53     if ( lhs.Length != rhs.Length ) return false;
54     if ( lhs.HasChecksum() && rhs.HasChecksum() )
55         return (lhs.Checksum == rhs.Checksum);
56     else return true;
57 }
58
59 } // namespace BamTools
60
61 #endif // SAM_SEQUENCE_H