-
Notifications
You must be signed in to change notification settings - Fork 9
/
PPR2.m
173 lines (145 loc) · 4.39 KB
/
PPR2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
function PPR2(SeqFile,ResultFile,t,tmp)
if nargin==2
t='0';
end
if exist([pwd,'/',tmp],'dir')
cmd=['rm -rf ',pwd,'/',tmp];
unix(cmd);
end
cmd=['mkdir ',pwd,'/',tmp];
unix(cmd);
%%%%%%%%split sequence%%%%%%%%%
data=fastaread(SeqFile);
c=1;
for i=1:1:size(data,1)
L=size(data(i).Sequence,2);
if L<=1200 %|| L>=5000
data_split(c,1).Header=['complete_',data(i).Header];
data_split(c,1).Sequence=data(i).Sequence;
c=c+1;
else
p1=1;
p2=1200;
seq=data(i).Sequence;
sub_seq=1;
while p1<=L
data_split(c,1).Header=['part',num2str(sub_seq),'_',data(i).Header];
data_split(c,1).Sequence=seq(p1:min(p2,L));
c=c+1;
sub_seq=sub_seq+1;
p1=p1+1200;
p2=p2+1200;
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%predict%%%%%%%%%
clear data
p1=1;
p2=10000;
c=1;
num=size(data_split,1);
while p1<=num
f=data_split(p1:min(p2,num));
fastawrite([pwd,'/',tmp,'file',num2str(c),'.fna'],f);
clear f
PPR([pwd,'/',tmp,'file',num2str(c),'.fna'],[pwd,'/',tmp,'out',num2str(c),'.csv'],t,tmp);
cmd=['rm ',pwd,'/',tmp,'file',num2str(c),'.fna'];
unix(cmd);
c=c+1;
p1=p1+10000;
p2=p2+10000;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%parse result%%%%%%%%%%
clear data_split
c=c-1;
predict=[];
for i=1:1:c
pre=readtable([pwd,'/',tmp,'out',num2str(i),'.csv'],'Delimiter',',');
pre=table2cell(pre);
predict=[predict;pre];
cmd=['rm ',pwd,'/',tmp,'out',num2str(i),'.csv'];
unix(cmd);
end
c=1;
total=size(predict,1);
for i=1:1:total
if size(predict{i,1},2)>=9 && strcmp(predict{i,1}(1:9),'complete_')
Group(c,1).Header=predict{i,1}(10:end);
Group(c,1).Length=predict{i,2};
Group(c,1).phage_score=predict{i,3};
Group(c,1).chromosome_score=predict{i,4};
Group(c,1).plasmid_score=predict{i,5};
c=c+1;
elseif strcmp(predict{i,1}(1:6),'part1_')
cc=i;
phage=predict{cc,3};
chromosome=predict{cc,4};
plasmid=predict{cc,5};
weight=predict{cc,2};
cc=cc+1;
while cc<=total && ~strcmp(predict{cc,1}(1:6),'part1_') && ~strcmp(predict{cc,1}(1:6),'comple')
phage=[phage,predict{cc,3}];
chromosome=[chromosome,predict{cc,4}];
plasmid=[plasmid,predict{cc,5}];
weight=[weight,predict{cc,2}];
cc=cc+1;
end
length=sum(weight);
weight=weight/length;
Group(c,1).Header=predict{i,1}(7:end);
Group(c,1).Length=length;
Group(c,1).phage_score=sum(phage.*weight);
Group(c,1).chromosome_score=sum(chromosome.*weight);
Group(c,1).plasmid_score=sum(plasmid.*weight);
c=c+1;
end
end
t=str2num(t);
for i=1:1:size(Group,1)
scores=[Group(i,1).phage_score,Group(i,1).chromosome_score,Group(i,1).plasmid_score];
[x,y]=max(scores);
if y==1
Group(i,1).Possible_source='phage';
if x<t
Group(i,1).Possible_source='uncertain_phage';
end
elseif y==2
Group(i,1).Possible_source='chromosome';
if x<t
Group(i,1).Possible_source='uncertain_chromosome';
end
elseif y==3
Group(i,1).Possible_source='plasmid';
if x<t
Group(i,1).Possible_source='uncertain_plasmid';
end
end
end
for i=1:1:size(Group,1)
result{i,1}=Group(i,1).Header;
result{i,2}=Group(i,1).Length;
result{i,3}=Group(i,1).phage_score;
result{i,4}=Group(i,1).chromosome_score;
result{i,5}=Group(i,1).plasmid_score;
result{i,6}=Group(i,1).Possible_source;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(newline)
disp(newline)
disp(newline)
disp(newline)
disp(newline)
if size(ResultFile,2)<4 || ~strcmp(ResultFile(end-3:end),'.csv')
disp('Warning!! The name of the output file has been changed to:')
disp([ResultFile,'.csv'])
disp('Note: The current version of PPR-Meta uses "Comma-Separated Values (CSV)" as the format of the output file!!')
ResultFile=[ResultFile,'.csv'];
end
result=cell2table(result,'VariableNames',{'Header','Length','phage_score','chromosome_score','plasmid_score','Possible_source'});
writetable(result,ResultFile);
cmd=['rm -rf ',pwd,'/',tmp];
unix(cmd);
disp(' ')
%disp('Finished.')