How void function call input variables from file?

1 view (last 30 days)
I'm new to MATLAB and i have some probable simple problem.
I have some matlab script with void function
PredPPI = (Protein1,Protein2) in h1 line.
It use protein sequence (VIKNADMSEEMQQDSVECATQALEKYNIEKDIAAHIKKEFDK- like this) as input in matlab command window, for Protein1 and Protein2 in this format:
PredPPI = ('VIKNADMSEEMQQDSVECATQALEKYNIEKDIAAHIKKEFDK','MDNMSITNTPTSNDACLSIVHSLMCHRQGGESETF')
So I need to put every time this sequences for protein pairs to get some result.
I have 100 000 of this pairs....
So is it possible that Protein1 be read form file where I put every of this sequences in new line like this:
Protein1.txt
AIESLVKKLKEKKDELDSLIT
DMSEEMQQDSVECATQALEKYNIEKDIAAH
SITNTPTSNDACLSIVHSLMCHRQGGE
Protein2.txt
YNPTWHCIVGR
DMSEEMQQDSVECATQALEKYNIEKDIA
DACLSIVHSLMCHRQGGESETFAKRAIESLVKKLKEK
So when i call function input is FIRST line (protein sequence) from file Protein1.txt and first line from Protein2.txt, then when function finish, run next pair in second lines, then third then n-th to end of files. Or some similar solution so i dont need to manual input this long sequences every time...
Thanks in ADVANCE!!!
  2 Comments
Jan
Jan on 2 Jun 2015
I do not understand the question. Please take the time to rephrase it more clearly.
Max Skorceny
Max Skorceny on 3 Jun 2015
Sorry if i wrote it that way, Eng is my second language. I posted whole code now. My goal is to make this script (i posted below) read proteinA form file file1.txt and file2.txt and process it. This files have structure such as. Long lines of big letters where every new sequence is in new line. So Function open file1 and read proteinA seqence from first row, and open file2 and read proteinA sequence form 1 row, process it give output, then repeat this for second rows in file1 and file2 to the end of files.

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 2 Jun 2015
pfid1 = fopen('protein1.txt');
pfid2 = fopen('protein2.txt');
while true
prot1 = fgetl(pfid1);
if ~ischar(prot1); break; end %end of file
prot2 = fgetl(pfid2);
if ~ischar(prot2); break; end %end of file
PredPPI(prot1, prot2);
end
fclose(pfid1);
fclose(pfid2);
Question, though: what do you want to do with the output? Your function does not return any result, but it probably displays something. Do you need the displayed output saved? If you do, then before the "while true" add the line
diary('YourOutputFile.txt'); %use suitable name
and after the "end" of the "while" add
diary off

Max Skorceny
Max Skorceny on 3 Jun 2015
function Predict_PPI(proteinA,proteinB);
% proteinA and proteinB are two protein sequences for a protein pair AB
OriginData = dlmread('Descriptors.csv',',');
% property.csv is the file for listing the normalized values of seven descriptors of amino acids.
OriginData = OriginData';
AAindex = 'ACDEFGHIKLMNPQRSTVWY';
Pse=[];
L1=length(proteinA);
L2=length(proteinB);
AAnum1= [];
AAnum2= [];
for i=1:L1
AAnum1 = [AAnum1,OriginData(:,findstr(AAindex,proteinA(i)))];
end
for i=1:L2
AAnum2 = [AAnum2,OriginData(:,findstr(AAindex,proteinB(i)))];
end
Matrix1=[];
Matrix2=[];
for i=1:7
t1=zeros(1,30);
t2=zeros(1,30);
for j=1:30
for k=1:(L1-j)
J=(AAnum1(i,k)-sum(AAnum1(i,:)/L1))*(AAnum1(i,(k+j))-sum(AAnum1(i,:)/L1));
t1(j)=t1(j)+J;
end
for k=1:(L2-j)
J=(AAnum2(i,k)-sum(AAnum2(i,:)/L2))*(AAnum2(i,(k+j))-sum(AAnum2(i,:)/L2));
t2(j)=t2(j)+J;
end
t1(j)=t1(j)/(L1-j);
t2(j)=t2(j)/(L2-j);
end
Matrix1=[Matrix1,t1];
Matrix2=[Matrix2,t2];
end
Matrix=[0,Matrix1,Matrix2];
L=length(Matrix);
fid=fopen('proteinAB.txt','a+');
% proteinAB.txt: the vector of the protein pair AB are listed in this file for further predicting using SVM. This is the format required by libSVM.
for i=1:L
if i==1
fprintf(fid,'\n%3d',Matrix(i));
else
fprintf(fid,'\t%d',(i-1));fprintf(fid,':');fprintf(fid,'%f',Matrix(i));
end
end
fclose(fid);
This is original code I try to make more automatic. When I implement your code it give me this message
Caught "std::exception" Exception message is: Message Catalog MATLAB:services was not loaded from the file. Please check file location, format or contents
But I think we are on right track. Thanks for effort.
  2 Comments
Walter Roberson
Walter Roberson on 3 Jun 2015
Where in the code does it encounter that error?
Max Skorceny
Max Skorceny on 3 Jun 2015
function Predict_PPI(proteinA,proteinB);
% proteinA and proteinB are two protein sequences for a protein pair AB
pfid1 = fopen('PositiveA.txt');
pfid2 = fopen('PositiveB.txt');
while true
proteinA = fgetl(pfid1);
if ~ischar(proteinA); break; end %end of file
proteinB = fgetl(pfid2);
if ~ischar(proteinB); break; end %end of file
predict_PPI(proteinA, proteinB);
end
OriginData = dlmread('Descriptors.csv',',');
% property.csv is the file for listing the normalized values of seven descriptors of amino acids.
OriginData = OriginData';
AAindex = 'ACDEFGHIKLMNPQRSTVWY';
Pse=[];
L1=length(proteinA);
L2=length(proteinB);
AAnum1= [];
AAnum2= [];
for i=1:L1
AAnum1 = [AAnum1,OriginData(:,findstr(AAindex,proteinA(i)))];
end
for i=1:L2
AAnum2 = [AAnum2,OriginData(:,findstr(AAindex,proteinB(i)))];
end
Matrix1=[];
Matrix2=[];
for i=1:7
t1=zeros(1,30);
t2=zeros(1,30);
for j=1:30
for k=1:(L1-j)
J=(AAnum1(i,k)-sum(AAnum1(i,:)/L1))*(AAnum1(i,(k+j))-sum(AAnum1(i,:)/L1));
t1(j)=t1(j)+J;
end
for k=1:(L2-j)
J=(AAnum2(i,k)-sum(AAnum2(i,:)/L2))*(AAnum2(i,(k+j))-sum(AAnum2(i,:)/L2));
t2(j)=t2(j)+J;
end
t1(j)=t1(j)/(L1-j);
t2(j)=t2(j)/(L2-j);
end
Matrix1=[Matrix1,t1];
Matrix2=[Matrix2,t2];
end
Matrix=[0,Matrix1,Matrix2];
L=length(Matrix);
fid=fopen('proteinAB.txt','a+');
% proteinAB.txt: the vector of the protein pair AB are listed in this file for further predicting using SVM. This is the format required by libSVM.
for i=1:L
if i==1
fprintf(fid,'\n%3d',Matrix(i));
else
fprintf(fid,'\t%d',(i-1));fprintf(fid,':');fprintf(fid,'%f',Matrix(i));
end
end
fclose(fid);
fclose(pfid1);
fclose(pfid2);
When i try to implement Yours code like this and run
Predict_PPI(proteinA,proteinB)
i get error
Undefined function or variable 'proteinA'.
But if i try to load first files PostiveA and B with fopen and then define proteinA = fget1(pfid1); i get this second error
Caught "std::exception" Exception message is: Message Catalog MATLAB:services was not loaded from the file. Please check file location, format or contents

Sign in to comment.

Categories

Find more on Genomics and Next Generation Sequencing in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!