cav_alndisplay.cpp

来自「ncbi源码」· C++ 代码 · 共 1,340 行 · 第 1/4 页

CPP
1,340
字号
                        if (color != prevColor) {                            os << "</font><font color=" << color << '>';                            prevColor = color;                        }                        condensedColumns[paragraphStart+i]->DumpRow(os, row);                    }                    os << "</font>";                } else {                    for (i=0; i<nCondensedColumns; ++i) {                        condensedColumns[paragraphStart+i]->DumpRow(os, row);                    }                }                // right end pos                if (nDisplayedResidues > 0) {                    os << ' ';                    if (doHTML) os << "<font color=" << numColor << '>';                    os << LEFT_JUSTIFY << setw(0) << (lastShownSeqLocs[alnRow]+nDisplayedResidues+1);                    if (doHTML) os << "</font>";                }                os << '\n';                // setup to begin next parag                lastShownSeqLocs[alnRow] += nDisplayedResidues;            }            // print alignment annotation characters            else {                // skip number                os << RIGHT_JUSTIFY << setw(maxSeqLocStrLength) << ' ' << ' ';                // do characters                for (i=0; i<nCondensedColumns; ++i)                    condensedColumns[paragraphStart+i]->DumpRow(os, row);                os << (doHTML ? "</font>\n" : "\n");            }        }        // end table row        if (doHTML) os << "</pre></td></tr>\n";    }    if (doHTML) os << "</TABLE>\n";    // add feature legend    if (nFeatures > 0) {        os << (doHTML ? "<BR>\n" : "\n");        for (featIndex=0; featIndex<nFeatures; ++featIndex)            if (alnFeatures[featIndex].description)                os << alnFeatures[featIndex].shortName << ": " << alnFeatures[featIndex].description                   << (doHTML ? "<BR>\n" : "\n");    }    if (doHTML && doHTMLHeader) os << "</BODY></HTML>\n";    // additional sanity check on seqloc markers    if (firstCol == 0 && lastCol == GetWidth()-1) {        for (alnRow=0; alnRow<GetNRows(); ++alnRow) {            if (lastShownSeqLocs[alnRow] !=                    indexAlnLocToSeqLocRows[alnRow]->sequence->sequenceString.size()-1) {                ERR_POST(Error << "full display - seqloc markers don't add up");                break;            }        }        if (alnRow == GetNRows())            ERR_POST(Info << "full display - seqloc markers add up correctly");    }    return CAV_SUCCESS;}int AlignmentDisplay::DumpText(CNcbiOstream& os, unsigned int options,    int firstCol, int lastCol, int nColumns, double conservationThreshhold,    const char *titleHTML, int nFeatures, const AlignmentFeature *alnFeatures) const{    bool doHTML = ((options & CAV_HTML) > 0), doHTMLHeader = ((options & CAV_HTML_HEADER) > 0);    if (firstCol < 0 || lastCol >= GetWidth() || firstCol > lastCol || nColumns < 1) {        ERR_POST(Error << "AlignmentDisplay::DumpText() - nonsensical display region parameters");        return CAV_ERROR_BAD_PARAMS;    }    // how many rows in the display, including annotations?    int nDisplayRows = GetNRows();    if (!alnFeatures) nFeatures = 0;    if (nFeatures > 0) nDisplayRows += nFeatures;    // set up the titles and uids, figure out how much space any seqLoc string will take    vector < string > titles(nDisplayRows), uids(doHTML ? GetNRows() : 0);    int row, featIndex, alnRow, maxTitleLength = 0, maxSeqLocStrLength = 0, leftMargin, decimalLength;    bool isAlnRow;    for (row=0; row<nDisplayRows; ++row) {        if (options & CAV_ANNOT_BOTTOM) {            alnRow = row;            featIndex = row - GetNRows();        } else {            featIndex = row;            alnRow = row - nFeatures;        }        isAlnRow = (alnRow >= 0 && alnRow < GetNRows());        // title        titles[row] = isAlnRow ?            indexAlnLocToSeqLocRows[alnRow]->sequence->GetTitle() :            string(alnFeatures[featIndex].shortName);        if (titles[row].size() > maxTitleLength) maxTitleLength = titles[row].size();        if (isAlnRow) {            decimalLength = ((int) log10((double)                indexAlnLocToSeqLocRows[alnRow]->sequence->sequenceString.size())) + 1;            if (decimalLength > maxSeqLocStrLength) maxSeqLocStrLength = decimalLength;        }        // uid for link to entrez        if (doHTML && isAlnRow) {            if (indexAlnLocToSeqLocRows[alnRow]->sequence->pdbID.size() > 0) {                if (indexAlnLocToSeqLocRows[alnRow]->sequence->pdbID != "query" &&                    indexAlnLocToSeqLocRows[alnRow]->sequence->pdbID != "consensus") {                    uids[alnRow] = indexAlnLocToSeqLocRows[alnRow]->sequence->pdbID;                    if (indexAlnLocToSeqLocRows[alnRow]->sequence->pdbChain != ' ')                        uids[alnRow] += (char) indexAlnLocToSeqLocRows[alnRow]->sequence->pdbChain;                }            } else if (indexAlnLocToSeqLocRows[alnRow]->sequence->gi != Sequence::NOT_SET) {                CNcbiOstrstream uidoss;                uidoss << indexAlnLocToSeqLocRows[alnRow]->sequence->gi << '\0';                uids[alnRow] = uidoss.str();                delete uidoss.str();            } else if (indexAlnLocToSeqLocRows[alnRow]->sequence->accession.size() > 0) {                uids[alnRow] = indexAlnLocToSeqLocRows[alnRow]->sequence->accession;            }        }    }    leftMargin = maxTitleLength + maxSeqLocStrLength + 2;    // need to keep track of first, last seqLocs for each row in each paragraph;    // find seqLoc of first residue >= firstCol    vector < int > lastShownSeqLocs(GetNRows());    int alnLoc;    for (alnRow=0; alnRow<GetNRows(); ++alnRow) {        lastShownSeqLocs[alnRow] = -1;        for (alnLoc=0; alnLoc<firstCol; ++alnLoc)            if (!IsGap(textRows[alnRow]->GetCharAt(alnLoc))) lastShownSeqLocs[alnRow]++;    }    // header    if (doHTML && doHTMLHeader)        os << "<HTML><TITLE>" << (titleHTML ? titleHTML : "CDDAlignView HTML Display") <<            "</TITLE><BODY BGCOLOR=" << bgColor << ">\n";;    // do make look-up location index for each feature    vector < vector < bool > > annotLocsByIndex;    int i, masterIndex;    if (nFeatures > 0) {        annotLocsByIndex.resize(nFeatures);        for (featIndex=0; featIndex<nFeatures; ++featIndex) {            annotLocsByIndex[featIndex].resize(indexAlnLocToSeqLocRows[0]->sequence->Length(), false);            for (i=0; i<alnFeatures[featIndex].nLocations; ++i) {                masterIndex = alnFeatures[featIndex].locations[i];                if (masterIndex >= 0 && masterIndex < indexAlnLocToSeqLocRows[0]->sequence->Length())                    annotLocsByIndex[featIndex][masterIndex] = true;            }        }    }    // split alignment up into "paragraphs", each with nColumns    if (doHTML) os << "<TABLE>\n";    int paragraphStart, nParags = 0;    for (paragraphStart=0; (firstCol+paragraphStart)<=lastCol; paragraphStart+=nColumns, ++nParags) {        // start table row        if (doHTML)            os << "<tr><td bgcolor=" << blockBGColors[nParags % nBlockColors] << "><pre>\n";        else            if (paragraphStart > 0) os << '\n';        // do ruler        int nMarkers = 0, width;        if (doHTML) os << "<font color=" << rulerColor << '>';        for (i=0; i<nColumns && (firstCol+paragraphStart+i)<=lastCol; ++i) {            if ((paragraphStart+i+1)%10 == 0) {                if (nMarkers == 0)                    width = leftMargin + i + 1;                else                    width = 10;                os << RIGHT_JUSTIFY << setw(width) << (paragraphStart+i+1);                ++nMarkers;            }        }        if (doHTML) os << "</font>";        os << '\n';        if (doHTML) os << "<font color=" << rulerColor << '>';        for (i=0; i<leftMargin; ++i) os << ' ';        for (i=0; i<nColumns && (firstCol+paragraphStart+i)<=lastCol; ++i) {            if ((paragraphStart+i+1)%10 == 0)                os << '|';            else if ((paragraphStart+i+1)%5 == 0)                os << '*';            else                os << '.';        }        if (doHTML) os << "</font>";        os << '\n';        // get column colors        vector < string > columnColors;        if (doHTML)            for (i=0; i<nColumns && (firstCol+paragraphStart+i)<=lastCol; ++i)                columnColors.resize(columnColors.size()+1,                    GetColumnColor(firstCol+paragraphStart+i, conservationThreshhold));        // output each alignment row        int nDisplayedResidues;        for (row=0; row<nDisplayRows; ++row) {            if (options & CAV_ANNOT_BOTTOM) {                alnRow = row;                featIndex = row - GetNRows();            } else {                featIndex = row;                alnRow = row - nFeatures;            }            isAlnRow = (alnRow >= 0 && alnRow < GetNRows());            // actual sequence characters; count how many non-gaps in each row            nDisplayedResidues = 0;            string rowChars;            if (isAlnRow) {                for (i=0; i<nColumns && (firstCol+paragraphStart+i)<=lastCol; ++i) {                    char ch = textRows[alnRow]->GetCharAt(firstCol+paragraphStart+i);                    rowChars += ch;                    if (!IsGap(ch)) ++nDisplayedResidues;                }            }            // title            if (isAlnRow && doHTML && uids[alnRow].size() > 0) {                os << "<a href=\"http://www.ncbi.nlm.nih.gov/entrez/query.fcgi"                    << "?cmd=Search&doptcmdl=GenPept&db=Protein&term="                    << uids[alnRow] << "\" onMouseOut=\"window.status=''\"\n"                    << "onMouseOver=\"window.status='"                    << ((indexAlnLocToSeqLocRows[alnRow]->sequence->description.size() > 0) ?                            indexAlnLocToSeqLocRows[alnRow]->sequence->description : titles[row])                    << "';return true\">"                    << setw(0) << titles[row] << "</a>";            } else {                if (doHTML && !isAlnRow) os << "<font color=" << featColor << '>';                os << setw(0) << titles[row];            }            os << setw(maxTitleLength+1-titles[row].size()) << ' ';            if (isAlnRow) {                // left start pos (output 1-numbered for humans...)                if (doHTML) os << "<font color=" << numColor << '>';                if (nDisplayedResidues > 0)                    os << RIGHT_JUSTIFY << setw(maxSeqLocStrLength) << (lastShownSeqLocs[alnRow]+2) << ' ';                else                    os << RIGHT_JUSTIFY << setw(maxSeqLocStrLength) << ' ' << ' ';                // dump sequence, applying color changes only when necessary                if (doHTML) {                    string prevColor;                    for (i=0; i<rowChars.size(); ++i) {                        if (columnColors[i] != prevColor) {                            os << "</font><font color=" << columnColors[i] << '>';                            prevColor = columnColors[i];                        }                        os << rowChars[i];                    }                    os << "</font>";                } else                    os << rowChars;                // right end pos                if (nDisplayedResidues > 0) {                    os << ' ';                    if (doHTML) os << "<font color=" << numColor << '>';                    os << LEFT_JUSTIFY << setw(0) << (lastShownSeqLocs[alnRow]+nDisplayedResidues+1);                    if (doHTML) os << "</font>";                }                os << '\n';                // setup to begin next parag                lastShownSeqLocs[alnRow] += nDisplayedResidues;            }            // print alignment annotation characters            else {                // skip number                os << RIGHT_JUSTIFY << setw(maxSeqLocStrLength) << ' ' << ' ';                // do characters, but only allow annot where master residue is aligned to something                for (i=0; i<nColumns && (firstCol+paragraphStart+i)<=lastCol; ++i) {                    if (IsAligned(textRows[0]->GetCharAt(firstCol+paragraphStart+i))) {                        masterIndex = indexAlnLocToSeqLocRows[0]->GetSeqLocAt(firstCol+paragraphStart+i);                        os << ((masterIndex >= 0 && annotLocsByIndex[featIndex][masterIndex])                            ? alnFeatures[featIndex].featChar : ' ');                    } else                        os << ' ';                }                os << (doHTML ? "</font>\n" : "\n");            }        }        // end table row        if (doHTML) os << "</pre></td></tr>\n";    }    if (doHTML) os << "</TABLE>\n";    // add feature legend    if (nFeatures > 0) {        os << (doHTML ? "<BR>\n" : "\n");        for (featIndex=0; featIndex<nFeatures; ++featIndex)            if (alnFeatures[featIndex].description)                os << alnFeatures[featIndex].shortName << ": " << alnFeatures[featIndex].description                   << (doHTML ? "<BR>\n" : "\n");    }    if (doHTML && doHTMLHeader) os << "</BODY></HTML>\n";    // additional sanity check on seqloc markers    if (firstCol == 0 && lastCol == GetWidth()-1) {        for (alnRow=0; alnRow<GetNRows(); ++alnRow) {            if (lastShownSeqLocs[alnRow] !=                    indexAlnLocToSeqLocRows[alnRow]->sequence->sequenceString.size()-1) {                ERR_POST(Error << "full display - seqloc markers don't add up");                break;            }        }        if (alnRow == GetNRows())            ERR_POST(Info << "full display - seqloc markers add up correctly");    }    return CAV_SUCCESS;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?