Skip to content

Instantly share code, notes, and snippets.

@AntonPetrov
Created November 19, 2012 00:55
Show Gist options
  • Save AntonPetrov/4108400 to your computer and use it in GitHub Desktop.
Save AntonPetrov/4108400 to your computer and use it in GitHub Desktop.
Sample code for outputting basepair, basestacking, basephosphate, and baseribose annotations found by FR3D in a PDB file. Get FR3D here: https://github.com/BGSU-RNA/FR3D
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Sample code for outputting basepair, basestacking, basephosphate, and
% baseribose annotations found by FR3D in a PDB file.
% Input parameters:
% <pdb_id> - four-character PDB identifier.
% <output_filename> - optional name of the output file. If not provided, the
% output is printed to the screen
% Sample output:
% "1_A_1001_A","cWW","1_A_1040_U"
% "1_A_1002_G","s55","1_A_1040_U"
% "1_A_1039_C","s35","1_A_1040_U"
% FR3D looks in the /PDBFiles folder for <pdb_id>.pdb, if it's not there,
% then it attempts to download the structure from PDB.
% FR3D stores internal representation of the 3D structure in the
% /PrecomputedData folder for faster performance.
% Make sure that /PDBFiles and /PrecomputedData folders are writeable.
% Examples:
% from Matlab or octave command line:
% annotate_pdb('1S72')
% annotate_pdb('1S72', 'output.csv')
% from Unix system command line:
% path/to/matlab -nodisplay -r "setup_path; annotate_pdb('1S72'), quit"
% path/to/matlab -nodisplay -r "setup_path; annotate_pdb('1S72', 'output.csv'), quit"
% path/to/octave --eval "setup_path; annotate_pdb('1S72')"
% path/to/octave --eval "setup_path; annotate_pdb('1S72', 'output.csv')"
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function annotate_pdb(pdb_id, output_filename)
if nargin == 2
writeToFile = 1;
fid = fopen(output_filename, 'w');
else
writeToFile = 0;
fid = -1;
end
% create internal FR3D representation of the input file
File = zAddNTData(pdb_id);
% first parameter - function handle for data exporting
% second parameter - matrix with the interaction data
outputInteractions(@zEdgeText, File, 'Edge', writeToFile, fid);
outputInteractions(@zBasePhosphateText, File, 'BasePhosphate', writeToFile, fid);
outputInteractions(@zBaseRiboseText, File, 'BaseRibose', writeToFile, fid);
if writeToFile, fclose(fid); end
end
function outputInteractions(functionHandle, File, field_name, writeToFile, fid)
interaction_matrix = getfield(File, field_name);
interactions = find(interaction_matrix);
dimensions = size(interaction_matrix);
N = length(interactions);
for i = 1:N
[nt1, nt2] = ind2sub(dimensions, interactions(i));
% convert internal interaction label to its text representation
annotation = strtrim(functionHandle(interaction_matrix(nt1, nt2)));
if strcmp(annotation, '----'), continue; end
% edit this line to change the output format
output = sprintf('"%i_%s_%s_%s","%s","%i_%s_%s_%s"\n', ...
File.NT(nt1).ModelNum, ...
File.NT(nt1).Chain, ...
File.NT(nt1).Number, ...
File.NT(nt1).Base, ...
annotation, ...
File.NT(nt1).ModelNum, ...
File.NT(nt2).Chain, ...
File.NT(nt2).Number, ...
File.NT(nt2).Base);
if writeToFile
fprintf(fid, output);
else
fprintf(output);
end
end
end
@AntonPetrov
Copy link
Author

Tested with Matlab R2007b and octave 3.2.3

@AntonPetrov
Copy link
Author

Tested with Matlab R2007b and octave 3.6.3

@AntonPetrov
Copy link
Author

Tested with Matlab R2007b and octave 3.8.0

@AntonPetrov
Copy link
Author

Tested with the following Docker image: https://hub.docker.com/r/schickling/octave/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment