示例#1
0
bool RemasterWithStructure(CCdCore* cd, string* msg)
{
    static const string msgHeader = "Remastering CD to ";

	CRef< CSeq_id > seqId;
	cd->GetSeqIDForRow(0,0,seqId);
	if (seqId->IsPdb())
		return false;
	AlignmentCollection ac(cd,CCdCore::USE_NORMAL_ALIGNMENT);
	int nrows = ac.GetNumRows();
	int i = 1;
	for (; i < nrows; i++)
	{
		ac.GetSeqIDForRow(i,seqId);
		if (seqId->IsPdb())
			break;
	}
	if ( i < nrows)
	{
		ReMasterCdWithoutUnifiedBlocks(cd, i, true);
        if (msg) {
            *msg = msgHeader + seqId->AsFastaString();
        }
		return true;
	}
	else
		return false;
}
示例#2
0
int  PurgeConsensusSequences(CCdCore* pCD, bool resetFields)
{
    int nPurged = 0;
    vector<int> consensusRows, consensusSeqListIds;

    if (pCD) {
        //  First see if the master is a consensus; if so, remaster to 2nd row
        if (pCD->UsesConsensusSequenceAsMaster()) {
            ReMasterCdWithoutUnifiedBlocks(pCD, 1,true);
        }

        //  Next, find all rows using 'consensus' as a seq_id and remove them.

        nPurged = pCD->GetRowsWithConsensus(consensusRows);
        if (nPurged) {
            pCD->EraseTheseRows(consensusRows);
            if (pCD->FindConsensusInSequenceList(&consensusSeqListIds)) {
                for (int i = consensusSeqListIds.size() - 1; i >= 0 ; --i) {
                    pCD->EraseSequence(consensusSeqListIds[i]);
                }
            }
        }
    }

    return nPurged;
}
示例#3
0
void SeqSwapper::swapSequences()
{
	int numNormal = m_cd->GetNumRows();
	LOG_POST("Clustering");
	vector< vector<int> * > clusters;
	makeClusters(m_clusteringThreshold, clusters);
	vector< pair<int, int> > replacementPairs;
	set<int> structures;
	LOG_POST("Clustering is done (made " << clusters.size() << " clusters)");
	LOG_POST("Find replacements by BLAST in each cluster");
	for (int i = 0; i < clusters.size(); i++)
	{
		vector<int>* cluster = clusters[i];
        if (cluster) {
            findReplacements(*cluster, replacementPairs, structures);
            delete cluster;
        }
	}
	LOG_POST("Done with BLAST in each cluster");
	set<int> usedPendings;
	
	vector<int> selectedNormalRows;
	int newMaster = -1;
	for (int p = 0; p < replacementPairs.size(); p++)
	{
		//debug
		CRef< CSeq_id > seqId;
		m_ac.GetSeqIDForRow(replacementPairs[p].first, seqId);
		string nid = seqId->AsFastaString();
		m_ac.GetSeqIDForRow(replacementPairs[p].second, seqId);
		string pid = seqId->AsFastaString();
		LOG_POST("replacing "<<nid<<" with "<<pid);
		//take care of master replacement
		if (replacementPairs[p].first == 0)
			newMaster = replacementPairs[p].second - numNormal;
		else
		{
			selectedNormalRows.push_back(replacementPairs[p].first);
			usedPendings.insert(replacementPairs[p].second - numNormal);
		}
	}
	m_cd->EraseTheseRows(selectedNormalRows);
	if (structures.size() > 0)
	{
		LOG_POST("Adding "<<structures.size()<<" structures");
		for (set<int>::iterator sit = structures.begin(); sit != structures.end(); sit++)
			usedPendings.insert(*sit - numNormal);
	}
	if (newMaster >= 0)
		promotePendingRows(usedPendings, &newMaster);
	else
		promotePendingRows(usedPendings);
	//findStructuralPendings(structures);
	
	if (newMaster > 0)
	{
		ReMasterCdWithoutUnifiedBlocks(m_cd, newMaster, true);
		vector<int> rows;
		rows.push_back(newMaster);
		m_cd->EraseTheseRows(rows);
	}
	m_cd->ResetPending();
	m_cd->EraseSequences();
}