0

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;

                   }
user1830108
  • 195
  • 1
  • 15

1 Answers1

3

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.

amit
  • 175,853
  • 27
  • 231
  • 333
  • And I think the Microsoft C++ libraries will yell about comparing iterators from different objects if you compile in Debug mode. – Zan Lynx Dec 10 '12 at 17:11
  • OK..but after fix the a/b issue ...it looks like my intersetion would be always be 0/...so I added one more commends that iaa = set_difference (pdb_a_list.begin(),pdb_a_list.end(),pdb_b_list.begin(), pdb_b_list.end(), diffset.begin()); cout <<" the difference part has \t" << int(iaa - diffset.begin())<<"\t elements"< – user1830108 Dec 10 '12 at 17:45