Protocol Online logo
Top : Forum Archives: : Bioinformatics and Biostatistics

FOR C++ EXPERTS - need your help (Jan/06/2007 )

Pages: Previous 1 2 3 4 Next

Looks o.k. Where you try to determine the sequence length - I think you have another pointless for loop. I am almost sure that in c/c++ there is a method belogning to arrays that allows you to get the length.

array.length or array.size.


sorry if this makes no sense - r there are typos as iu forgot my glasses today so can' look at the screen!!!!

I found my glasses under the monitor!!!

array.length() should do.... just going to check that!

I am also going to be a complete pain and suggest that rather than using the arrays you use vectors instead - this means you won't get an out of bounds error when someone puts in too many characters.

CODE
int arr[10];
cout << sizeof(arr)/sizeof(int);

sizeof(arr) - returns the size in bytes off the entire array.
sizeof(int) - returns the number of bytes required for one element of the array.
Thus dividing gives the number of elements.

-perlmunky-

hi perlmunky, i welcome your comments smile.gif
array.length .......mmm....this belongs to structures i think, right!!? glare.gif

-strawberry-

QUOTE (strawberry @ Jan 15 2007, 08:19 AM)
hi perlmunky, i welcome your comments smile.gif
array.length .......mmm....this belongs to structures i think, right!!? glare.gif

errm too many languages floating around in my head.... ignore that unless you want to do java!!!!
The best way is to use the sizeof method i showed above.

Not sure about structures!!!!!! ermm I am trying to setup my new linux box at the moment (currently trying a new (to me) c editor called anjuta) - looks good!
The only reason I am doing this is becasuse eclipse is being an arse.

length belongs to the string class - my bad...

blink.gif blink.gif blink.gif blink.gif blink.gif blink.gif blink.gif blink.gif blink.gif

-perlmunky-

Already exists a program like that.
If you want to use it you can download it from here.



Description: This freeware tool will show the proportions between nucleotides in a DNA sequence.
How to use it: Start the program, and then paste your DNA sequence from the clipboard into the program. Press the ‘Start’ button. It will show you the proportion between AT and CG bases.

-fedra-

Perhaps you should read the entire thread before posting. The objective here was to solve a problem and learn how to program not just use existing code. There are hundreds of programs to do this type of stuff, specifically the EMBOSS package - you could even use the ?harvard? scriptome project. It was/is simply a starting point for learning c/c++.

-perlmunky-

thanx fedra, appreciate your help
but as perlmunky said, i want to learn and practice this language smile.gif

-strawberry-

hi, i'm trying to find the %homology of a sequence
check this simple program, what's wrong with it! unsure.gif

CODE
#include<iostream.h>
void homology(char dna1[],char dna2[],int j)
{
    
    int count=0;
    for(int i=0;i<=j;i++)
    {
        if(dna1[i]==dna2[i]){
        
        cout<<dna2[i];
        count++;}
        else
            cout<<" ";
    }
    cout<<"%homology= "<<(count/100)*j<<endl;
}

int main()
{
    char seq1[10],seq2[10];
    int size=10;

    cout<<"sequence1: "<<endl;
    cin>>seq1;
    cout<<"sequence2: "<<endl;
    cin>>seq2;

    homology( seq1, seq2,size);
    

    return 0;
}

-strawberry-

You tell me. What errors are you getting? What on earth does your forum post tag mean?

-perlmunky-

i'll keep trying smile.gif

-strawberry-

I think what we should be doing here is using vectors.

The advantage of using vectors here is that we can happily insert data from cin without having to worry about an array out of bounds error at run-time. This means you will need to rewrite your code. This includes a new way of getting data from the user - hint use a while(1) loop and a break with cin.eof() & break;
If you create this as a method you call it twice to populate your vectors (seqA, seqB). As you are using vectors you can apply the size() method (seqA.size()) ... you then have the option of not doing homology if the sequences don't match in length or maybe matching bar the smallest or doing some double dynamic programming and aligning the sequences yourself!!!!!

-perlmunky-

Pages: Previous 1 2 3 4 Next