Thread: Need function to evaluate sequence content

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    77

    Need function to evaluate sequence content

    Hello to all,

    I am relatively new to programming and not fluent with the built-in functions. I am looking for a function that will evaluate a string of characters. The strings that will be evaluated will have different content based on their origin. To be more specific, I need to know the if the sequence is DNA (contains A C G T ), RNA ( A C G U ), protein (20 amino acid notations) or other.

    Any help would be great.

  2. #2
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Easiest for the first two would just be nested if statements with something like strchr()

    See http://cppreference.com/stdstring/index.html for more functions.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    77
    Could anyone give me some help on how to set that up?

  4. #4
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Something like(Code isn't tested):

    Code:
    char string[] = "gtac";  // To check
    char dna[]   = "acgt";   // Characters that DNA can/must have(?)
    int i;
    
    for(i = 0; i < strlen(dna); i++)
         if(strchr(string, dna[i]) == NULL) break;
    
    if(i != strlen(dna)) 
    {
         // String was not DNA, do something
    }

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    77
    how would i set it up so that if the sequence evaluates to DNA,
    the variable "loadedSequences[nSequences].type" is set to DNA
    and likewise for RNA and PROTEIN?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Something like this perhaps?
    Code:
    static const char dna[] = "acgt";
    static const char rna[] = "acgu";
    static const char protein[] = "aehtrvw";    // whatever. 
    
    int check_valid(char *str, int type)   // int may actually be an enum
    {
       char *match;
       switch(type)
       { 
          case DNA: 
             match = dna;
             break;
          case RNA:
             match = rna;
             break;
          case PROTEIN:
             match = protein;
             break;
          default:
             // do something sensible here - whatever that may be. 
             // return or exit
             break;
        }
        // Now check that all elements in "str" are in "match". 
        ...
    }
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM