I am trying to retrieve particular data from a txt file and would like to save it in a new txt file.
Here’s the sample of the data that i would like to retrive from the text file:
//
FORMAT CDDF1.0
DOMAIN 1cuk003
VERSION 3.1.0
VERDATE 20-Jan-2007
NAME Ruva protein. Chain: null. Engineered: yes
SOURCE Escherichia coli. Strain: 12 bl21 (de3). Expressed in: escherichia co
SOURCE li.
CATHCODE 1.10.8.10
CLASS Mainly Alpha
ARCH Orthogonal Bundle
TOPOL Helicase, Ruva Protein; domain 3
HOMOL DNA helicase RuvA subunit, C-terminal domain
DLENGTH 48
DSEQH >pdb|1cuk003
DSEQS TDDAEQEAVARLVALGYKPQEASRMVSKIARPDASSETLIREALRAAL
NSEGMENTS 1
SEGMENT 1cuk003:1:1
SRANGE START=156 STOP=203
SLENGTH 48
SSEQH >pdb|1cuk003:1:1
SSEQS TDDAEQEAVARLVALGYKPQEASRMVSKIARPDASSETLIREALRAAL
ENDSEG
//
From those details, I am trying to retrieve “DOMAIN, SRANGE START AND STOP”, but i would just like to select the information, not the header of the file name. For an example, DOMAIN is 1cuk003, i would just like to select “1cuk003” from it.
Do i need to store this data in an array? Or is there any other way that i could use to solve this problem. Also, i have over 10,000 entrires more of this data with different values.
The other part is that, once i have retrived those data, i would then like to format the data using “sprintf”, eg. sprintf('INSERT INTO postgres VALUES %d,%d.',array1,array2);
Is this possible?
Basically, in the end, I would like to have a text file, containing SQL INSERT statements of all the data been stored in which i can just easily execute them in PostgreSQL.
I did a test code in which it opens a text file, replicates the data and saves it in a new text file.
fid = fopen('sample.txt');
readfile = fread(fid, '*char');
fclose(fid);
output = fopen('output_sample.txt', 'wt');
fprintf(output,'%s \n', readfile);
fclose(output);
Thank you.
There are several MATLAB functions which come in handy:
Armed with these, the basic workflow is like that:
I currently do not have access to a MATLAB installation, so the code above is not tested. It should get you going, though.