-
Notifications
You must be signed in to change notification settings - Fork 0
/
protein.java
114 lines (99 loc) · 2.29 KB
/
protein.java
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
import java.util.LinkedList;
public class protein {
String sequence;
LinkedList<Integer> bloc;
public protein(String sequence,LinkedList<Integer> bloc){
this.sequence=sequence;
this.bloc=bloc;
}
public static void printListe(LinkedList<Integer> bloc){
int N=bloc.size();
for (int i=0; i<N; i++){
System.out.print(bloc.get(i));
}
}
public static int FirstH(String S){
int compt=0;
int N=S.length();
char c=S.charAt(compt);
while (c!='H'&&compt<N){
compt=compt+1;
c=S.charAt(compt);
}
return compt;
}
public static int nextH(String S, int i){
int compt=1;
int N=S.length();
if (i==N-1){
return(compt);
}
char c=S.charAt(i+1);
while ((compt+i+1<N)&&(c!='H')){
c=S.charAt(i+compt);
compt=compt+1;
}
return (compt);
}
public protein formationBloc(){
String s1=this.sequence;
LinkedList<Integer> blok=new LinkedList<Integer>();
int N=s1.length();
int lettreCourante=0;
int Init= FirstH(s1);
if (Init==0||Init==1){
for (int i=0; i<Init+1;i++){
blok.add(1);
}
lettreCourante=Init;
}
else{
for (int i=0; i<2*(Init/2)+1;i++){
blok.add(0);
}
lettreCourante=2*(Init/2);
}
int QuelBloc=0; // Oscille entre 0 et 1 et détermine le bloc courant
int NextH=N+1;
while (lettreCourante<N&&NextH>1){
NextH = nextH(s1,lettreCourante);
int borne = NextH+lettreCourante;
if (NextH%2==0){
while (lettreCourante<N&&lettreCourante<borne-1){
blok.add(0);
lettreCourante=lettreCourante+1;
}
QuelBloc=(QuelBloc+1)%2;
}
else {
if(QuelBloc==0){
while (lettreCourante<N&&lettreCourante<borne-1){
blok.add(1);
lettreCourante=lettreCourante+1;
}
}
else {
while (lettreCourante<N&&lettreCourante<borne-1){
blok.add(2);
lettreCourante=lettreCourante+1;
}
}
}
}
protein P=new protein(s1,blok);
return(P);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String s1= "HPPPHPHPPPPHPPPHPPHPPPPPH";
LinkedList<Integer> blok=new LinkedList<Integer>();
for (int i=0; i<4;i++){blok.add(i);}
protein P=new protein(s1,blok);
P= P.formationBloc();
System.out.println(P.sequence);
System.out.println(nextH(s1,4));
System.out.println(s1.length());
printListe(P.bloc);
System.out.println(FirstH(s1));
}
}