Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97983570
Reader.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jan 8, 06:26
Size
5 KB
Mime Type
text/x-c
Expires
Fri, Jan 10, 06:26 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23470656
Attached To
R3229 Genome Privacy - SHCS App
Reader.java
View Options
package
io.hla
;
import
java.awt.Color
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.math.BigInteger
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
javax.swing.JTextPane
;
import
javax.swing.text.BadLocationException
;
import
javax.swing.text.SimpleAttributeSet
;
import
javax.swing.text.StyleConstants
;
import
javax.swing.text.StyledDocument
;
import
crypto.CryptoException
;
import
crypto.paillier.PaillierScheme
;
import
database.DBconnector_server
;
public
class
Reader
implements
Runnable
{
private
File
input_f
;
private
BufferedReader
br
;
private
DBconnector_server
conn_s
;
private
String
path_gprobs
;
private
String
path_fam
;
private
JTextPane
tp
;
private
StyledDocument
doc
;
public
Reader
(
String
gprobs
,
String
fam
,
JTextPane
txp
){
conn_s
=
new
DBconnector_server
();
path_fam
=
fam
;
path_gprobs
=
gprobs
;
tp
=
txp
;
doc
=
tp
.
getStyledDocument
();
}
// /**
// * @param args
// * @throws IOException
// * @throws CryptoException
// * @throws SQLException
// */
// public static void main(String[] args) throws IOException, SQLException, CryptoException {
//
// Reader r = new Reader("C:\\Users\\raisaro\\Dropbox\\EPFL\\Genomic Privacy\\CHUV\\dataSet\\SHCS693.samples.26-04-13.HLA.bgl.gprobs",
// "C:\\Users\\raisaro\\Dropbox\\EPFL\\Genomic Privacy\\CHUV\\dataSet\\SHCS693.samples.26-04-13.HLA.fam", null);
// // hardcoded paths
// r.run();
// System.out.println("GPROBS file complete");
//
// }
@Override
public
void
run
()
{
try
{
// conn_s.openConnection();
//check extension file for the FAM file
String
[]
pathCheck
=
path_fam
.
split
(
"\\."
);
if
(!
pathCheck
[
pathCheck
.
length
-
1
].
equalsIgnoreCase
(
"fam"
))
{
throw
new
IOException
(
"Wrong Format for FAM File!"
);
}
long
start
=
System
.
currentTimeMillis
();
SimpleAttributeSet
attribute
=
new
SimpleAttributeSet
();
StyleConstants
.
setForeground
(
attribute
,
Color
.
BLACK
);
try
{
doc
.
insertString
(
doc
.
getLength
(),
"Analysing FAM File, please wait..."
+
"\n\n"
,
attribute
);
}
catch
(
BadLocationException
e1
)
{
e1
.
printStackTrace
();
}
input_f
=
new
File
(
path_fam
);
br
=
new
BufferedReader
(
new
FileReader
(
input_f
));
String
newline
;
ArrayList
<
Integer
>
IDs_p
=
new
ArrayList
<
Integer
>();
while
((
newline
=
br
.
readLine
())
!=
null
){
String
[]
tokens
=
newline
.
split
(
" "
);
int
pat_id
;
try
{
pat_id
=
Integer
.
parseInt
(
tokens
[
0
]);
}
catch
(
Exception
e
){
String
[]
subtokens
=
tokens
[
0
].
split
(
"_"
);
pat_id
=
Integer
.
parseInt
(
subtokens
[
1
]);
}
IDs_p
.
add
(
pat_id
);
}
//check extension file for the GPROBS file
pathCheck
=
path_gprobs
.
split
(
"\\."
);
if
(!
pathCheck
[
pathCheck
.
length
-
1
].
equalsIgnoreCase
(
"gprobs"
))
{
throw
new
IOException
(
"Wrong Format for GPROBS File!"
);
}
try
{
doc
.
insertString
(
doc
.
getLength
(),
"Parsing GRPOBS File, please wait..."
+
"\n"
,
attribute
);
}
catch
(
BadLocationException
e1
)
{
e1
.
printStackTrace
();
}
input_f
=
new
File
(
path_gprobs
);
br
=
new
BufferedReader
(
new
FileReader
(
input_f
));
double
pp
=
0d
;
double
pa
=
0d
;
// double aa;
ArrayList
<
String
>[]
p_hla
=
new
ArrayList
[
IDs_p
.
size
()];
for
(
int
i
=
0
;
i
<
IDs_p
.
size
();
i
++){
p_hla
[
i
]
=
new
ArrayList
<
String
>();
}
while
((
newline
=
br
.
readLine
())
!=
null
){
String
[]
tokens
=
newline
.
split
(
" "
);
for
(
int
i
=
0
;
i
<
IDs_p
.
size
();
i
++){
pp
=
Double
.
parseDouble
(
tokens
[
i
*
3
+
3
]);
pa
=
Double
.
parseDouble
(
tokens
[
i
*
3
+
4
]);
if
(
pp
>
0.8
){
p_hla
[
i
].
add
(
tokens
[
0
]);
p_hla
[
i
].
add
(
tokens
[
0
]);
}
else
if
(
pa
>
0.8
){
p_hla
[
i
].
add
(
tokens
[
0
]);
}
}
}
BigInteger
[]
pbk
;
PaillierScheme
s
;
try
{
doc
.
insertString
(
doc
.
getLength
(),
"Encryption of HLA values, please wait..."
+
"\n"
,
attribute
);
}
catch
(
BadLocationException
e1
)
{
e1
.
printStackTrace
();
}
for
(
int
i
=
0
;
i
<
p_hla
.
length
;
i
++){
String
hla_a
=
""
;
String
hla_b
=
""
;
String
hla_c
=
""
;
for
(
int
j
=
0
;
j
<
p_hla
[
i
].
size
();
j
++){
// System.out.println(p_hla[i].get(j));
String
[]
tokens
=
p_hla
[
i
].
get
(
j
).
split
(
"_"
);
if
(
tokens
[
1
].
equals
(
"A"
)
&&
tokens
[
2
].
length
()
==
4
)
hla_a
=
hla_a
.
concat
(
tokens
[
2
]).
concat
(
";"
);
else
if
(
tokens
[
1
].
equals
(
"B"
)
&&
tokens
[
2
].
length
()
==
4
)
hla_b
=
hla_b
.
concat
(
tokens
[
2
]).
concat
(
";"
);
else
if
(
tokens
[
1
].
equals
(
"C"
)
&&
tokens
[
2
].
length
()
==
4
)
hla_c
=
hla_c
.
concat
(
tokens
[
2
]).
concat
(
";"
);
}
pbk
=
conn_s
.
getPublicKey
(
IDs_p
.
get
(
i
));
s
=
new
PaillierScheme
(
pbk
[
0
],
pbk
[
1
],
pbk
[
2
]);
BigInteger
[]
enc_hla_A
=
s
.
encrypt
(
new
BigInteger
(
hla_a
.
getBytes
()));
BigInteger
[]
enc_hla_B
=
s
.
encrypt
(
new
BigInteger
(
hla_b
.
getBytes
()));
BigInteger
[]
enc_hla_C
=
s
.
encrypt
(
new
BigInteger
(
hla_c
.
getBytes
()));
conn_s
.
insertEncryptedHLA
(
IDs_p
.
get
(
i
),
enc_hla_A
[
0
],
enc_hla_A
[
1
],
enc_hla_B
[
0
],
enc_hla_B
[
1
],
enc_hla_C
[
0
],
enc_hla_C
[
1
]);
}
long
end
=
System
.
currentTimeMillis
();
try
{
doc
.
insertString
(
doc
.
getLength
(),
"Parsing GRPOBS File completed!"
+
"\n\n"
,
attribute
);
doc
.
insertString
(
doc
.
getLength
(),
(
end
-
start
)
+
" ms\n"
,
attribute
);
}
catch
(
BadLocationException
e1
)
{
e1
.
printStackTrace
();
}
// conn_s.closeConnection();
}
catch
(
IOException
|
NumberFormatException
|
CryptoException
e
){
e
.
printStackTrace
();
SimpleAttributeSet
error
=
new
SimpleAttributeSet
();
StyleConstants
.
setForeground
(
error
,
Color
.
RED
);
try
{
doc
.
insertString
(
doc
.
getLength
(),
e
.
getMessage
()
+
"\n"
,
error
);
}
catch
(
BadLocationException
e1
)
{
e1
.
printStackTrace
();
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
SimpleAttributeSet
error
=
new
SimpleAttributeSet
();
StyleConstants
.
setForeground
(
error
,
Color
.
RED
);
try
{
doc
.
insertString
(
doc
.
getLength
(),
"No Connection with the Server"
+
"\n"
,
error
);
}
catch
(
BadLocationException
e1
)
{
e1
.
printStackTrace
();
}
}
}
}
Event Timeline
Log In to Comment