]> git.donarmstrong.com Git - bamtools.git/blob - src/api/SamSequence.h
fea09d39b4148526e639784af9b509e4f5a30569
[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: 4 March 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 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 HasName(void) const;                   // returns true if sequence has a name
32     bool HasLength(void) const;                 // returns true if sequence has a length
33     bool HasAssemblyID(void) const;             // returns true if sequence has an assembly ID
34     bool HasChecksum(void) const;               // returns true if sequence has an MD5 checksum
35     bool HasURI(void) const;                    // returns true if sequence has a URI
36     bool HasSpecies(void) const;                // returns true if sequence has a species ID
37
38     // data members
39     std::string Name;       // SN:<Name>
40     std::string Length;     // LN:<Length>
41     std::string AssemblyID; // AS:<AssemblyID>
42     std::string Checksum;   // M5:<Checksum>
43     std::string URI;        // UR:<URI>
44     std::string Species;    // SP:<Species>
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