Newer
Older
/* AddMenu.java
*
* created: Tue Dec 29 1998
*
* This file is part of Artemis
*
* Copyright (C) 1998,1999,2000,2001,2002 Genome Research Limited
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/AddMenu.java,v 1.32 2007-12-12 16:03:09 tjc Exp $
*/
package uk.ac.sanger.artemis.components;
import uk.ac.sanger.artemis.*;
import uk.ac.sanger.artemis.sequence.BasePattern;
import uk.ac.sanger.artemis.sequence.BasePatternFormatException;
import uk.ac.sanger.artemis.sequence.Bases;
import uk.ac.sanger.artemis.sequence.MarkerRange;
import uk.ac.sanger.artemis.sequence.MarkerRangeVector;
import uk.ac.sanger.artemis.sequence.Strand;
import uk.ac.sanger.artemis.components.genebuilder.GeneUtils;
import uk.ac.sanger.artemis.io.GFFStreamFeature;
import uk.ac.sanger.artemis.io.Key;
import uk.ac.sanger.artemis.io.Range;
import uk.ac.sanger.artemis.io.RangeVector;
import uk.ac.sanger.artemis.io.Location;
import uk.ac.sanger.artemis.io.QualifierVector;
import uk.ac.sanger.artemis.io.Qualifier;
import uk.ac.sanger.artemis.io.LocationParseException;
import uk.ac.sanger.artemis.io.EntryInformationException;
import java.awt.Cursor;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Vector;
import java.util.Enumeration;
import javax.swing.Box;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
/**
* A Menu with commands that add new features/entries to an EntryGroup. This
* should have been called CreateMenu.
*
* @author Kim Rutherford
* @version $Id: AddMenu.java,v 1.32 2007-12-12 16:03:09 tjc Exp $
public class AddMenu extends SelectionMenu
{
/** The GotoEventSource object that was passed to the constructor. */
private GotoEventSource goto_event_source = null;
/** The EntryGroup object that was passed to the constructor. */
private EntryGroup entry_group;
private BasePlotGroup base_plot_group;
/**
* The shortcut for "Create From Base Range".
**/
final static KeyStroke CREATE_FROM_BASE_RANGE_KEY =
KeyStroke.getKeyStroke (KeyEvent.VK_C,
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); //InputEvent.CTRL_MASK);
final static public int CREATE_FROM_BASE_RANGE_KEY_CODE = KeyEvent.VK_C;
/** busy cursor */
private Cursor cbusy = new Cursor(Cursor.WAIT_CURSOR);
/** done cursor */
private Cursor cdone = new Cursor(Cursor.DEFAULT_CURSOR);
/*private AlignmentViewer alignQueryViewer;
private AlignmentViewer alignSubjectViewer;*/
/**
* Create a new AddMenu object.
* @param frame The JFrame that owns this JMenu.
* @param selection The Selection that the commands in the menu will
* operate on.
* @param entry_group The EntryGroup object where new features/entries will
* be added.
* @param goto_event_source The object the we will call makeBaseVisible ()
* on.
* @param base_plot_group The BasePlotGroup associated with this JMenu -
* needed to call getCodonUsageAlgorithm()
* @param base_plot_group The AlignmentViewer associated with this JMenu
*
* @param menu_name The name of the new menu.
**/
public AddMenu (final JFrame frame,
final Selection selection,
final EntryGroup entry_group,
final GotoEventSource goto_event_source,
final BasePlotGroup base_plot_group,
final String menu_name)
{
this(frame,selection,entry_group,
}
/**
* Create a new AddMenu object.
* @param frame The JFrame that owns this JMenu.
* @param selection The Selection that the commands in the menu will
* operate on.
* @param entry_group The EntryGroup object where new features/entries will
* be added.
* @param goto_event_source The object the we will call makeBaseVisible ()
* on.
* @param base_plot_group The BasePlotGroup associated with this JMenu -
* needed to call getCodonUsageAlgorithm()
* @param menu_name The name of the new menu.
**/
public AddMenu(final JFrame frame,
final Selection selection,
final EntryGroup entry_group,
final GotoEventSource goto_event_source,
final BasePlotGroup base_plot_group,
final AlignmentViewer alignQueryViewer,
final AlignmentViewer alignSubjectViewer,
final String menu_name)
/*this.alignQueryViewer = alignQueryViewer;
this.alignSubjectViewer = alignSubjectViewer;*/
this.entry_group = entry_group;
this.base_plot_group = base_plot_group;
final JMenuItem new_feature_item = new JMenuItem ("New Feature");
new_feature_item.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent event) {
makeNewFeature ();
}
});
add (new_feature_item);
new JMenuItem ("Create Feature From Base Range");
create_feature_from_range_item.setAccelerator (CREATE_FROM_BASE_RANGE_KEY);
create_feature_from_range_item.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent event) {
createFeatureFromBaseRange (getParentFrame (), getSelection (),
entry_group, getGotoEventSource ());
}
});
add (create_feature_from_range_item);
if(GeneUtils.isDatabaseEntry(entry_group))
{
final JMenuItem create_gene_model_from_range_item = new JMenuItem(
"Create Gene Model From Base Range");
// create_gene_model_from_range_item.setAccelerator
// (CREATE_FROM_BASE_RANGE_KEY);
create_gene_model_from_range_item.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
GeneUtils.createGeneModel(getParentFrame(), getSelection(),
entry_group, getGotoEventSource());
}
});
add (create_gene_model_from_range_item);
}
add (create_feature_from_range_item);
{
JMenuItem create_difference_feature =
create_difference_feature.addActionListener(new ActionListener()
{
public void actionPerformed (ActionEvent event)
{
if(alignQueryViewer == null || alignSubjectViewer == null)
diffs = alignQueryViewer.getDifferenceCoords(false);
sequence_entry = alignQueryViewer.getSubjectEntryGroup().getSequenceEntry();
}
diffs = alignSubjectViewer.getDifferenceCoords(true);
sequence_entry = alignSubjectViewer.getQueryEntryGroup().getSequenceEntry();
}
comparisonNote = comparisonNote + sequence_entry.getName();
}
else // multi-comparison
{
Vector diffs1 = alignQueryViewer.getDifferenceCoords(false);
Vector diffs2 = alignSubjectViewer.getDifferenceCoords(true);
Entry sequence_entry;
sequence_entry = alignQueryViewer.getSubjectEntryGroup().getSequenceEntry();
comparisonNote = comparisonNote + sequence_entry.getName();
sequence_entry = alignSubjectViewer.getQueryEntryGroup().getSequenceEntry();
comparisonNote = comparisonNote + " and " + sequence_entry.getName();
createFeatures(diffs, frame, comparisonNote);
}
});
add (create_difference_feature);
}
new JMenuItem ("Create Intron Features");
create_intron_features_item.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent event) {
createIntronFeatures (getParentFrame (), getSelection (),
entry_group);
}
});
if(entry_group.getDefaultEntry().getEMBLEntry() instanceof
uk.ac.sanger.artemis.io.DatabaseDocumentEntry)
create_intron_features_item.setEnabled(false);
final JMenuItem create_intergenic_features_item =
new JMenuItem ("Create Intergenic Features");
create_intergenic_features_item.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent event) {
createIntergenicFeatures(getParentFrame (), entry_group);
}
});
add (create_intergenic_features_item);
new JMenuItem ("Create Exon Features");
create_exon_features_item.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent event) {
createExonFeatures (getParentFrame (), getSelection (),
entry_group);
}
});
add (create_exon_features_item);
if(entry_group.getDefaultEntry().getEMBLEntry() instanceof
uk.ac.sanger.artemis.io.DatabaseDocumentEntry)
create_exon_features_item.setEnabled(false);
new JMenuItem ("Create Gene Features");
create_gene_features_item.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent event) {
createGeneFeatures (getParentFrame (), getSelection (),
entry_group);
}
});
add (create_gene_features_item);
if(entry_group.getDefaultEntry().getEMBLEntry() instanceof
uk.ac.sanger.artemis.io.DatabaseDocumentEntry)
create_gene_features_item.setEnabled(false);
final JMenuItem new_entry_item = new JMenuItem ("New Entry");
new_entry_item.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent event) {
makeNewEntry ();
}
});
add (new_entry_item);
addSeparator ();
final JMenuItem mark_orfs_with_size_item = new JMenuItem ("Mark Open Reading Frames ...");
mark_orfs_with_size_item.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent event) {
final JMenuItem mark_empty_orfs_with_size_item = new JMenuItem ("Mark Empty ORFs ...");
mark_empty_orfs_with_size_item.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent event) {
final JMenuItem mark_orfs_range_item = new JMenuItem ("Mark ORFs In Range ...");
mark_orfs_range_item.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent event) {
markOpenReadingFramesInRange ();
}
});
add (mark_orfs_range_item);
final JMenuItem mark_pattern_item = new JMenuItem ("Mark From Pattern ...");
mark_pattern_item.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent event) {
makeFeaturesFromPattern ();
}
});
add (mark_pattern_item);
final JMenuItem mark_ambiguities_item = new JMenuItem ("Mark Ambiguities");
mark_ambiguities_item.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent event) {
markAmbiguities ();
}
});
add (mark_ambiguities_item);
}
/**
*
* Find the union of coordinates in two Vecor objects.
* @param v1 Vector of Integer coordinates
* @param v2 Vector of Integer coordinates
*
*/
protected static Vector union(Vector v1, Vector v2)
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
{
Vector union = new Vector();
for(int i=0; i<v1.size(); i++)
{
Integer[] imatch = (Integer[])v1.get(i);
int istart = imatch[0].intValue();
int iend = imatch[1].intValue();
for(int j=0; j<v2.size(); j++)
{
Integer[] jmatch = (Integer[])v2.get(j);
int jstart = jmatch[0].intValue();
int jend = jmatch[1].intValue();
if( (istart >= jstart && istart <= jend) ||
(iend >= jstart && iend <= jend) ||
(jstart > istart && jend < iend) )
{
if(jstart > istart)
istart = jstart;
if(iend < jend)
jend = iend;
Integer coords[] = new Integer[2];
coords[0] = new Integer(istart);
coords[1] = new Integer(jend);
union.add(coords);
}
}
}
return union;
}
/**
*
* Create features from Vector of coordinates.
* @param diffs Vector of coordinates to create feature from.
* @param frame The JFrame that owns this JMenu.
*
*/
private void createFeatures(Vector diffs, JFrame frame, String name)
{
Enumeration eDiffs = diffs.elements();
while(eDiffs.hasMoreElements())
{
Integer coords[] = (Integer[])eDiffs.nextElement();
int start = coords[0].intValue();
int end = coords[1].intValue();
// System.out.println(start+" "+end);
final Entry default_entry = entry_group.getDefaultEntry();
if(default_entry == null)
{
new MessageDialog(frame, "There is no default entry");
return;
}
Location loc = null;
Feature temp_feature;
try
{
loc = new Location(start+".."+end);
Key misc_feature = new Key("misc_feature");
temp_feature = default_entry.createFeature(misc_feature, loc);
Qualifier note = new Qualifier("note",
"Automatically generated region of difference with "+
name);
temp_feature.setQualifier(note);
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
}
catch(EntryInformationException e)
{
// use the default key instead
final Key default_key =
default_entry.getEntryInformation().getDefaultKey();
try
{
temp_feature =
default_entry.createFeature(default_key, loc);
}
catch(EntryInformationException einfo)
{
throw new Error("internal error - unexpected exception: " + einfo);
}
catch(ReadOnlyException eRead)
{
new MessageDialog(frame, "feature not created: " +
"the default entry is read only");
}
catch(OutOfRangeException eout)
{
throw new Error("internal error - unexpected exception: " + eout);
}
}
catch(ReadOnlyException e)
{
new MessageDialog(frame, "feature not created: " +
"the default entry is read only");
}
catch(OutOfRangeException e)
{
throw new Error("internal error - unexpected exception: " + e);
}
catch(LocationParseException lpe)
{
throw new Error("internal error - unexpected exception: " + lpe);
}
}
}
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
/**
* Create a new AddMenu object.
* @param frame The JFrame that owns this JMenu.
* @param selection The Selection that the commands in the menu will
* operate on.
* @param entry_group The EntryGroup object where new features/entries will
* be added.
* @param goto_event_source The object the we will call makeBaseVisible ()
* on.
* @param base_plot_group The BasePlotGroup associated with this JMenu -
* needed to call getCodonUsageAlgorithm()
**/
public AddMenu (final JFrame frame,
final Selection selection,
final EntryGroup entry_group,
final GotoEventSource goto_event_source,
final BasePlotGroup base_plot_group) {
this (frame, selection, entry_group,
goto_event_source, base_plot_group, "Create");
}
/**
* Create a new feature in the default Entry of the entry group. See
* EntryGroup.createFeature () for details.
**/
private void makeNewFeature () {
if (entry_group.size () > 0) {
if (entry_group.getDefaultEntry () == null) {
new MessageDialog (getParentFrame (), "There is no default entry");
} else {
try {
entry_group.getActionController ().startAction ();
final Feature new_feature = entry_group.createFeature ();
final JFrame edit_frame = new JFrame("Artemis Feature Edit: " +
new_feature.getIDString() +
(new_feature.isReadOnly() ?
" - (read only)" :
""));
final FeatureEdit feature_edit = new FeatureEdit(new_feature, entry_group,
getSelection(), getGotoEventSource(), edit_frame);
edit_frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent event)
{
feature_edit.stopListening();
edit_frame.dispose();
}
});
edit_frame.getContentPane().add(feature_edit);
edit_frame.pack();
//final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
//edit_frame.setLocation(new Point((screen.width - edit_frame.getSize().width)/2,
// (screen.height - edit_frame.getSize().height)/2));
Utilities.centreFrame(edit_frame);
final ActionListener cancel_listener =
new ActionListener () {
public void actionPerformed (ActionEvent e) {
try {
new_feature.removeFromEntry ();
} catch (ReadOnlyException exception) {
throw new Error ("internal error - unexpected exception: " +
exception);
}
}
};
feature_edit.addCancelActionListener (cancel_listener);
feature_edit.addApplyActionListener (new ActionListener () {
public void actionPerformed (ActionEvent e) {
// after apply is pressed cancel should not remove the new
// feature
feature_edit.removeCancelActionListener (cancel_listener);
}
});
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
} catch (ReadOnlyException e) {
new MessageDialog (getParentFrame (), "feature not created: " +
"the default entry is read only");
} finally {
entry_group.getActionController ().endAction ();
}
}
} else {
new MessageDialog (getParentFrame (),
"Cannot make a feature without an existing entry");
}
}
/**
* Create a new Entry in the first Entry of the entry group.
**/
private void makeNewEntry () {
entry_group.createEntry ();
}
/**
* Create a new Feature in entry_group from the selected range of bases and
* then display a FeatureEdit component for the new Feature.
* @param frame The JFrame to use for MessageDialog components.
* @param selection The Selection containing the sequence to create the
* feature from.
* @param entry_group The EntryGroup to create the feature in.
* @param goto_event_source Needed to create a FeatureEdit component.
**/
static void createFeatureFromBaseRange (final JFrame frame,
final Selection selection,
final EntryGroup entry_group,
final GotoEventSource
goto_event_source) {
try {
entry_group.getActionController ().startAction ();
if (!checkForSelectionRange (frame, selection)) {
return;
}
final MarkerRange range = selection.getMarkerRange ();
final Entry default_entry = entry_group.getDefaultEntry ();
if (default_entry == null) {
new MessageDialog (frame, "There is no default entry");
return;
}
try {
final Location new_location = range.createLocation ();
/*final*/ Feature temp_feature;
QualifierVector qualifiers = null;
final boolean isDatabaseEntry = GeneUtils.isDatabaseEntry(entry_group);
String uniquename = GeneUtils.promptForUniquename(entry_group,
Qualifier qualifier = new Qualifier("ID", uniquename);
qualifiers = new QualifierVector();
qualifiers.add(qualifier);
}
try
{
temp_feature = default_entry.createFeature (key, new_location);
temp_feature = default_entry.createFeature (key, new_location, qualifiers);
{
final ChadoCanonicalGene chado_gene = new ChadoCanonicalGene();
chado_gene.setGene(temp_feature.getEmblFeature());
((uk.ac.sanger.artemis.io.GFFStreamFeature)
(temp_feature.getEmblFeature())).setChadoGene(chado_gene);
}
catch (EntryInformationException e)
{
// use the default key instead
final Key default_key =
default_entry.getEntryInformation ().getDefaultKey ();
try
{
if(qualifiers == null)
temp_feature =
default_entry.createFeature (default_key, new_location);
else
temp_feature =
default_entry.createFeature (default_key, new_location, qualifiers);
}
catch (EntryInformationException ex)
{
throw new Error ("internal error - unexpected exception: " + ex);
}
}
final Feature new_feature = temp_feature;
selection.setMarkerRange (null);
selection.set (new_feature);
final ActionListener cancel_listener = new ActionListener()
try
{
new_feature.removeFromEntry ();
selection.setMarkerRange(range);
}
catch (ReadOnlyException exception)
{
throw new Error("internal error - unexpected exception: " +
exception);
};
EditMenu.editSelectedFeatures(entry_group, selection, goto_event_source,
new_feature, cancel_listener, null);
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
} catch (ReadOnlyException e) {
new MessageDialog (frame, "feature not created: " +
"the default entry is read only");
} catch (OutOfRangeException e) {
throw new Error ("internal error - unexpected exception: " + e);
}
} finally {
entry_group.getActionController ().endAction ();
}
}
/**
* Create a new intron between each pair of exons in the selected CDS
* features. The introns are created in the Entry that contains the CDSs.
* @param frame The Frame to use for MessageDialog components.
* @param selection The Selection containing the CDS features to create the
* introns for.
* @param entry_group The EntryGroup to create the features in.
**/
static void createIntronFeatures (final JFrame frame,
final Selection selection,
final EntryGroup entry_group) {
try {
entry_group.getActionController ().startAction ();
if (!checkForSelectionFeatures (frame, selection)) {
return;
}
final FeatureVector selected_features = selection.getAllFeatures ();
for (int feature_index = 0 ;
feature_index < selected_features.size () ;
++feature_index) {
final Feature selection_feature =
selected_features.elementAt (feature_index);
if (!selection_feature.isProteinFeature ()) {
continue;
}
final Location cds_location = selection_feature.getLocation ();
final RangeVector cds_ranges = cds_location.getRanges ();
if (cds_ranges.size () < 2) {
continue;
}
if (cds_location.isComplement ()) {
cds_ranges.reverse ();
}
for (int range_index = 0 ;
range_index < cds_ranges.size () - 1 ;
++range_index) {
final int end_of_range_1 =
if (end_of_range_1 > start_of_range_2) {
// ignore - the exons overlap so there is no room for an intron
continue;
}
try {
new_range = new Range (end_of_range_1 + 1,
start_of_range_2 - 1);
} catch (OutOfRangeException e) {
Object[] options = { "CANCEL", "IGNORE", "IGNORE ALL"};
if(select != 2)
{
select = JOptionPane.showOptionDialog(null,
"Found overlapping CDS\n"+e,
"Out of Range",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE,
null,
options,
options[0]);
if(select == 0)
throw new Error ("internal error - unexpected exception: " + e);
continue;
}
}
final RangeVector intron_ranges = new RangeVector ();
intron_ranges.add (new_range);
final Key intron_key = new Key ("intron");
final Location intron_location =
new Location (intron_ranges, cds_location.isComplement ());
final QualifierVector qualifiers = new QualifierVector ();
try {
selection_feature.getEntry ().createFeature (intron_key,
intron_location,
qualifiers);
} catch (ReadOnlyException e) {
throw new Error ("internal error - unexpected exception: " + e);
} catch (EntryInformationException e) {
throw new Error ("internal error - unexpected exception: " + e);
} catch (OutOfRangeException e) {
Object[] options = { "CANCEL", "IGNORE", "IGNORE ALL"};
if(select != 2)
{
select = JOptionPane.showOptionDialog(null,
"Found overlapping CDS\n"+e,
"Out of Range",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE,
null,
options,
options[0]);
if(select == 0)
throw new Error ("internal error - unexpected exception: " + e);
}
}
}
}
} finally {
entry_group.getActionController ().endAction ();
}
}
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
/**
* Create intergenic regions between CDS.
* @param frame The Frame to use for MessageDialog components.
* @param entry_group The EntryGroup to create the features in.
**/
static void createIntergenicFeatures (final JFrame frame,
final EntryGroup entry_group)
{
try {
entry_group.getActionController ().startAction ();
final FeatureKeyPredicate predicate = new FeatureKeyPredicate(Key.CDS);
final FeatureVector cdsFeatures = new FeatureVector ();
final FeatureEnumeration feature_enum = entry_group.features ();
while (feature_enum.hasMoreFeatures ())
{
final Feature current_feature = feature_enum.nextFeature ();
if(predicate.testPredicate (current_feature))
cdsFeatures.add (current_feature);
}
RangeVector cdsRanges = new RangeVector();
for (int i = 0; i < cdsFeatures.size (); ++i)
{
final Feature selection_feature = cdsFeatures.elementAt(i);
final Location cds_location = selection_feature.getLocation();
final Range cds_range = cds_location.getTotalRange();
cdsRanges.add(cds_range);
//if (cds_location.isComplement ()) {
// cds_ranges.reverse ();
//}
}
int prevEnd = 1;
for(int i=0; i < cdsRanges.size(); i++)
{
Range r = (Range)cdsRanges.get(i);
int currentStart = r.getStart();
if(i==0 && r.getStart()==1)
{
prevEnd = r.getEnd();
continue;
}
try
{
Range new_range = new Range(prevEnd + 1,
currentStart - 1);
Location location = new Location(new_range);
final Key key = new Key ("misc_feature");
final QualifierVector qualifiers = new QualifierVector ();
entry_group.getDefaultEntry().createFeature(key,
location, qualifiers);
prevEnd = r.getEnd();
if(i==cdsRanges.size()-1)
{
if(entry_group.getSequenceLength() > r.getEnd())
{
new_range = new Range(prevEnd + 1,
entry_group.getSequenceLength());
location = new Location(new_range);
entry_group.getDefaultEntry().createFeature(key,
location, qualifiers);
}
}
}
catch (OutOfRangeException e) {}
catch(ReadOnlyException e) {}
catch(EntryInformationException e) {}
}
}
finally
{
entry_group.getActionController ().endAction ();
}
}
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
/**
* Create a new exon for each FeatureSegment in the selected CDS features.
* The exons are created in the Entry that contains the CDSs.
* @param frame The Frame to use for MessageDialog components.
* @param selection The Selection containing the CDS features to create the
* exons for.
* @param entry_group The EntryGroup to create the features in.
**/
static void createExonFeatures (final JFrame frame,
final Selection selection,
final EntryGroup entry_group) {
try {
entry_group.getActionController ().startAction ();
if (!checkForSelectionFeatures (frame, selection)) {
return;
}
final FeatureVector selected_features = selection.getAllFeatures ();
for (int feature_index = 0 ;
feature_index < selected_features.size () ;
++feature_index) {
final Feature selection_feature =
selected_features.elementAt (feature_index);
if (!selection_feature.isProteinFeature ()) {
continue;
}
final Location cds_location = selection_feature.getLocation ();
final RangeVector cds_ranges = cds_location.getRanges ();
for (int range_index = 0 ;
range_index < cds_ranges.size () ;
++range_index) {
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
final RangeVector exon_ranges = new RangeVector ();
exon_ranges.add (this_range);
final Key exon_key = new Key ("exon");
final Location exon_location =
new Location (exon_ranges, cds_location.isComplement ());
final QualifierVector qualifiers = new QualifierVector ();
try {
selection_feature.getEntry ().createFeature (exon_key,
exon_location,
qualifiers);
} catch (ReadOnlyException e) {
throw new Error ("internal error - unexpected exception: " + e);
} catch (EntryInformationException e) {
throw new Error ("internal error - unexpected exception: " + e);
} catch (OutOfRangeException e) {
throw new Error ("internal error - unexpected exception: " + e);
}
}
}
} finally {
entry_group.getActionController ().endAction ();
}
}
/**
* Create a new gene for each of the selected CDS features.