0
|
1 /*****************************************************************************
|
|
2 linksBed.cpp
|
|
3
|
|
4 (c) 2009 - Aaron Quinlan
|
|
5 Hall Laboratory
|
|
6 Department of Biochemistry and Molecular Genetics
|
|
7 University of Virginia
|
|
8 aaronquinlan@gmail.com
|
|
9
|
|
10 Licenced under the GNU General Public License 2.0 license.
|
|
11 ******************************************************************************/
|
|
12 #include "lineFileUtilities.h"
|
|
13 #include "linksBed.h"
|
|
14
|
|
15 //
|
|
16 // Constructor
|
|
17 //
|
|
18 BedLinks::BedLinks(string &bedFile, string &base, string &org, string &db) {
|
|
19 _bedFile = bedFile;
|
|
20 _bed = new BedFile(bedFile);
|
|
21
|
|
22 _base = base;
|
|
23 _org = org;
|
|
24 _db = db;
|
|
25
|
|
26 CreateLinks();
|
|
27 }
|
|
28
|
|
29 //
|
|
30 // Destructor
|
|
31 //
|
|
32 BedLinks::~BedLinks(void) {
|
|
33 }
|
|
34
|
|
35
|
|
36 void BedLinks::WriteURL(BED &bed, string &base) {
|
|
37
|
|
38 string position = bed.chrom;
|
|
39 std::stringstream posStream;
|
|
40 posStream << ":" << bed.start << "-" << bed.end;
|
|
41 position.append(posStream.str());
|
|
42
|
|
43 cout << "<tr>" << endl;
|
|
44 cout << "\t<td>" << endl;
|
|
45 cout << "\t\t<a href=" << base << position << ">";
|
|
46 cout << bed.chrom << ":" << bed.start << "-" << bed.end;
|
|
47 cout << "</a>" << endl;
|
|
48 cout << "\t</td>" << endl;
|
|
49
|
|
50 if (_bed->bedType == 4) {
|
|
51 cout << "\t<td>" << endl;
|
|
52 cout << bed.name << endl;
|
|
53 cout << "\t</td>" << endl;
|
|
54 }
|
|
55 else if (_bed->bedType == 5) {
|
|
56 cout << "\t<td>" << endl;
|
|
57 cout << bed.name << endl;
|
|
58 cout << "\t</td>" << endl;
|
|
59
|
|
60 cout << "\t<td>" << endl;
|
|
61 cout << bed.score << endl;
|
|
62 cout << "\t</td>" << endl;
|
|
63 }
|
|
64 else if ((_bed->bedType == 6) || (_bed->bedType == 9) || (_bed->bedType == 12)) {
|
|
65 cout << "\t<td>" << endl;
|
|
66 cout << bed.name << endl;
|
|
67 cout << "\t</td>" << endl;
|
|
68
|
|
69 cout << "\t<td>" << endl;
|
|
70 cout << bed.score << endl;
|
|
71 cout << "\t</td>" << endl;
|
|
72
|
|
73 cout << "\t<td>" << endl;
|
|
74 cout << bed.strand << endl;
|
|
75 cout << "\t</td>" << endl;
|
|
76 }
|
|
77 cout << "</tr>" << endl;
|
|
78 }
|
|
79
|
|
80
|
|
81 void BedLinks::CreateLinks() {
|
|
82
|
|
83
|
|
84 // construct the html base.
|
|
85 string org = _org;
|
|
86 string db = _db;
|
|
87 string base = _base;
|
|
88 base.append("/cgi-bin/hgTracks?org=");
|
|
89 base.append(org);
|
|
90 base.append("&db=");
|
|
91 base.append(db);
|
|
92 base.append("&position=");
|
|
93
|
|
94 // create the HTML header
|
|
95 cout << "<html>" << endl <<"\t<body>" << endl;
|
|
96 cout << "<title>" << _bedFile << "</title>" << endl;
|
|
97
|
|
98 // start the table of entries
|
|
99 cout << "<br>Firefox users: Press and hold the \"apple\" or \"alt\" key and click link to open in new tab." << endl;
|
|
100 cout << "<p style=\"font-family:courier\">" << endl;
|
|
101 cout << "<table border=\"0\" align=\"justify\"" << endl;
|
|
102 cout << "<h3>BED Entries from: stdin </h3>" << endl;
|
|
103
|
|
104 int lineNum = 0;
|
|
105 BED bedEntry, nullBed;
|
|
106 BedLineStatus bedStatus;
|
|
107
|
|
108 _bed->Open();
|
|
109 while ((bedStatus = _bed->GetNextBed(bedEntry, lineNum)) != BED_INVALID) {
|
|
110 if (bedStatus == BED_VALID) {
|
|
111 WriteURL(bedEntry, base);
|
|
112 bedEntry = nullBed;
|
|
113 }
|
|
114 }
|
|
115 _bed->Close();
|
|
116
|
|
117 cout << "</table>" << endl;
|
|
118 cout << "</p>" << endl;
|
|
119 cout << "\t</body>" << endl <<"</html>" << endl;
|
|
120 }
|
|
121
|
|
122
|