Basically, after the user inputs a cvs file which is formatted like (unmod.cvs that is attached is complete file):
Source, Native ID, Index, Charge, Cluster ID, FDR, Precursor Mass, Calculated Mass, Mass Error, Peptide, Mods, Search Scores
/tumor/set2/mam_082208o_individualsamples_747T_set2_082008_A01,scan=771,770,2,46,0,1162.436,1162.438,0.001953125,NDDDEEEAAR,,(mvh 52.0926)(mzFidelity 69.9226)
/tumor/set2/mam_082208o_individualsamples_747T_set2_082008_A01,scan=1147,1146,2,93,0,1436.543,1436.506,-0.0369873,AAEDDEDDDVDTQ,,(mvh 68.8836)(mzFidelity 92.7468)

*note that the mods value is a space, hence the double commas after the Peptide ("NDDDEEEAAR")

I need all those values to be copied and outputted in another file. I used the getline() function to get the values, and everything is copied fine to the output file. The problem I'm having though, is that I need to grab the peptide value (first column: "NDDDEEEAAR, second column: "AAEDDEDDDVDTQ") and pass that to the Calling_Function. Calling_Function analyzes the string, and will return the associated pI (which is a float). I then need to append a column for the pI, and place each peptides pI in that column (columns if you opened the cvs in excel, in cvs the output format should resemeble:
Source, Native ID, Index, Charge, Cluster ID, FDR, Precursor Mass, Calculated Mass, Mass Error, Peptide, Mods, Search Scores, Estimated pI
/tumor/set2/mam_082208o_individualsamples_747T_set2_082008_A01,scan=771,770,2,46,0,1162.436,1162.438,0.001953125,NDDDEEEAAR,,(mvh 52.0926)(mzFidelity 69.9226), pI[from calling_function]
/tumor/set2/mam_082208o_individualsamples_747T_set2_082008_A01,scan=1147,1146,2,93,0,1436.543,1436.506,-0.0369873,AAEDDEDDDVDTQ,,(mvh 68.8836)(mzFidelity 92.7468), pI[from calling_function]

Below is the program

// program extracts data, runs various other functions to find pI, then writes data on another file"

#include <iostream>
#include <cstring>
#include <fstream>

using namespace std;

float Calling_Function(const string& sequence, float low_pH, float high_pH);

int main () 
{
	
	float start_pH=0;
	float end_pH=14;
	string output_file;
	string input_file;
	
	fstream infile;
	cout << "Please enter the input file name: ";
	getline(cin, input_file, '\n');
	fstream ts(input_file.c_str(), ios_base::in);
	
	if (ts) //if file exists
	{
	
		
		// First, this program will extract the sequence from a file
		// and store the sequence in a variable called pep_sequence
		infile.open(input_file.c_str());
		string Source, Native_ID, Index, Charge, Cluster_ID, FDR, Precursor_mass, Calculated_Mass, Mass_Error, Peptide,test_pI, Mods, Search_Scores, pI_label;
		string pep_sequence;
		
		getline( infile, Source, ',' );
		getline( infile, Native_ID, ',' );
		getline( infile, Index, ',' );
		getline( infile, Charge, ',' );
		getline( infile, Cluster_ID, ',' );
		getline( infile, FDR, ',' );
		getline( infile, Precursor_mass	, ',' );
		getline( infile, Calculated_Mass, ',' );
		getline( infile, Mass_Error, ',' );
		getline( infile, Peptide, ',' );
		float pI_estimate= Calling_Function(Peptide, start_pH, end_pH);
		getline(infile, Mods, ',');
		getline( infile,  Search_Scores, '\n' );
		infile.close();
		
		ofstream datafile;
		cout << "Please enter the output file name: ";
		getline(cin,output_file,'\n');
		fstream fs(output_file.c_str(), ios_base::in);
		
		if (fs) //if file exists 
		{
			cout << "Output file exists already. Please Restart Program and enter nonexisting name"<<endl;
		}
		else
		{
			datafile.open(output_file.c_str());
			cout << "source: "<< Source<<endl;
			cout << "native id: "<< Native_ID<<endl;
			cout << "pI label is" <<pI_label;
			datafile<< Source<< " ,"<<Native_ID<< " ,"<<Index<<" ,"<<Charge<<" ,"<<Cluster_ID<<" ,"<<FDR<<" ,"<<Precursor_mass<<" ,"<<Calculated_Mass<<" ,"<<Mass_Error<<" ,"<<Peptide<<","<<Mods<<" ,"<<Search_Scores<<","<<pI_estimate<<"\n";
			datafile.close();
			return 0;
		}

	
	}
	
	else 
	{
		cout << "Input file does not exist.  Please restart program and choose proper input file"<<endl;
		return 0;
	}

}

When I run the code, the output attaches only the pI for the 1st row (peptide is the value being analyzed for the first row, it would be NDDDEEEAAR for the 2nd, AAEDDEDDDVDTQ for the 3rd, etc )
in the final cell.

Main question:
After getline(infile, Peptide, ','); how do I make the program analyze the value for each row in the peptide column?

I've only been doing c++ ( and object oriented) for about a week now, and I know there are probably much better ways to accomplish what I'm doing, so sorry if the code is rough

Also, as a side question, why do the getline() functions copy all the rows when I haven't written any sort of loop for it? I was under the impression that it would have only copied the first line, and that I would have to create some sort of loop for it to get all the rows.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.