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