遺伝子間の関係や関係の一部などの遺伝子情報を含むテキストファイルがあります。
このテキストファイルには、各GOTermの段落が含まれています(GO用語は、GO:0030436のような特定のコード番号を含むノードです)。これには、Go用語ID(各段落の最初の行)とisa(存在する場合)(isaで始まる)が含まれます。そして、isaの終わりで終わります)およびpartof Go用語(存在する場合)(partof:で始まり、partofの終わりで終わります)このテキストファイルからの小さなサンプルは次のとおりです。
GO:0030436
isa:
GO:0034297
GO:0043936
GO:0048315
end of isa
partof:
GO:0042243
end of partof
genes:
end of genes
GO:0034297
isa:
end of isa
partof:
end of partof
genes:
end of genes
GO:0043936
isa:
GO:0001410
GO:0034300
GO:0034301
GO:0034302
GO:0034303
GO:0034304
end of isa
partof:
end of partof
genes:
end of genes
このテキストファイルを読み、そこから3つのデータを取得して、次のように3つの列を持つセルマトリックスを作成する必要があります。
map=
ID GoTerms is_a partof
GO:0030436 GO:0034297 GO:0042243
GO:0030436 GO:0043936 0
GO:0030436 GO:0048315 0
GO:0034297 0 0
GO:0043936 GO:0001410 0
GO:0043936 GO:0034300 0
GO:0043936 GO:0034301 0
GO:0043936 GO:0034302 0
GO:0043936 GO:0034303 0
GO:0043936 GO:0034304 0
各Go用語に複数の用語が含まれている場合は、セルマトリックスを適切に整理するために、Go用語IDを繰り返す必要があることに注意してください。
このコードを作成する方法について何かアイデアはありますか?
コードを作成しようとしましたが、複数のisaと用語の一部を取得する方法がわからないため、機能しません。
s={};
fid = fopen('Opt.pad'); % read from the certain text file
tline = fgetl(fid);
while ischar(tline)
s=[s;tline];
tline = fgetl(fid);
end
% find start and end positions of every [Term] marker in s
terms = [find(~cellfun('isempty', regexp(s, '\GO:\w*'))); numel(s)+1];
% for every [Term] section, run the previously implemented regexps
% and save the results into a map - a cell array with 3 columns map = cell(0,3);
for term=1:numel(terms)-1
% extract single [Term] data
s_term = s(terms(term):terms(term+1)-1); % match regexps
%To generate the GO_Terms vector from the text file
tok = regexp(s_term, '^(GO:\w*)', 'tokens');
idx = ~cellfun('isempty', tok);
GO_Terms=cellfun(@(x)x{1}, (tok(idx))); %To generate the is_a relations vector from the text file
tok = regexp(s_term, '^isa: (GO:\w*)', 'tokens');
idx = ~cellfun('isempty', tok);
is_a_relations =cellfun(@(x)x{1}, (tok(idx))); %To generate the part_of relaions vector from the text file
tok = regexp(s_term, '^partof: (GO:\w*)', 'tokens');
idx = ~cellfun('isempty', tok);
part_of_relations =cellfun(@(x)x{1}, (tok(idx))); % map. note the end+1 - here we create a new map row. Only once!
map{end+1,1} = GO_Terms;
map{end, 2} = is_a_relations;
map{end, 3} = part_of_relations;
end map( cellfun(@isempty, map) ) = {0};