Merge branch 'alpha/JAL-3362_Jalview_212_alpha' into merge-212
[jalview.git] / src / jalview / io / CountReader.java
1 package jalview.io;
2
3 import jalview.bin.Jalview;
4 import jalview.datamodel.AlignmentI;
5 import jalview.datamodel.ResidueCount;
6 import jalview.datamodel.SequenceI;
7 import jalview.gui.AlignmentPanel;
8 import jalview.gui.Desktop;
9 import jalview.gui.JvOptionPane;
10 import jalview.util.MessageManager;
11
12 import java.io.File;
13 import java.io.IOException;
14 import java.net.MalformedURLException;
15
16 import javax.swing.JFileChooser;
17
18 public class CountReader
19 {
20   public static ResidueCount getBackgroundFrequencies(AlignmentPanel ap, SequenceI seq) throws MalformedURLException, IOException
21   {
22     JFileChooser bkgdFreqChooser = new JFileChooser();
23     
24     bkgdFreqChooser.showOpenDialog(ap);
25     
26     File file = bkgdFreqChooser.getSelectedFile();
27     if (file == null)
28     {
29       return null;
30     }
31     
32     IdentifyFile identifier = new IdentifyFile();
33     FileFormatI format = null;
34     try
35     {
36       format = identifier.identify(file.getPath(), DataSourceType.FILE);
37     } catch (Exception e)
38     {
39
40     }
41     
42     if (format == null)
43     {
44       if (!Jalview.isHeadlessMode())
45       {
46         JvOptionPane.showInternalMessageDialog(Desktop.desktop,
47                 MessageManager.getString("label.couldnt_read_data") + " in "
48                         + file + "\n"
49                         + AppletFormatAdapter.getSupportedFormats(),
50                 MessageManager.getString("label.couldnt_read_data"),
51                 JvOptionPane.WARNING_MESSAGE);
52       }
53     }
54
55     FileParse parser = new FileParse(file.getPath(), DataSourceType.FILE);
56     AlignmentI al = new FormatAdapter().readFromFile(parser, format);
57     parser.close();
58     
59     ResidueCount counts = new ResidueCount(al.getSequences());
60     
61     return counts;
62   }
63 }