Merging the unique values

조회 수: 5 (최근 30일)
Pat
Pat 2012년 7월 23일
final_result =
'Genes' 'T0&T2' 'T1&T3' 'T2&T4' 'T3&T5' 'T4&T6'
'YAR029W' 'dd' 'uu' 'dd' 'uu' 'du'
'YBL095W' 'du' 'ud' 'ud' 'du' 'du'
'YBL111C' 'uu' 'uu' 'ud' 'ud' 'du'
'YBL113C' 'uu' 'uu' 'uu' 'ud' 'ud'
'YBR096W' 'uu' 'uu' 'ud' 'ud' 'dd'
'YBR138C' 'ud' 'ud' 'ud' 'du' 'du'
In these i have to find the genes having same variable(1st variable in each interval) for all the intervals for example
'YAR029W'has 'd'(1st variable) in interval 'T0&T2' ,in same interval i want to find which genes havibg variable'd',for example
'YBL095W','YBR138C',has value 'd'('d' may be 1sy or 2nd variable )
Same should be done for 2nd gene also in interval 'T0&T2'
'YBL111C' has 1st value 'u',the genes having 'u' must be displayed where , 'YBL113C''YBR096W','YBR138C' must be displayed
So i need output as
'Gene1' 'T0&T2'
'YAR029W' 'dd'
'YBL095W' 'du'
'YBR138C' 'ud'
;
;
'Gene3' 'T0&T2'
'YBL111C' 'uu'
'YBL113C' 'uu'
'YBR096W' 'uu'
'YBR138C' 'ud'
;
;
I have 1000 genes please help

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 7월 24일
%i'm not sur if i've understood what you meant, but try this
a=final_result;[n,m]=size(a);B=a(2:end,1);
for k=2:m
A=a(2:end,k); C=[B A];
ent1={strcat('out',num2str(2*k-3)) char(a(1,k))};
ent2={strcat('out',num2str(2*k-2)) char(a(1,k))};
s{1,k-1} =[ ent1;C(cellfun(@(x)any(regexp(x,'d')),A),:)];
s{2,k-1}= [ ent2;C(cellfun(@(x)any(regexp(x,'u[u,d]')),A),:)];
disp(s{1,k-1});disp(s{2,k-1})
end

추가 답변 (3개)

Andrei Bobrov
Andrei Bobrov 2012년 7월 23일
편집: Andrei Bobrov 2012년 7월 24일
EDIT
final_result = {...
'Genes' 'T0&T2' 'T1&T3' 'T2&T4' 'T3&T5' 'T4&T6'
'YAR029W' 'dd' 'uu' 'dd' 'uu' 'du'
'YBL095W' 'du' 'ud' 'ud' 'du' 'du'
'YBL111C' 'uu' 'uu' 'ud' 'ud' 'du'
'YBL113C' 'uu' 'uu' 'uu' 'ud' 'ud'
'YBR096W' 'uu' 'uu' 'ud' 'ud' 'dd'
'YBR138C' 'ud' 'ud' 'ud' 'du' 'du' };
fr = final_result(2:end,1:2);
frd = fr(cellfun(@(x)any(ismember(x,'d'),2),fr(:,2)),:);
fru = fr(cellfun(@(x)strcmp(x(1),'u'),fr(:,2)),:);
out = [arrayfun(@(x)frd([1,x:end],:),(2:size(fru,1)-1)','un',0);...
arrayfun(@(x)fru([x:end],:),(1:size(fru,1)-1)','un',0)];
  댓글 수: 3
Jan
Jan 2012년 7월 23일
I do not understand the format of your output. Should "out1", "out2" be separate variables? What are the "; ;" exactly - an [2 x 0] cell string?
Andrei Bobrov
Andrei Bobrov 2012년 7월 24일
Answer was edited.

댓글을 달려면 로그인하십시오.


Azzi Abdelmalek
Azzi Abdelmalek 2012년 7월 23일
편집: Azzi Abdelmalek 2012년 7월 23일
combining with Andrei answer:
a=final_result;[n,m]=size(a);B=a(2:end,1);
for k=2:m
A=a(2:end,k);
s{1,k-1} = [ [char(a(1,k)) '/gen1']; B(cellfun(@(x)any(regexp(x,'d')),A),:)];
s{2,k-1}= [[char(a(1,k)) '/gen3'] ;B(cellfun(@(x)any(regexp(x,'u[u,d]')),A),:)];
disp(s{1,k-1});disp(s{2,k-1})
end
  댓글 수: 1
Pat
Pat 2012년 7월 24일
Azzi i cannot understand the output of your code ,but i need the output as
out1(1st gene) 'T0&T2'
'YAR029W' 'dd'
'YBL095W' 'du'
'YBR138C' 'ud'
out2(2nd gene)
'YAR029W' 'dd'
'YBR138C' 'ud'
out3
'YBL111C' 'uu'
'YBL113C' 'uu'
'YBR096W' 'uu'
'YBR138C' 'ud'
out4;
'YBL113C' 'uu'
'YBR096W' 'uu'
'YBR138C' 'ud'
out5
'YBR096W' 'uu'
'YBR138C' 'ud'
The 1st column is the Genes and the 2nd is Interval

댓글을 달려면 로그인하십시오.


per isakson
per isakson 2012년 7월 24일
편집: per isakson 2012년 7월 24일
This code
for ii = 2 : 6
out = cell(0,2);
first_character = final_result{ ii, 2 }(1);
for jj = ii : 7
if ismember( first_character, final_result{ jj, 2 } )
out = cat( 1, out, final_result( jj, 1:2 ) );
end
end
out
end
prints
out =
'YAR029W' 'dd'
'YBL095W' 'du'
'YBR138C' 'ud'
out =
'YBL095W' 'du'
'YBR138C' 'ud'
out =
'YBL111C' 'uu'
'YBL113C' 'uu'
'YBR096W' 'uu'
'YBR138C' 'ud'
out =
'YBL113C' 'uu'
'YBR096W' 'uu'
'YBR138C' 'ud'
out =
'YBR096W' 'uu'
'YBR138C' 'ud'
>>
The columns
'T1&T3' 'T2&T4' 'T3&T5' 'T4&T6'
are confusing.
.
You write:
out2(2nd gene)
'YAR029W' 'dd'
'YBR138C' 'ud'
is that in accordance with your requirements?
  댓글 수: 2
Pat
Pat 2012년 7월 24일
Thanks a lot per isakson, The columns
'T1&T3' 'T2&T4' 'T3&T5' 'T4&T6' has to be prossed another operation i have given out1,out2 because these has to be processed further for another operations
per isakson
per isakson 2012년 7월 24일
편집: per isakson 2012년 7월 24일
I guessed that regarding the columns, but still not including them here would have made it easier to read the question.
You know, I cannot assign the result to out1, out2, etc. That would have made Jan and Walter very disappointed with me:) See the FAQ.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by