Ejemplo n.º 1
0
        public double GetScore(WregexResult w)
        {
            if (m_pssm.Count == 0)
            {
                return(0.0);
            }

            double score = 0.0;
            int    i, j, k, len;

            for (i = 0; i < w.Groups.Count; i++)
            {
                for (j = 0; j < m_pssm.Count && m_pssm[j].order != i; j++)
                {
                    if (m_pssm[j].order >= w.Groups.Count)
                    {
                        throw new ApplicationException("Regex and PSSM have diferent lengths");
                    }
                }
                if (j == m_pssm.Count)
                {
                    continue;
                }
                //Console.WriteLine( "DEBUG: " + w.Groups[i] + ", " + w.Groups[i].Length );
                len = w.Groups[i].Length;
                for (k = 0; k < len; k++)
                {
                    score += GetScore(m_pssm[j], AminoAcid.Get((w.Groups[i])[k]));            ///len;
                }
            }

            return(Math.Pow(10, score / w.Match.Length) * 100);
        }
Ejemplo n.º 2
0
        public List <WregexResult> Search(string seq, string id, ResultType type)
        {
            List <WregexResult> results = new List <WregexResult>();

            Match m = mRegex.Match(seq);

            if (!m.Success)
            {
                return(results);
            }

            WregexResult result;

            do
            {
                result = new WregexResult();
                //result.Id = id + "@" + m.Index;
                result.Entry        = id;
                result.Index        = m.Index;
                result.Combinations = 1;
                result.Groups       = new List <string>();
                result.Match        = m.Value;
                result.Length       = m.Length;
                if (mMaxLength == 0 || m.Length > mMaxLength)
                {
                    mMaxLength = m.Length;
                }
                if (mMinLength == 0 || m.Length < mMinLength)
                {
                    mMinLength = m.Length;
                }
                for (int i = 1; i < m.Groups.Count; i++)
                {
                    result.Groups.Add(m.Groups[i].Value);
                }
                result.Score = mPssm != null?mPssm.GetScore(result) : 0.0;

                result.Type = type;
                results.Add(result);
                m = mRegex.Match(seq, result.Index + 1);
            } while(m.Success);

            if (mGrouping)
            {
                return(Filter(results));
            }
            return(results);
        }
Ejemplo n.º 3
0
        private string GetID(List <Variant> m, WregexResult r, bool original)
        {
            string id = "";

            foreach (Variant v in m)
            {
                if ((int)v.pos >= r.Index && (int)v.pos < (r.Index + r.Length))
                {
                    if (original || r.Match[(int)v.pos - r.Index] == v.mut)
                    {
                        id += "-" + v.orig + (v.pos + 1).ToString() + v.mut;
                    }
                }
            }
            return(id);
        }
Ejemplo n.º 4
0
        private List <List <Variant> > GetMutations(Fasta seq, WregexResult r)
        {
            int i1 = 0, i2;

            while (i1 < seq.mVariants.Count && (int)seq.mVariants[i1].pos < r.Index)
            {
                i1++;
            }
            i2 = i1;
            while (i2 < seq.mVariants.Count && (int)seq.mVariants[i2].pos < (r.Index + r.Length))
            {
                i2++;
            }

            return(GetMutations(seq, i1, i2 - 1));
        }
Ejemplo n.º 5
0
        public double GetScore( WregexResult w )
        {
            if( m_pssm.Count == 0 )
            return 0.0;

            double score = 0.0;
            int i, j, k, len;
            for( i = 0; i < w.Groups.Count; i++ ) {
            for( j = 0; j < m_pssm.Count && m_pssm[j].order != i; j++ ) {
                if( m_pssm[j].order >= w.Groups.Count )
                    throw new ApplicationException( "Regex and PSSM have diferent lengths" );
            }
            if( j == m_pssm.Count )
                continue;
            //Console.WriteLine( "DEBUG: " + w.Groups[i] + ", " + w.Groups[i].Length );
            len = w.Groups[i].Length;
            for( k = 0; k < len; k++ )
                score += GetScore(m_pssm[j], AminoAcid.Get((w.Groups[i])[k]));///len;
            }

            return Math.Pow(10,score/w.Match.Length)*100;
        }
Ejemplo n.º 6
0
        private List <WregexResult> GetTotalVariantsResults(Fasta seq)
        {
            List <WregexResult> ret = new List <WregexResult>();

            WregexResult[]         orig, mut;
            bool                   found;
            int                    i, j;
            List <List <Variant> > mutations;
            string                 id;

            // Original (without mutations)
            orig = mRegex.Search(seq.mSequence, seq.ID + "-orig").ToArray();
            ret.AddRange(orig);

            // Lost
            foreach (WregexResult r in orig)
            {
                /*if( r.Entry.Contains("NP_002968.1") )
                 *      Console.WriteLine( "KK" );*/
                mutations = GetMutations(seq, r);
                foreach (List <Variant> m in mutations)
                {
                    if (GetVariantsResults(seq.ID, r.Match, r.Index, m).Count == 0)
                    {
                        WregexResult r2 = r;
                        r2.Type  = ResultType.Lost;
                        r2.Entry = r2.Entry.Replace("-orig", "-lost") + GetID(m, r, true);
                        ret.Add(r2);
                    }
                }
            }

            // Mutations
            mutations = GetMutations(seq, mRegex.MaxLength);
            mut       = GetVariantsResults(seq.ID, seq.mSequence, mutations).ToArray();
            for (i = 0; i < mut.Length; i++)
            {
                // Filter duplicates
                found = false;
                foreach (WregexResult r in ret)
                {
                    if (r.Index == mut[i].Index && r.Match.Equals(mut[i].Match))
                    {
                        found = true;
                        break;
                    }
                }
                if (found)
                {
                    continue;
                }
                // Assign names
                id = GetID(seq.mVariants, mut[i]);
                if (id.Length == 0)
                {
                    continue;
                }
                mut[i].Entry += id;
                // Gained
                found = false;
                for (j = 0; j < orig.Length; j++)
                {
                    if (mut[i].Index == orig[j].Index)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    mut[i].Type = ResultType.Gained;
                }
                ret.Add(mut[i]);
            }

            return(ret.Count == 0 ? null : ret);
        }
Ejemplo n.º 7
0
 private string GetID(List <Variant> m, WregexResult r)
 {
     return(GetID(m, r, false));
 }
Ejemplo n.º 8
0
        public List<WregexResult> Search( string seq, string id, ResultType type )
        {
            List<WregexResult> results = new List<WregexResult>();

            Match m = mRegex.Match(seq);
            if( !m.Success )
            return results;

            WregexResult result;
            do {
            result = new WregexResult();
            //result.Id = id + "@" + m.Index;
            result.Entry = id;
            result.Index = m.Index;
            result.Combinations = 1;
            result.Groups = new List<string>();
            result.Match = m.Value;
            result.Length = m.Length;
            if( mMaxLength == 0 || m.Length > mMaxLength )
                mMaxLength = m.Length;
            if( mMinLength == 0 || m.Length < mMinLength )
                mMinLength = m.Length;
            for( int i = 1; i < m.Groups.Count; i++ )
                result.Groups.Add( m.Groups[i].Value );
            result.Score = mPssm != null ? mPssm.GetScore(result) : 0.0;
            result.Type = type;
            results.Add( result );
            m = mRegex.Match( seq, result.Index + 1 );
            } while( m.Success );

            if( mGrouping )
            return Filter(results);
            return results;
        }
Ejemplo n.º 9
0
        private List<List<Variant>> GetMutations( Fasta seq, WregexResult r )
        {
            int i1 = 0, i2;

            while( i1 < seq.mVariants.Count && (int)seq.mVariants[i1].pos < r.Index )
            i1++;
            i2 = i1;
            while( i2 < seq.mVariants.Count && (int)seq.mVariants[i2].pos < (r.Index+r.Length) )
            i2++;

            return GetMutations( seq, i1, i2-1 );
        }
Ejemplo n.º 10
0
 private string GetID( List<Variant> m, WregexResult r, bool original )
 {
     string id = "";
     foreach( Variant v in m )
     if( (int)v.pos >= r.Index && (int)v.pos < (r.Index+r.Length) )
         if( original || r.Match[(int)v.pos-r.Index] == v.mut )
             id += "-" + v.orig + (v.pos+1).ToString() + v.mut;
     return id;
 }
Ejemplo n.º 11
0
 private string GetID( List<Variant> m, WregexResult r )
 {
     return GetID( m, r, false );
 }