Domanda

I have two vector make by protein pdb id such as 1A3BA, 3B5RE, 1WYX5. I want to compare if the protein list in these tow vectors are same. and what's the different? I tried to used the stl algorithms in the C++, but there is segment faults all the time! Is there anyone could tell me what's wrong..? I also do not quite sure about the sorting algorithms but anyway..No matter i put the sorting or not the code has something wrong...

vector<string> pdb_b_list;
vector<string> pdb_a_list;
vector<string> intset;
vector<string>::iterator im;

           sort(pdb_a_list.begin(),pdb_a_list.end());
           sort(pdb_b_list.begin(),pdb_a_list.end());  

         if (includes(pdb_a_list.begin(), pdb_a_list.end(), pdb_b_list.begin(), pdb_b_list.end())){
            cout << "a includes b"<<endl;
             cnt_s++;
              }

       else if (includes(pdb_b_list.begin(), pdb_b_list.end(), pdb_a_list.begin(), pdb_a_list.end()) ){
             cout <<"b includes a" <<endl;
             cnt_s++;
              }
         else      {
           cout << "different proteins  in the sets" <<endl;
           cnt_d++;
           //sort(pdb_a_list.begin(),pdb_a_list.end());
          // sort(pdb_b_list.begin(),pdb_a_list.end());
           im = set_intersection(pdb_a_list.begin(),pdb_a_list.end(),pdb_b_list.begin(),pdb_a_list.end(), intset.begin());
           cout <<" the intersetion has \t" <<int(im- intset.begin())<<"elements" <<endl;

                   }
È stato utile?

Soluzione

Have a look on how you sort your second vector:

sort(pdb_b_list.begin(),pdb_a_list.end());  

You are inserting the wrong end index, it should be pdb_**b**_list.end(), thus the segfault.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top