diff --git a/uk/ac/sanger/artemis/components/alignment/BamView.java b/uk/ac/sanger/artemis/components/alignment/BamView.java index d77f92a9636b0bb7caed35dec883018f21dc6958..34199b863c029b38dfc65a340474bce2d38902ca 100644 --- a/uk/ac/sanger/artemis/components/alignment/BamView.java +++ b/uk/ac/sanger/artemis/components/alignment/BamView.java @@ -216,6 +216,7 @@ public class BamView extends JPanel private AlphaComposite translucent = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f); + private GroupBamFrame groupsFrame = new GroupBamFrame(this, bamFilesMenu); private CoveragePanel coverageView = new CoveragePanel(); protected static String BAM_SUFFIX = ".*\\.(bam|cram)$"; @@ -2413,9 +2414,8 @@ public class BamView extends JPanel }); bamFilesMenu.setFont(addBam.getFont()); - + final JMenuItem groupBams = new JMenuItem("Group BAMs ..."); - final GroupBamFrame groupsFrame = new GroupBamFrame(this, bamFilesMenu); groupBams.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { @@ -3688,7 +3688,7 @@ public class BamView extends JPanel if(coverageMenu == null) { coverageMenu = new JMenu("Coverage HeatMap"); - final JCheckBoxMenuItem coverageGrid = new JCheckBoxMenuItem("Heatmap grid", false); + final JCheckBoxMenuItem coverageGrid = new JCheckBoxMenuItem("Show heatmap grid", false); coverageGrid.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -3701,9 +3701,16 @@ public class BamView extends JPanel createGroup = new JMenuItem("Create group from selected BAMs"); createGroup.addActionListener(new ActionListener() { + private int n = 1; public void actionPerformed(ActionEvent e) { - + String groupName = "group_"+n; + groupsFrame.addGroup(groupName); + final List<String> selected = coverageView.getSelected(); + for(String sel: selected) + groupsFrame.addToGroup((new File(sel)).getName(), groupName); + groupsFrame.updateAndDisplay(); + n++; } }); coverageMenu.add(createGroup); diff --git a/uk/ac/sanger/artemis/components/alignment/CoveragePanel.java b/uk/ac/sanger/artemis/components/alignment/CoveragePanel.java index 1f3c6e0a4cc295b6ed8107cf28c80ba64b81f393..4810c54fbd65fc727e91a5c2e71feb95fa2ce1df 100644 --- a/uk/ac/sanger/artemis/components/alignment/CoveragePanel.java +++ b/uk/ac/sanger/artemis/components/alignment/CoveragePanel.java @@ -624,6 +624,11 @@ import net.sf.samtools.SAMRecord; { return (selected.size() > 0); } + + protected List<String> getSelected() + { + return selected; + } class HeatMapLn { diff --git a/uk/ac/sanger/artemis/components/alignment/GroupBamFrame.java b/uk/ac/sanger/artemis/components/alignment/GroupBamFrame.java index 148a80d90a4ed68ec98c554fea6bd47aa9e29caa..ee720fca2e79606505f59dc3b090db93c605fc19 100644 --- a/uk/ac/sanger/artemis/components/alignment/GroupBamFrame.java +++ b/uk/ac/sanger/artemis/components/alignment/GroupBamFrame.java @@ -66,7 +66,7 @@ class GroupBamFrame extends JFrame newGroup.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { - addGroup(bamView, bamFilesMenu, newGroup, jsp); + addGroup(newGroup.getText().trim()); } }); newGroup.addFocusListener(new java.awt.event.FocusAdapter() { @@ -92,7 +92,7 @@ class GroupBamFrame extends JFrame JOptionPane.INFORMATION_MESSAGE); return; } - addGroup(bamView, bamFilesMenu, newGroup, jsp); + addGroup(newGroup.getText().trim()); } }); xBox.add(Box.createHorizontalGlue()); @@ -148,18 +148,16 @@ class GroupBamFrame extends JFrame setVisible(true); } - private void addGroup(final BamView bamView, final JMenu bamFilesMenu, - final JTextField newGroup, final JScrollPane jsp) + protected void addGroup(final String newGroup) { final String tmpGroups[] = new String[groups.length+1]; - for(int i=0; i<groups.length; i++) - tmpGroups[i] = groups[i]; - tmpGroups[tmpGroups.length-1] = newGroup.getText().trim(); + System.arraycopy(groups, 0, tmpGroups, 0, groups.length); + tmpGroups[tmpGroups.length-1] = newGroup; groups = tmpGroups; updateGroupPanel(); updateBamPanel(); - jsp.validate(); + validate(); } private void updateBamPanel() @@ -203,6 +201,29 @@ class GroupBamFrame extends JFrame } } + /** + * Add a BAM to a specified group + * @param bam + * @param group + */ + protected void addToGroup(String bam, String group) + { + final Component cs[] = bamFilesMenu.getMenuComponents(); + for(Component cp : cs) + { + if(cp instanceof JCheckBoxMenuItem) + { + final JCheckBoxMenuItem cbBam = (JCheckBoxMenuItem) cp; + final String thisBam = cbBam.getText(); + if(bam.equals(thisBam)) + { + bamGroupMap.get(cbBam).setSelectedItem(group); + return; + } + } + } + } + /** * For a give BAM file return the group it belongs to. * @param bamName