MATLAB: Searching a given line in a text file

text file

The following file is a txt file in sdf format(chemical structures) It looks sumthin lik this
7 9 1 0 0 0 0
7 14 1 0 0 0 0
8 10 1 0 0 0 0
8 15 1 0 0 0 0
9 10 2 0 0 0 0
9 16 1 0 0 0 0
10 17 1 0 0 0 0
12 13 1 0 0 0 0
13 18 1 0 0 0 0
13 19 1 0 0 0 0
13 20 1 0 0 0 0
M END
> <PUBCHEM_COMPOUND_CID>
2244
> <PUBCHEM_COMPOUND_CANONICALIZED>
1
> <PUBCHEM_CACTVS_COMPLEXITY>
212
I need to extract just the information under the CID number field and there could be multiple CID number fields in a single file.. How should I go about this?? Any help would be appreciated..

Best Answer

  • I tried sumthin lik this
    [A,B]=uigetfile('*.sdf','sdf');
    C=fopen(A,'r');
    n=0;
    i=<ui>; %number of structures -- wil be obtained from the user
    pubchem_id=[];
    z=<ui>*300; %rough approximation-- 300lines for each structure
    for j=1:1:z
    D=fgetl(C);
    if strcmp('> <PUBCHEM_COMPOUND_CID>',D)
    E=fgetl(C);
    E = str2double(E);
    pubchem_id=[pubchem_id; E]
    end
    end
    and it worked :)