kamit
2Messages postés
16 juin 2009Date d'inscription
16 déc. 2009 à 02:13
s´lut les forumistes.
Le probleme m´a encore ete reposé sous la forme suivante:
On a un fichier, qui contient les Motifs de proteins suivants:
>PS00058
G-F-R-G-E-[AG]-L
>PS00059
G-H-E-x-{EL}-G-{AP}-x(4)-[GA]-x(2)-[IVSAC]
Le devoir est reecrire le contenu du fichier sous la forme suivante:
>PS00058
GFRGEAGL
>PS00059
GHEXELGXGAXIVSAC
Donc on doit annuler :[,],{,},(,),-
tout element annuler doit etre ecrit dans un fichier sous la forme (1, 2) pour[AG] par exemple ou (2,2) pour {AP}. En fait : 1 represente [; 2 represente {; 3---->(, 4-----> - et 0 si aucun des symboles n´est present.
Les chiffres prensents dans le string doivent tout simplement etre annulé.
J´ai pu developper ceci, mais ca ne marche.
Pouvez vous m´aider?
/*****************BEGIN*******************************************/
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <utility>
using namespace std;
struct Motiv {
vector<string> tokens; //content the amino acid
vector<pair<int, int> > brackets; //information about the brackets and the length of the charater
} Prot;
/**
* This function deletes all form of brackets in the string
* @param str is our string
* @param &vect is of typ vector<string> an has the character
*/
void strSplit(string str, vector<string> &vect)
{
int cutAt;
while( (cutAt = str.find_first_of("[]{}()-")) != str.npos )
{
if(cutAt > 0) vect.push_back(str.substr(0,cutAt));
str = str.substr(cutAt+1);
}
if(str.length() > 0) vect.push_back(str);
}
/****** end of function strSplit()***********************************/
/**
* This prints the brackets
* @param out
* @param charac
* @param brac the information about the bracket
*/
void printMBrackets(vector<pair<int, int> > brac, char charac, ostream &out)
{
int j = 0; //position of brackets
int i=0; // the length of one token
// vector<pair<int, int> > brac = make_pair(0,0);
if (charac == '[' || charac == '-' || charac == '{' || charac == '(' )
{
i++; // i = i+1
brac[j].second = i;
i = 0;
}
// if the founded charater is "[" we have 1, "{"--->2; "("--->3; "-" ----->4, else 0
switch (charac)
{
case '[':
brac[j].first = 1;
break;
case '{':
brac[j].first = 2;
break;
case '(':
brac[j].first = 3;
break;
case '-':
brac[j].first = 4;
break;
default:
brac[j].first = 0;
}
// brac.push_back(pair<int, int>(brac[j].first, brac[j].second));
out<<"("<<brac[j].first<<","<<brac[j].second<<")"<< endl; //
j++;
}
/*************end of printMBrackets()***********************************************/
/**
* This prints the Tokens
* @param out
* @param vect the information about the bracket
*/
void printMTokens(vector<string> vect, ostream &out)
{
for(vector<string>::iterator it = vect.begin(); it!=vect.end(); out<<*it<<" ", it++ );
out<<endl;
}
/***********************end of printMTokens()****************************************/
/**
* This prints the brackets
* @param f_name
*/
void readSeqFile(char* f_name)
{
/***** we try to delete all presented number in the string******************/
if (f_name)
{
f_name = strtok(NULL, "0123456789"); // delete 0,1,2,3,4,5,6,7,8,9
}
ifstream testIn(f_name); //open reading the the file testIn
string fres(f_name); //put f_name inside a string fres
fres += "Res";
ofstream testRes(fres.c_str()); //open writting the file testRes
if (testIn.is_open()) //check if the file is open
{
string line;
while (!testIn.eof() )
{
getline(testIn,line); //write the line in testIn
char c;
if ( line.empty() || (c = line.at(0)) == ' ') continue; //check if the line is empty or if it beginning whit a space
if ( c == '>')
{
Prot.tokens.push_back(line); //we get the name of the protein
getline(testIn,line); //amino acid
}
printMBrackets(Prot.brackets,c, testRes);
strSplit(line,Prot.tokens);
printMTokens(Prot.tokens, testRes);
Prot.tokens.clear();
Prot.brackets.clear();
}
testIn.close();
testRes.close();
}
else cout << "Unable to open in_file";
}
int main(int argc, char* argv[]){
readSeqFile(argv[1]);
system("pause");
return 0;
}