Esempio n. 1
0
void Chain::turnover ()
{
	stack<Part*> stack_part;
	const int numparts = listOfParts.size ();

	for (int i=0; i < numparts; i++)
	{
		Part* p = listOfParts[i];
		stack_part.push (p);

		if (p->getPartType () == "ForwardDNA") 
			p->setPartType ("ReverseDNA");
		else if (p->getPartType () == "ReverseDNA") 
			p->setPartType ("ForwardDNA");
	}

	listOfParts.clear ();

	for (int i=0; i < numparts; i++) {
		listOfParts.push_back (stack_part.top ());	
		stack_part.pop ();
	}

	//	reset unicode
	unicode = genUnicode (0, listOfParts.size ()-1, true);
}
Esempio n. 2
0
void Chain::__add_chain_prefix (
		const string& prefix
		)
{
	for (int i=0; i<listOfParts.size (); i++) {
		Part* p = listOfParts[i]; 
		p->partLabel = prefix + p->partLabel;
	}
	genUnicode (0, listOfParts.size ()-1, true);
}
Esempio n. 3
0
bool Chain::isCsymm ()
{
	//	is this chain a DNA chain?
	this->setIsDNA ();

	//	is this chain a RNA chain?
	this->setIsRNA ();

	//	yes
	if (isDNA)
	{
		string fw_unicode = genUnicode (0, listOfParts.size ()-1, true);
		string rev_unicode = genUnicode (0, listOfParts.size ()-1, false);
		if (rev_unicode < fw_unicode) {turnover (); unicode = rev_unicode; return false;}
		else if (rev_unicode > fw_unicode) {unicode = fw_unicode; return false;}
		else {unicode = fw_unicode; return true;}
	}
	else
	{
		unicode = genUnicode (0, listOfParts.size ()-1, true);
		return false;
	}
}
Esempio n. 4
0
bool Chain::match (
    const Chain* c,
    vector<cMatchType>& xyz
) const
{

//
//	find parts of non-substituent type
//
    vector<markType> ns_t;
    vector<cMatchType> asmb;

    bool start = true;
    int numParts = c->listOfParts.size ();
    for (int cnt =0; cnt < listOfParts.size (); cnt++)
    {
        Part* p = listOfParts[cnt];
        string ctg = p->getPartCategory ();
        if (ctg != "substituent")
        {
            if (start)
            {
                ns_t.push_back (make_pair (cnt, 0));
                start = false;
            }
        }
        else
        {
            ns_t.back ().second = cnt-1;
            start = true;
        }
    }

    if (ns_t.size () > 0)
    {
        vector< markType >* m_pos =
            new vector< markType > [ns_t.size ()];

        //
        //	for each non-substituent part, find its possible
        //	matching points in this chain
        //
        int permAll = 0;
        for (int cnt =0; cnt < ns_t.size (); cnt++)
        {
            int start = ns_t[cnt].first;
            int end = ns_t[cnt].second;
            int diff = end-start;

            Part* ps = listOfParts[start];
            Part* pe = listOfParts[end];

            string mkey = genUnicode (ps, pe);

            for (string::size_type pos = 0;
                    (pos = unicode.find_first_of (mkey, pos))
                    != string::npos; pos++)
            {
                int spos = count (unicode.begin (), unicode.begin ()+pos, ']');
                int epos = spos + diff;

                m_pos[cnt].push_back (make_pair (spos, epos));
            }

            if (m_pos[cnt].size () == 0)
            {
                delete [] m_pos;
                return 0;
            }
            else permAll *= m_pos[cnt].size ();
        }

        //
        //	find possible matching combinations
        //
        for (int i =0; i < permAll; i++)
        {
            int lastp = -1;
            cMatchType tmp;

            int divide = i;
            for (int j=0; j< ns_t.size (); j++)
            {
                markType p = m_pos[j][divide % m_pos[j].size ()];
                if (p.first <= lastp)
                {
                    tmp.clear ();
                    break;
                }
                else
                {
                    lastp = p.second;
                    tmp.push_back (p);
                }
                divide /= m_pos[j].size ();
            }

            assert (tmp.size () == ns_t.size ());
            if (!tmp.empty ()) asmb.push_back (tmp);
        }

        delete [] m_pos;
    }

//
//	insert substituent pieces into asmb
//
    for (int cnt =0; cnt < asmb.size (); cnt++)
    {
        int lastf1, lastf2;
        lastf1 = lastf2 = 0;
        bool found = true;

        //
        //	*it ==> pair<int,int>
        //
        vector<cMatchType> pm;
        cMatchType::const_iterator it = asmb[cnt].begin ();

        vector<cMatchType> tmp;
        bool mok = substituent_m (
                       0, ns_t[0].first-1, 0, it->first-1, c, tmp
                   );
        if (mok)
        {
            for (int i = 0; i < tmp.size (); i++)
                pm.push_back (tmp[i]);
        }
        else continue;

        //
        for (int cnt2 =0; cnt2 < ns_t.size (); cnt2++, it++)
        {
            int start1 = ns_t[cnt2].first;
            int end1 = ns_t[cnt2].second;

            int start2 = it->first;
            int end2 = it->second;

            //
            //  add non-substituent type matching
            //
            for (int cnt3 =0; cnt3 < pm.size (); cnt3++)
            {
                for (int k =start2; k <= end2; k++)
                    pm[cnt3].push_back (make_pair (k,k));
            }

            //
            //  add substituent type matching
            //
            bool mok = substituent_m (
                           lastf1, start1-1, lastf2, start2-1, c, tmp
                       );
            if (mok)
            {
                vector<cMatchType>::iterator iter = pm.begin ();

                int k = -1;
                int currsize = pm.size ();
                while (++k < currsize)
                {
                    cMatchType tmp1 = pm[k];
                    pm.erase (iter + k);

                    //  tmp ==> vector<cMatchType>
                    for (int i =0; i < tmp.size (); i++)
                    {
                        cMatchType tmp2 = tmp1;
                        tmp2.insert (tmp2.end (), tmp[i].begin (), tmp[i].end ());
                        pm.push_back (tmp2);
                    }
                }
            }
            else
            {
                found = false;
                break;
            }

            //
            //  update
            //
            lastf1 = end1+1;
            lastf2 = end2+1;
        }

        if (!found) continue;
        else
        {
            for (int i =0; i < pm.size (); i++)
                xyz.push_back (pm[cnt]);
        }
    }

    if (xyz.empty ()) return false;
    return true;
}