CReating a mass output of files from one file

I need a function to add into my program that will create a a mass output of files.  Meaning if one file is in csv format and says:

,,zulu,A*30101,A*0101,,,,,
,,finn 90, A*1010, A*0101,,,,

and the second file is

>word A*30101
sdasdas
>word A*1010
wewew
>word A*0101
3423242

the output files would be

Zulu
>A*30101
sdasdas
>A*0101
3423242

Finn 90
>A*1010
wewew
>A*0101
3423242

those twow ould be seperate outfiles with the header being the file name

ettt6Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
Well, we had that in your last Q:

void Process ( string sPopulation, char* pszFastaFile, char* pszResult, bool bRemoveDuplicates) {
  string sPop;
 
 list<string> lstTypes;
 map<string,string> mapProteins;

 ExtractHaplotypesForPopulation ( "mhc.csv", sPopulation, lstTypes);

 if (bRemoveDuplicates) RemoveDuplicates (lstTypes);

 ReadProteins ( pszFastaFile, mapProteins);

 AssociateProteinsWithHaplotypes ( pszResult, sPop, lstTypes, mapProteins);

}

The idea was to use it like

Process("Zulu", "2nd_file_1.fasta", "result1.txt", true);
Process("Finn 90", "2nd_file_2.fasta", "result1.txt", true);

ettt6Author Commented:
is there a way it will automaitcally take the population name out of column 3 and associate it with a file, rather than specifying it myself?
jkrCommented:
Sure. If that also is 'mhc.csv, you could

string ExtractField ( unsigned int unRow, const string& sLine) {

 // find 'unRow' column

 string sField = "";

 int nPos = 0;
 int nCount = 0;

 while ( nCount < (unRow - 1)) { // 'unRow row' means 'unRow - 1 commas'

     nPos = sLine.find(',',nPos);

     if ( -1 == nPos) return sField; // assume 'no match' if there is no such column

     ++nPos; ++nCount;
 }

 // find next delimiting comma

 if ( nPos >= sLine.size()) return string("");

 int nEnd = sLine.find(',',nPos);

 if ( -1 == nEnd) return false; // assume 'no match' if there is no following comma

 sField = sLine.substr(nPos, nEnd - nPos);

 return sField;
}

void ReadPopulations(const char* pszPopulationFileName, list<string>& lstPopulations) {

 ifstream is (pszPopulationFileName);

 string strLine;
 string strField;

 if (!is.is_open()) {

     cout << "Could not open input file" << endl;

     return;
 }

 while (!is.eof()) {

     getline(is,strLine);

     strField = ExtractField ( 3, strLine);

     if (!strField.empty()) lstPolupations.push_back(sField);
 }
}

//...

list<string> lstPopulations;
list<string>::iterator i;

ReadPopulations("mhc.csv", lstPopulations);

for (i = lstPopulations.begin(); i != lstPopulations.end(); ++i) {

string strResult = string("result_") + *i + string(".txt");

    Process(*i, "file.fasta", strResult.c_str(), true);
}

which will create files called 'result_<population>.txt' for each entry does the fasta file's name change also?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

ettt6Author Commented:
no the fasta file stays the same it will always be hla_nuc.fasta
ettt6Author Commented:
no the fasta file stays the same it will always be hla_nuc.fasta

also what do the //.. mean?
jkrCommented:
//...

should just illustrate that there's other code between the functions and the snippet that shows how to use them. If the file name stays teh same, just hard-code it, e.g.

    Process(*i, "hla_nuc.fasta", strResult.c_str(), true);

ettt6Author Commented:
use the same code from the program we just made, or use the code from above with the void process function
jkrCommented:
Well, the process function can go in your program 'as is'. Then, you need or probably want to add a 'case' to your 'switch' that calls that, e.g. like

case 1:
   {
   lstTypes.clear();
   mapProteins.clear();
   GetPopulation(sPop);
   Process(sPop, "hla_nuc.fasta", strResult.c_str(), false);
   break; // <-------

   break; // <-------
   }
case 2:
   {
   lstTypes.clear();
   mapProteins.clear();
   GetPopulation(sPop);
   Process(sPop, "hla_nuc.fasta", strResult.c_str(), true);
   break; // <-------

   }
case 3:
   {
   lstTypes.clear();
   list<string> lstPopulations;
   list<string>::iterator i;

   ReadPopulations("mhc.csv", lstPopulations);

   for (i = lstPopulations.begin(); i != lstPopulations.end(); ++i) {

      string strResult = string("result_") + *i + string(".txt");

      Process(*i, "hla_nuc.fasta", strResult.c_str(), true);
   }
   break; // <-------

   }
ettt6Author Commented:
this here is what i used however i got errors with the 'process' call line in the switch function amongst other things

#include <iostream>
#include <fstream>
#include <string>
#include <list>
#include <map>
using namespace std;

void ExtractHaplotypesForPopulation(const char* pszHaplotypeFileName, const string& sPop, list<string>& lstResult);
void ReadProteins(const char* pszProteinFileName, map<string,string>& mapProteins);
void AssociateProteinsWithHaplotypes(const char* pszFileName, string sPop, list<string>& lstTypes, map<string,string>& mapProteins);
void RemoveDuplicates (list<string>& lstTypes);
void Process ( string sPopulation, char* pszFastaFile, char* pszResult, bool bRemoveDuplicates);
void ReadPopulations(const char* pszPopulationFileName, list<string>& lstPopulations);


string ExtractField ( unsigned int unRow, const string& sLine) {

  // find 'unRow' column

  string sField = "";

  int nPos = 0;
  int nCount = 0;

  while ( nCount < (unRow - 1)) { // 'unRow row' means 'unRow - 1 commas'

      nPos = sLine.find(',',nPos);

      if ( -1 == nPos) return sField; // assume 'no match' if there is no such column

      ++nPos; ++nCount;
  }

  // find next delimiting comma

  if ( nPos >= sLine.size()) return false;

  int nEnd = sLine.find(',',nPos);

  if ( -1 == nEnd) return false; // assume 'no match' if there is no following comma

  sField = sLine.substr(nPos, nEnd - nPos);

  return sField;
}

void ReadPopulations(const char* pszPopulationFileName, list<string>& lstPopulations) {

 ifstream is (pszPopulationFileName);

 string strLine;
 string strField;

 if (!is.is_open()) {

     cout << "Could not open input file" << endl;

     return;
 }

 while (!is.eof()) {

     getline(is,strLine);

     strField = ExtractField ( 3, strLine);

     if (!strField.empty()) lstPolupations.push_back(sField);
 }
}

void Process ( string sPopulation, char* pszFastaFile, char* pszResult, bool bRemoveDuplicates) {
  string sPop;
 
 list<string> lstTypes;
 map<string,string> mapProteins;

 ExtractHaplotypesForPopulation ( "mhc.csv", sPopulation, lstTypes);

 if (bRemoveDuplicates) RemoveDuplicates (lstTypes);

 ReadProteins ( pszFastaFile, mapProteins);

 AssociateProteinsWithHaplotypes ( pszResult, sPop, lstTypes, mapProteins);

}

string GetPopulation(string& sPop)
{
   char* apszPopulations[] = {"Algerian 99","American Samoa","AmerIndian","Ami 97","Arab Durze","Atayal","Bari","Brazilian","Brazilian (Af Eu)","Bulgarian","Bunun","Burait","Cape York","Chaouya","Croatian","Cuban (Af Eu)","Cuban (Eu)","Czech","Doggon","Filipino","Finn 90","Georgian","Groote Eylandt","Guarani-Kaiowa","Guarani-Nandewa","Hakka","Han-Chinese 149","Han Chinese 572","Irish","Israeli Jews","Ivantan","Kenyan 142","Kenyan Highlander","Kenyan Lowlander","Kimberley","Korean 200","Kurdish","Malay","Mandenka","Metalsa","Mexican","Minnan","North America (Af)","North America (As)","North America (Eu)","North American (Hi)","Okinawan","Omani","Paiwan 51","Pazeh","Puyuma 49","Rukai","Ryukuan","Saisiat","Seri","Shona","Singapore","Siraya","Thai","Thao","Toroko","Tsou","Tuva","Ugandan","Yami","Yuendumu","Yupik","Zambian","Zulu", NULL};
   
    bool bFound =false;


   while(!bFound){
        cout<<"What is the name of the population you want to search for?"<<endl;
        cout<<"The search is case sensitive and you have to press enter twice."<<endl;
        cin >> sPop;

        for (int i=0; apszPopulations[i] !=NULL; ++i){
             if (!sPop.compare(apszPopulations[i])){bFound = true; break;}
        }
       
    }
   return sPop;
}
void ExtractHaplotypesForPopulation(const char* pszHaplotypeFileName, const string& sPop, list<string>& lstResult)
{
      static int anFields[] = { 3,4,6,7,9,10,12,13,15,16,18,19, -1}; // TEST - remove the 1st -1

 ifstream is (pszHaplotypeFileName);

 string sLine;

 if (!is.is_open()) {

     cout << "Could not open input file " << pszHaplotypeFileName << endl;

     return;
 }

 while (!is.eof()) {

     getline(is,sLine);

 //    cout << "RAW " << sLine << endl;

     string sField = ExtractField (3,sLine);

     if (sField == sPop) {

         for ( int i = 0; anFields[i] > 0; ++i) {

             sField = ExtractField (anFields[i] + 2,sLine);

  //           cout << "    found " << sField << endl;

             while ( ' ' == sField[0]) sField.erase(0,1); // remove whitespace

             if (sField.size()) lstResult.push_back(sField);
         }
     }
 }
}

void RemoveDuplicates (list<string>& lstTypes){

map<string,string> tmp;
map<string,string>::iterator im;
list<string>::iterator il;

  for ( il = lstTypes.begin(); il != lstTypes.end(); ++il) {

     tmp.insert(map<string,string>::value_type(*il,*il));
  }

  lstTypes.clear();

   for (im = tmp.begin(); tmp.end() != im; ++im) lstTypes.push_back(im->first);

     

}

void ReadProteins(const char* pszProteinFileName, map<string,string>& mapProteins) {

  ifstream is (pszProteinFileName);

  string strLine;
  string strData;
  string strType;

  if (!is.is_open()) {

      cout << "Could not open input file" << endl;

      return;
  }

  while (!is.eof()) {

      int nPos;

      getline(is,strLine);
//       cout << "RAW " << strLine << endl;

      if ( strLine[0] == '>') {

          nPos = strLine.find(' ');

          if ( -1 == nPos) continue;

          strType = strLine.substr(nPos + 1);

//            cout << " found " << strType << endl;

      getline(is,strData);

          while ( '>' != (char) is.peek() && !is.eof()) {

                getline(is,strLine);
             //   cout << "    data " << strLine << endl;

                strData += strLine;
          }

   //       cout << "  adding " << strData << endl;;

          mapProteins.insert(map<string,string>::value_type(strType,strData));
          strData.erase(); // start out with a fresh buffer

      }
  }
}
void AssociateProteinsWithHaplotypes(const char* pszFileName, string sPop, list<string>& lstTypes, map<string,string>& mapProteins) {

  ofstream os (pszFileName);

  string strLine;
  string strData;
  string strType;

  if (!os.is_open()) {

      cout << "Could not open output file" << endl;

      return;
  }

  os << sPop << endl;

  list<string>::iterator il;

  for ( il = lstTypes.begin(); il != lstTypes.end(); ++il) {

      cout << "   looking up " << *il << endl;
      map<string,string>::iterator im = mapProteins.find(*il);

      if ( mapProteins.end() != im) {

          os << ">" << im->first << endl << im->second << endl;
          cout << "      found entry: " << im->first << endl;
       }
  }

  map<string,string>::iterator im;

  cout << " We searched the following entries: " << endl;
  for (im = mapProteins.begin(); mapProteins.end() != im; ++im)
          cout << "  " << im->first << endl;

}

int main () {
   string sPop;
   
   list<string> lstTypes;
  map<string,string> mapProteins;

      cout<<"Available Populations:"<<endl;
    cout<<" "<<endl;
    cout<<"Algerian 99,         American Samoa,          AmerIndian,               Ami 97"<<endl;
    cout<<"Arab Durze,            Atayal,                   Bari,                    Brazilian"<<endl;
    cout<<"Brazilian (Af Eu),   Bulgarian,          Bunun,                    Burait"<<endl;
    cout<<"Cape York,            Chaouya,          Croatian,               Cuban (Af Eu)"<<endl;
    cout<<"Cuban (Eu),            Czech,               Doggon,                    Filipino"<<endl;
    cout<<"Finn 90,                  Georgian,          Groote Eylandt,               Guarani-Kaiowa"<<endl;
    cout<<"Guarani-Nandewa,     Hakka,               Han-Chinese 149               Han Chinese 572"<<endl;
    cout<<"Irish,                  Israeli Jews,          Ivantan,               Kenyan 142"<<endl;
    cout<<"Kenyan Highlander,   Kenyan Lowlander,     Kimberley,               Korean 200"<<endl;
    cout<<"Kurdish,                  Malay,               Mandenka,               Metalsa"<<endl;
    cout<<"Mexican,            Minnan               North America (Af)          North America (As)"<<endl;
    cout<<"North America (Eu),  North American (Hi),     Okinawan,               Omani"<<endl;
    cout<<"Paiwan 51,            Pazeh,               Puyuma 49,               Rukai"<<endl;
    cout<<"Ryukuan,                  Saisiat,          Seri,                    Shona"<<endl;
    cout<<"Singapore,            Siraya,               Thai,                    Thao"<<endl;
    cout<<"Toroko,           Tsou,               Tuva,                    Ugandan"<<endl;
    cout<<"Yami,                  Yuendumu,           Yupik,                    Zambian"<<endl;
    cout<<"Zulu"<<endl;
int choice;
cout<<"Below are your menu choices:"<<endl;
cout<<"[1] Show individual populations with frequency"<<endl;
cout<<"[2] Show individual populations without the frequency"<<endl;
cout<<"[3] Print out all populations with their alleles"<<endl;
cin>>choice;

switch(choice)
{
case 1:
    {
    GetPopulation(sPop);
      ExtractHaplotypesForPopulation ( "mhc.csv", sPop, lstTypes);
    ReadProteins ( "hla_nuc.fasta", mapProteins);
    AssociateProteinsWithHaplotypes ( "result.txt", sPop, lstTypes, mapProteins);
    break;
      }
      
case 2:
    {
    lstTypes.clear();
      mapProteins.clear();
      GetPopulation(sPop);
    ExtractHaplotypesForPopulation ( "mhc.csv", sPop, lstTypes);
    ReadProteins ( "hla_nuc.fasta", mapProteins);
      RemoveDuplicates (lstTypes);
    AssociateProteinsWithHaplotypes ( "resultfre.txt", sPop, lstTypes, mapProteins);
      break;
    }
case 3:
    {
      lstTypes.clear();
   list<string> lstPopulations;
   list<string>::iterator i;

   ReadPopulations("mhc.csv", lstPopulations);

   for (i = lstPopulations.begin(); i != lstPopulations.end(); ++i) {

      string strResult = string("result_") + *i + string(".txt");

      Process(*i, "hla_nuc.fasta", strResult.c_str(), true);
   }
   break; // <-------

      break;
    }
default:
         cout << "Invalid Menu choice.  Please make another selection." << endl;
   
    return 0;
}
}

jkrCommented:
Well, mostly typos :o)

#include <iostream>
#include <fstream>
#include <string>
#include <list>
#include <map>
using namespace std;

void ExtractHaplotypesForPopulation(const char* pszHaplotypeFileName, const string& sPop, list<string>& lstResult);
void ReadProteins(const char* pszProteinFileName, map<string,string>& mapProteins);
void AssociateProteinsWithHaplotypes(const char* pszFileName, string sPop, list<string>& lstTypes, map<string,string>& mapProteins);
void RemoveDuplicates (list<string>& lstTypes);
void Process ( string sPopulation, const char* pszFastaFile, const char* pszResult, bool bRemoveDuplicates);
void ReadPopulations(const char* pszPopulationFileName, list<string>& lstPopulations);


string ExtractField ( unsigned int unRow, const string& sLine) {

 // find 'unRow' column

 string sField = "";

 int nPos = 0;
 int nCount = 0;

 while ( nCount < (unRow - 1)) { // 'unRow row' means 'unRow - 1 commas'

     nPos = sLine.find(',',nPos);

     if ( -1 == nPos) return sField; // assume 'no match' if there is no such column

     ++nPos; ++nCount;
 }

 // find next delimiting comma

 if ( nPos >= sLine.size()) return sField;

 int nEnd = sLine.find(',',nPos);

 if ( -1 == nEnd) return false; // assume 'no match' if there is no following comma

 sField = sLine.substr(nPos, nEnd - nPos);

 return sField;
}

void ReadPopulations(const char* pszPopulationFileName, list<string>& lstPopulations) {

ifstream is (pszPopulationFileName);

string strLine;
string strField;

if (!is.is_open()) {

    cout << "Could not open input file" << endl;

    return;
}

while (!is.eof()) {

    getline(is,strLine);

    strField = ExtractField ( 3, strLine);

    if (!strField.empty()) lstPopulations.push_back(strField);
}
}

void Process ( string sPopulation, const char* pszFastaFile, const char* pszResult, bool bRemoveDuplicates) {
 string sPop;

 list<string> lstTypes;
map<string,string> mapProteins;

ExtractHaplotypesForPopulation ( "mhc.csv", sPopulation, lstTypes);

if (bRemoveDuplicates) RemoveDuplicates (lstTypes);

ReadProteins ( pszFastaFile, mapProteins);

AssociateProteinsWithHaplotypes ( pszResult, sPop, lstTypes, mapProteins);

}

string GetPopulation(string& sPop)
{
  char* apszPopulations[] = {"Algerian 99","American Samoa","AmerIndian","Ami 97","Arab Durze","Atayal","Bari","Brazilian","Brazilian (Af Eu)","Bulgarian","Bunun","Burait","Cape York","Chaouya","Croatian","Cuban (Af Eu)","Cuban (Eu)","Czech","Doggon","Filipino","Finn 90","Georgian","Groote Eylandt","Guarani-Kaiowa","Guarani-Nandewa","Hakka","Han-Chinese 149","Han Chinese 572","Irish","Israeli Jews","Ivantan","Kenyan 142","Kenyan Highlander","Kenyan Lowlander","Kimberley","Korean 200","Kurdish","Malay","Mandenka","Metalsa","Mexican","Minnan","North America (Af)","North America (As)","North America (Eu)","North American (Hi)","Okinawan","Omani","Paiwan 51","Pazeh","Puyuma 49","Rukai","Ryukuan","Saisiat","Seri","Shona","Singapore","Siraya","Thai","Thao","Toroko","Tsou","Tuva","Ugandan","Yami","Yuendumu","Yupik","Zambian","Zulu", NULL};
 
    bool bFound =false;


  while(!bFound){
       cout<<"What is the name of the population you want to search for?"<<endl;
       cout<<"The search is case sensitive and you have to press enter twice."<<endl;
       cin >> sPop;

       for (int i=0; apszPopulations[i] !=NULL; ++i){
            if (!sPop.compare(apszPopulations[i])){bFound = true; break;}
       }
     
    }
  return sPop;
}
void ExtractHaplotypesForPopulation(const char* pszHaplotypeFileName, const string& sPop, list<string>& lstResult)
{
    static int anFields[] = { 3,4,6,7,9,10,12,13,15,16,18,19, -1}; // TEST - remove the 1st -1

ifstream is (pszHaplotypeFileName);

string sLine;

if (!is.is_open()) {

    cout << "Could not open input file " << pszHaplotypeFileName << endl;

    return;
}

while (!is.eof()) {

    getline(is,sLine);

//    cout << "RAW " << sLine << endl;

    string sField = ExtractField (3,sLine);

    if (sField == sPop) {

        for ( int i = 0; anFields[i] > 0; ++i) {

            sField = ExtractField (anFields[i] + 2,sLine);

 //           cout << "    found " << sField << endl;

            while ( ' ' == sField[0]) sField.erase(0,1); // remove whitespace

            if (sField.size()) lstResult.push_back(sField);
        }
    }
}
}

void RemoveDuplicates (list<string>& lstTypes){

map<string,string> tmp;
map<string,string>::iterator im;
list<string>::iterator il;

 for ( il = lstTypes.begin(); il != lstTypes.end(); ++il) {

    tmp.insert(map<string,string>::value_type(*il,*il));
 }

 lstTypes.clear();

  for (im = tmp.begin(); tmp.end() != im; ++im) lstTypes.push_back(im->first);

   

}

void ReadProteins(const char* pszProteinFileName, map<string,string>& mapProteins) {

 ifstream is (pszProteinFileName);

 string strLine;
 string strData;
 string strType;

 if (!is.is_open()) {

     cout << "Could not open input file" << endl;

     return;
 }

 while (!is.eof()) {

     int nPos;

     getline(is,strLine);
//       cout << "RAW " << strLine << endl;

     if ( strLine[0] == '>') {

         nPos = strLine.find(' ');

         if ( -1 == nPos) continue;

         strType = strLine.substr(nPos + 1);

//            cout << " found " << strType << endl;

     getline(is,strData);

         while ( '>' != (char) is.peek() && !is.eof()) {

               getline(is,strLine);
            //   cout << "    data " << strLine << endl;

               strData += strLine;
         }

  //       cout << "  adding " << strData << endl;;

         mapProteins.insert(map<string,string>::value_type(strType,strData));
         strData.erase(); // start out with a fresh buffer

     }
 }
}
void AssociateProteinsWithHaplotypes(const char* pszFileName, string sPop, list<string>& lstTypes, map<string,string>& mapProteins) {

 ofstream os (pszFileName);

 string strLine;
 string strData;
 string strType;

 if (!os.is_open()) {

     cout << "Could not open output file" << endl;

     return;
 }

 os << sPop << endl;

 list<string>::iterator il;

 for ( il = lstTypes.begin(); il != lstTypes.end(); ++il) {

     cout << "   looking up " << *il << endl;
     map<string,string>::iterator im = mapProteins.find(*il);

     if ( mapProteins.end() != im) {

         os << ">" << im->first << endl << im->second << endl;
         cout << "      found entry: " << im->first << endl;
      }
 }

 map<string,string>::iterator im;

 cout << " We searched the following entries: " << endl;
 for (im = mapProteins.begin(); mapProteins.end() != im; ++im)
         cout << "  " << im->first << endl;

}

int main () {
  string sPop;
 
   list<string> lstTypes;
 map<string,string> mapProteins;

    cout<<"Available Populations:"<<endl;
   cout<<" "<<endl;
   cout<<"Algerian 99,         American Samoa,          AmerIndian,               Ami 97"<<endl;
   cout<<"Arab Durze,          Atayal,                  Bari,                    Brazilian"<<endl;
   cout<<"Brazilian (Af Eu),   Bulgarian,          Bunun,                    Burait"<<endl;
   cout<<"Cape York,          Chaouya,          Croatian,               Cuban (Af Eu)"<<endl;
   cout<<"Cuban (Eu),          Czech,               Doggon,                    Filipino"<<endl;
   cout<<"Finn 90,               Georgian,          Groote Eylandt,               Guarani-Kaiowa"<<endl;
   cout<<"Guarani-Nandewa,     Hakka,               Han-Chinese 149               Han Chinese 572"<<endl;
   cout<<"Irish,               Israeli Jews,          Ivantan,               Kenyan 142"<<endl;
   cout<<"Kenyan Highlander,   Kenyan Lowlander,     Kimberley,               Korean 200"<<endl;
   cout<<"Kurdish,               Malay,               Mandenka,               Metalsa"<<endl;
   cout<<"Mexican,            Minnan               North America (Af)          North America (As)"<<endl;
   cout<<"North America (Eu),  North American (Hi),     Okinawan,               Omani"<<endl;
   cout<<"Paiwan 51,          Pazeh,               Puyuma 49,               Rukai"<<endl;
   cout<<"Ryukuan,               Saisiat,          Seri,                    Shona"<<endl;
   cout<<"Singapore,          Siraya,               Thai,                    Thao"<<endl;
   cout<<"Toroko,           Tsou,               Tuva,                    Ugandan"<<endl;
   cout<<"Yami,               Yuendumu,           Yupik,                    Zambian"<<endl;
   cout<<"Zulu"<<endl;
int choice;
cout<<"Below are your menu choices:"<<endl;
cout<<"[1] Show individual populations with frequency"<<endl;
cout<<"[2] Show individual populations without the frequency"<<endl;
cout<<"[3] Print out all populations with their alleles"<<endl;
cin>>choice;

while(1)
{
switch(choice)
{
case 1:
   {
   GetPopulation(sPop);
    ExtractHaplotypesForPopulation ( "mhc.csv", sPop, lstTypes);
   ReadProteins ( "hla_nuc.fasta", mapProteins);
   AssociateProteinsWithHaplotypes ( "result.txt", sPop, lstTypes, mapProteins);
   break;
    }
   
case 2:
   {
   lstTypes.clear();
    mapProteins.clear();
    GetPopulation(sPop);
   ExtractHaplotypesForPopulation ( "mhc.csv", sPop, lstTypes);
   ReadProteins ( "hla_nuc.fasta", mapProteins);
    RemoveDuplicates (lstTypes);
   AssociateProteinsWithHaplotypes ( "resultfre.txt", sPop, lstTypes, mapProteins);
    break;
   }
case 3:
   {
    lstTypes.clear();
  list<string> lstPopulations;
  list<string>::iterator i;

  ReadPopulations("mhc.csv", lstPopulations);

  for (i = lstPopulations.begin(); i != lstPopulations.end(); ++i) {

     string strResult = string("result_") + *i + string(".txt");

     Process(*i, "hla_nuc.fasta", strResult.c_str(), true);
  }


    break;
   }
case 4: exit(0); break;
default:
        cout << "Invalid Menu choice.  Please make another selection." << endl;
   }
   return 0;
}
}
ettt6Author Commented:
It only outputs one file, not seperate files it keeps reading the Zulu over and over again, is that because Zulu is listed many times in column 3
jkrCommented:
Then, what about

case 3:
   {
    lstTypes.clear();
  list<string> lstPopulations;
  list<string>::iterator i;

  ReadPopulations("mhc.csv", lstPopulations);
  RemoveDuplicates(lstPopulations); // <----------------------------

  for (i = lstPopulations.begin(); i != lstPopulations.end(); ++i) {

     string strResult = string("result_") + *i + string(".txt");

     Process(*i, "hla_nuc.fasta.txt", strResult.c_str(), true);
  }


    break;
   }

?

You should have thought of that :o)
jkrCommented:
BTW, why do you only implement half the suggestions? I also wrote

case 1:
  {
  lstTypes.clear();
  mapProteins.clear();
  GetPopulation(sPop);
  Process(sPop, "hla_nuc.fasta", strResult.c_str(), false);
  break; // <-------

  }
case 2:
  {
  lstTypes.clear();
  mapProteins.clear();
  GetPopulation(sPop);
  Process(sPop, "hla_nuc.fasta", strResult.c_str(), true);
  break; // <-------

  }

No need to duplicate code, that'll only lead to problems.
ettt6Author Commented:
it works thanks..
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.