Skip to content

Commit

Permalink
milestone: print fusion protein
Browse files Browse the repository at this point in the history
  • Loading branch information
sfchen committed Sep 2, 2017
1 parent 98ef8c6 commit 48335d3
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 90 deletions.
2 changes: 1 addition & 1 deletion src/fusionmapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ void FusionMapper::clusterMatches() {
frs[f].makeReference(mIndexer->mFusionSeq[frs[f].mLeftGP.contig], mIndexer->mFusionSeq[frs[f].mRightGP.contig]);
frs[f].adjustFusionBreak();
frs[f].calcUnique();
frs[f].makeTitle(fusionList);
frs[f].updateInfo(fusionList);
if(frs[f].isQualified()) {
frs[f].print(fusionList);
mFusionResults.push_back(frs[f]);
Expand Down
217 changes: 211 additions & 6 deletions src/fusionresult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
#include "common.h"
#include <stdlib.h>
#include "util.h"
#include <math.h>

using namespace std;

FusionResult::FusionResult() {

mLeftIsExon = false;
mRightIsExon = false;
mLeftExonOrIntronID = -1;
mRightExonOrIntronID = -1;
}

FusionResult::~FusionResult() {
Expand Down Expand Up @@ -126,19 +130,25 @@ bool FusionResult::isQualified() {
return true;
}

void FusionResult::makeTitle(vector<Fusion>& fusions) {
void FusionResult::updateInfo(vector<Fusion>& fusions) {
mLeftGene = fusions[mLeftGP.contig].mGene;
mRightGene = fusions[mRightGP.contig].mGene;

stringstream ss;
if(isDeletion())
ss << "Deletion: ";
else
ss << "Fusion: ";
ss << fusions[mLeftGP.contig].pos2str(mLeftGP.position) << "___";
ss << fusions[mRightGP.contig].pos2str(mRightGP.position) ;
ss << mLeftGene.pos2str(mLeftGP.position) << "___";
ss << mRightGene.pos2str(mRightGP.position) ;
ss << " (total: " << mMatches.size() << ", unique:" << mUnique <<")";
mTitle = ss.str();

mLeftPos = fusions[mLeftGP.contig].pos2str(mLeftGP.position);
mRightPos = fusions[mRightGP.contig].pos2str(mRightGP.position);
mLeftPos = mLeftGene.pos2str(mLeftGP.position);
mRightPos = mRightGene.pos2str(mRightGP.position);

mLeftGene.getExonIntron(mLeftGP.position, mLeftIsExon, mLeftExonOrIntronID);
mRightGene.getExonIntron(mRightGP.position, mRightIsExon, mRightExonOrIntronID);

}

Expand Down Expand Up @@ -232,4 +242,199 @@ void FusionResult::print(vector<Fusion>& fusions) {
cout << ">" << i+1 << ", ";
mMatches[i]->print();
}
}


void FusionResult::printFusionProteinHTML(ofstream& file) {
calcLeftExonIntronNumber();
calcRightExonIntronNumber();
float leftSize = mLeftExonNum + mLeftIntronNum;
float rightSize = mRightExonNum + mRightIntronNum;
int leftPercent = round(leftSize * 100 / (leftSize + rightSize));
int rightPercent = 100 - leftPercent;
file << "<table width='100%' class='protein_table'>\n";
file << "<tr>";
file << "<td width='" << int2str(leftPercent) << "%'>";
file << mLeftGene.mName;
file << "</td>";
file << "<td width='" << int2str(rightPercent) << "%'>";
file << mRightGene.mName;
file << "</td>";
file << "</tr>";
file << "<tr>";
file << "<td class='protein_left' width='" << int2str(leftPercent) << "%'>";
printLeftProteinHTML(file);
file << "</td>";
file << "<td class='protein_right' width='" << int2str(leftPercent) << "%'>";
printRightProteinHTML(file);
file << "</td>";
file << "</tr>";
file << "</table>";
}

void FusionResult::printLeftProteinHTML(ofstream& file) {
float totalStep = mLeftExonNum + mLeftIntronNum;
int exon = 1;
int intron = 1;
int step = 1;
float stepPercent = 100.0/totalStep;
float halfStepPercent = stepPercent * 0.5;
bool forward = isLeftProteinForward();
if(!forward){
exon = mLeftGene.mExons.size();
intron = exon - 1;
step = -1;
}
file << "<table width='100%' class='protein_table'>\n";
file << "<tr>";

float printExon = 0;
float printIntron = 0;

while(printExon < mLeftExonNum || printIntron < mLeftIntronNum) {
if(printExon < mLeftExonNum) {
float percent = stepPercent;
// last one is a half exon
if(printExon+1.0 > mLeftExonNum)
percent = halfStepPercent;
printExonIntronTD(file, true, forward, exon, percent, "exon_left");
printExon += 1.0;
exon += step;
}
if(printIntron < mLeftIntronNum) {
float percent = stepPercent;
// last one is a half intron
if(printIntron+1.0 > mLeftIntronNum)
percent = halfStepPercent;
printExonIntronTD(file, false, forward, intron, percent, "intron_left");
printIntron += 1.0;
intron += step;
}
}

file << "</tr>";
file << "</table>";
}

void FusionResult::printRightProteinHTML(ofstream& file) {
float totalStep = mRightExonNum + mRightIntronNum;
int exon = mRightExonOrIntronID;
int intron = mRightExonOrIntronID;
int step = 1;
float stepPercent = 100.0/totalStep;
float halfStepPercent = stepPercent * 0.5;
bool forward = isRightProteinForward();
if(!forward){
step = -1;
}
file << "<table width='100%' class='protein_table'>\n";
file << "<tr>";

float printExon = 0;
float printIntron = 0;

// print the first half intron
if(!mRightIsExon) {
printExonIntronTD(file, false, forward, intron, halfStepPercent, "intron_right");
printIntron += 0.5;
intron += step;
if(forward)
exon += step;
}

while(printExon < mRightExonNum || printIntron < mRightIntronNum) {
if(printExon < mRightExonNum) {
float percent = stepPercent;
if(mRightIsExon && printExon == 0.0)
percent = halfStepPercent;
printExonIntronTD(file, true, forward, exon, percent, "exon_right");
if(mRightIsExon && printExon == 0.0)
printExon += 0.5;
else
printExon += 1.0;
exon += step;
}
if(printIntron < mRightIntronNum) {
float percent = stepPercent;
printExonIntronTD(file, false, forward, intron, percent, "intron_right");
printIntron += 1.0;
intron += step;
}
}

file << "</tr>";
file << "</table>";
}

void FusionResult::printExonIntronTD(ofstream& file, bool isExon, bool forward, int number, float percent, string style) {
file << "<td class='"<<style<<"' width='" << int2str((int)percent) << "%'>";
if(isExon)
file << "E" << int2str(number);
else {
if(forward)
file << "";
else
file << "";
}
file << "</td>";
}

void FusionResult::calcLeftExonIntronNumber() {
int totalExon = mLeftGene.mExons.size();
int totalIntron = totalExon - 1;
if(isLeftProteinForward()) {
if(mLeftIsExon) {
mLeftExonNum = mLeftExonOrIntronID - 0.5;
mLeftIntronNum = mLeftExonOrIntronID - 1;
} else {
mLeftExonNum = mLeftExonOrIntronID;
mLeftIntronNum = mLeftExonOrIntronID - 0.5;
}
} else {
if(mLeftIsExon) {
mLeftExonNum = totalExon - mLeftExonOrIntronID + 0.5;
mLeftIntronNum = totalIntron - mLeftExonOrIntronID + 1;
} else {
mLeftExonNum = totalExon - mLeftExonOrIntronID;
mLeftIntronNum = totalIntron - mLeftExonOrIntronID + 0.5;
}
}
}

void FusionResult::calcRightExonIntronNumber() {
int totalExon = mRightGene.mExons.size();
int totalIntron = totalExon - 1;
if(isRightProteinForward()) {
if(mRightIsExon) {
mRightExonNum = totalExon - mRightExonOrIntronID + 0.5;
mRightIntronNum = totalIntron - mRightExonOrIntronID + 1;
} else {
mRightExonNum = totalExon - mRightExonOrIntronID;
mRightIntronNum = totalIntron - mRightExonOrIntronID + 0.5;
}
} else {
if(mRightIsExon) {
mRightExonNum = mRightExonOrIntronID - 0.5;
mRightIntronNum = mRightExonOrIntronID - 1;
} else {
mRightExonNum = mRightExonOrIntronID;
mRightIntronNum = mRightExonOrIntronID - 0.5;
}
}
}

bool FusionResult::isLeftProteinForward() {
if(mLeftGene.isReversed()) {
return mLeftGP.position < 0;
} else {
return mLeftGP.position > 0;
}
}

bool FusionResult::isRightProteinForward() {
if(mRightGene.isReversed()) {
return mRightGP.position < 0;
} else {
return mRightGP.position > 0;
}
}
20 changes: 19 additions & 1 deletion src/fusionresult.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FusionResult{
void print(vector<Fusion>& fusions);
void calcFusionPoint();
void calcUnique();
void makeTitle(vector<Fusion>& fusions);
void updateInfo(vector<Fusion>& fusions);
void makeReference(string& refL, string& refR);
void adjustFusionBreak();
void addMatch(Match* m);
Expand All @@ -31,10 +31,18 @@ class FusionResult{
bool canBeMatched(string& s1, string& s2);
bool isQualified();
static bool supportSame(Match* m1, Match* m2);
void printFusionProteinHTML(ofstream& file);

private:
string getRefSeq(string& ref, int start, int end);
int calcED(Match* m, int shift, int& leftED, int& rightED);
bool isLeftProteinForward();
bool isRightProteinForward();
void calcLeftExonIntronNumber();
void calcRightExonIntronNumber();
void printLeftProteinHTML(ofstream& file);
void printRightProteinHTML(ofstream& file);
void printExonIntronTD(ofstream& file, bool isExon, bool forward, int number, float percent, string style);

public:
GenePos mLeftGP;
Expand All @@ -48,6 +56,16 @@ class FusionResult{
string mRightRefExt;
string mLeftPos;
string mRightPos;
Gene mLeftGene;
Gene mRightGene;
bool mLeftIsExon;
bool mRightIsExon;
int mLeftExonOrIntronID;
int mRightExonOrIntronID;
float mLeftExonNum;
float mLeftIntronNum;
float mRightExonNum;
float mRightIntronNum;
};


Expand Down
27 changes: 27 additions & 0 deletions src/gene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,31 @@ string Gene::pos2str(int pos) {
ss<<pp;

return ss.str();
}


void Gene::getExonIntron(int pos, bool& isExon, int& number) {
int pp = abs(pos) + mStart;
for(int i=0; i<mExons.size(); i++) {
if(pp >= mExons[i].start && pp <= mExons[i].end) {
isExon = true;
number = mExons[i].id;
break;
}
if(i>0) {
if(mReversed) {
if(mExons[i].end < pp && pp < mExons[i-1].start){
isExon = false;
number = (mExons[i].id-1);
break;
}
} else {
if(mExons[i-1].end < pp && pp < mExons[i].start){
isExon = false;
number = (mExons[i].id-1);
break;
}
}
}
}
}
1 change: 1 addition & 0 deletions src/gene.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Gene{
void print();
static Gene parse(string linestr);
string pos2str(int pos);
void getExonIntron(int pos, bool& isExon, int& number);

public:
string mName;
Expand Down
6 changes: 6 additions & 0 deletions src/htmlreporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void HtmlReporter::printFusion(int id, FusionResult& fusion){
mFile << "<div class='fusion_head'><a name='fusion_id_" << id << "'>";
mFile << id << ", " << fusion.mTitle ;
mFile << "</a></div>";
fusion.printFusionProteinHTML(mFile);
mFile << "<table>";
mFile << "<tr class='header'>";
mFile << "<td class='alignright' colspan='3'>" << fusion.mLeftPos << " = <font color='yellow'>↓</font></td>";
Expand Down Expand Up @@ -139,6 +140,11 @@ void HtmlReporter::printCSS(){
mFile << ".fusion_point {color:#FFCCAA}";
mFile << "#helper {text-align:left;border:1px dotted #fafafa;color:#777777;font-size:12px;}";
mFile << "#footer {text-align:left;padding-left:10px;padding-top:20px;color:#777777;font-size:10px;}";
mFile << ".exon_left{background:blue;color:white;border:0px;padding:0px;}";
mFile << ".exon_right{background:red;color:white;0px;padding:0px;}";
mFile << ".intron_left{color:blue;0px;padding:0px;}";
mFile << ".intron_right{color:red;0px;padding:0px;}";
mFile << ".protein_table{text-align:center;font-size;8px;}";
mFile << "</style>";
}

Expand Down
Loading

0 comments on commit 48335d3

Please sign in to comment.