ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/tophat_cpp/insertions.h
Revision: 154
Committed: Tue Jan 24 02:29:21 2012 UTC (7 years, 8 months ago) by gpertea
File size: 2387 byte(s)
Log Message:
massive update with Daehwan's work

Line File contents
1 #ifndef INSERTIONS_H
2 #define INSERTIONS_H
3 /*
4 * insertions.h
5 * TopHat
6 *
7 * Adapted from junctions.h
8 */
9
10 #include <cstdio>
11 #include <vector>
12 #include <string>
13 //#include <map>
14 //#include <algorithm>
15 #include <set>
16 //#include <stdexcept>
17 #include <iostream>
18 #include <fstream>
19 #include <cstring>
20 #include <seqan/sequence.h>
21 #include <seqan/find.h>
22 #include <seqan/file.h>
23
24 #include "bwt_map.h"
25
26 using namespace std;
27
28
29
30
31
32 /**
33 * Data structure to represent an insertion.
34 * Need to keep track of the actual position of the insertion
35 * as well the actual inserted sequence.
36 */
37 struct Insertion
38 {
39
40 Insertion (uint32_t ref, uint32_t l, const std::string& seq)
41 : refid(ref), left(l), sequence(seq){}
42 Insertion() : refid(0), left(0), sequence("") {}
43 /**
44 * The ID of the assoicated reference sequence (eg, chr22). In order to actually turn this into
45 * a string, need to use the map associated with the reference table
46 */
47 uint32_t refid;
48 /**
49 * The position of the insertion.
50 * This is the 0-based position of the last genomic nucleotide before the insertion
51 */
52 uint32_t left;
53
54 /**
55 * The actual inserted sequence.
56 */
57 std::string sequence;
58
59 bool operator<(const Insertion& rhs) const
60 {
61 if (refid < rhs.refid)
62 return true;
63 else if (refid > rhs.refid)
64 return false;
65
66 if (left < rhs.left)
67 return true;
68 else if (left > rhs.left)
69 return false;
70
71 if (sequence.length() < rhs.sequence.length())
72 return true;
73 return false;
74 }
75
76
77 bool operator==(const Insertion& rhs) const
78 {
79 return (refid == rhs.refid && left == rhs.left && sequence == rhs.sequence);
80 }
81
82 };
83
84 /**
85 * A function used to compare Insertions, specifically for use
86 * with std::sets. My C++ is a little weak, but I imagine
87 * there should be someway to directly address the overloaded
88 * operator function and ditch this code.
89 */
90 struct insertion_comparison
91 {
92 bool operator()(const Insertion& lhs, const Insertion& rhs)
93 {
94 return lhs < rhs;
95 }
96 };
97
98 typedef std::map<Insertion, uint32_t> InsertionSet;
99
100
101 void insertions_from_alignment(const BowtieHit& bh, InsertionSet& insertions);
102 void print_insertions(FILE* insertions_out, const InsertionSet& insertions, RefSequenceTable& ref_sequences);
103 void insertions_from_spliced_hit(const BowtieHit& bh, vector<Insertion>& insertions);
104 void merge_with(InsertionSet& insertions, const InsertionSet& other);
105
106
107 #endif