/
PeptideArchive.java
77 lines (70 loc) · 2.24 KB
/
PeptideArchive.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
import java.util.*;
import java.io.*;
import com.google.common.collect.*;
public class PeptideArchive implements Serializable
{
public static final long serialVersionUID = 1L;
public final Map<String,List<Peptide>> map;
public PeptideArchive(Map<String,List<Peptide>> map)
{
this.map = ImmutableMap.copyOf(map);
}
@Override
public String toString()
{
String returnString = "";
for (String s : map.keySet())
returnString += String.format("%9s (%d structures)\n", s, map.get(s).size());
return returnString;
}
/**
* Writes the peptide to disk. Will not die from exceptions.
* @param filename the filename to write to
*/
public void checkpoint(String filename)
{
if ( filename == null || filename.length() == 0 )
throw new NullPointerException("must specify a filename");
try
{
FileOutputStream fileOut = new FileOutputStream(filename);
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(this);
out.close();
fileOut.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* Loads a peptide checkpoint from disk. WIll not die from exceptions.
* @param filename the filename to write to
* @return the deserialized peptide
*/
public static PeptideArchive load(String filename)
{
if ( filename == null || filename.length() == 0 )
throw new NullPointerException("must specify a filename");
try
{
FileInputStream fileIn = new FileInputStream(filename);
ObjectInputStream in = new ObjectInputStream(fileIn);
PeptideArchive p = (PeptideArchive)in.readObject();
in.close();
fileIn.close();
return p;
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public static void main(String[] args)
{
PeptideArchive archive = load("checkpoints/designs.chk");
System.out.println(archive);
}
}