Info

This question is closed. Reopen it to edit or answer.

Given a table, how can I find corresponding values for a given element?

1 view (last 30 days)
In this problem, you will write a function
site=getsite(enzyme,rebasefile)
that takes a restriction enzyme name and returns its recognition site, as identified from a file containing information about restriction enzymes. If a rebase file is not provided, use 'rebase_small.txt'. Download and use the example rebase file available from http://sacan.biomed.drexel.edu/ftp/bmes201/final.20131/rebase_small.txt The format of the rebase file is self-descriptive.
It must be in this format:
>> disp( getsite ('AaaI','rebase_small.txt') )
C^GGCCG
>> disp( getsite ('AamI','rebase_small.txt') )
?
>> disp( getsite ('AbaUI') )
C(11/9)
Here is what I have so far:
function out = getsite(enzyme, rebasefile)
fid=fopen('rebase_small.txt','r');
if fid<0
fprintf('I am unable to open text file.');
out=[];
end
if ~feof(fid)
line=fgetl(fid);
if strncmp(line,'enzyme',6) > 0
location=line(14:16);
location(location==' ')=[];
strncmp(location,'enzyme',6);
out = line{7};
end
end
fclose(fid);

Answers (1)

Geoff Hayes
Geoff Hayes on 27 Nov 2014
S - you may want to consider using strfind instead of strcmp as the former will search/match on a substring rather than do a direct comparison, which I think us what you want given the Data in your file.
Note the code
if strcmp(line,'enzyme',6) > 0
I am not sure what your intent is with the 6 (does thus line of code actually work or does it throw an error?). And wrapping the enzyme input in single quotes means that this line of code (if we are to ignore the 6) will try to compare the word enzyme with the line string. Instead consider
if strfind(line,enzyme) > 0
which will try to match the variable enzyme (whatever string that may be) to a substring within the variable line.
Once you have found a match, then I suspect you want to skip a couple of lines until you reach the recognition site and save that result to an your output cell array.
Since this is a homework question, try incorporating these changes into your code.
  2 Comments
S
S on 27 Nov 2014
I tried this and it is still coming as an error. The error is saying that the output argument is not assigned. What does this mean and how could I fix it?
Geoff Hayes
Geoff Hayes on 27 Nov 2014
If your code is the same as the above (with only minor changes for strfind), then it seems to be only checking the first line in the file. And if the first line does not have the enzyme you are looking for, then the code ends without assigning anything to the output parameter out.
I think that you would need to use a while loop to iterate over each line until you find the matching enzyme, then skip the next couple of lines until you reach the recognition site and assign that to out.
Note that to avoid this error, in the event that no line in the file contains the desired enzyme, you should default out to an empty string before opening the file.

Community Treasure Hunt

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

Start Hunting!