Newer
Older
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
text_requester.addTextRequesterListener (new TextRequesterListener () {
public void actionPerformed (final TextRequesterEvent event) {
if (event.getType () == TextRequesterEvent.CANCEL) {
return;
}
final String bases_string = event.getRequesterText ().trim ();
if (bases_string.length () == 0) {
new MessageDialog (getParentFrame (), "no bases inserted");
return;
}
try {
// addBases () is static and uses the strand reference from the
// start Marker to decide which Strand to edit
Strand.addBases (range.getStart (), bases_string);
} catch (ReadOnlyException e) {
new MessageDialog (getParentFrame (),
"sorry the bases are read only");
return;
} catch (org.biojava.bio.symbol.IllegalSymbolException e) {
new MessageDialog (getParentFrame (),
"sorry - new sequence contains non-IUB base " +
"codes");
return;
}
}
});
text_requester.setVisible(true);
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
}
/**
* Ask the user for some bases and then add them at the start of the
* selected range.
**/
private void addBasesFromFile () {
if (!checkForSelectionRange ()) {
return;
}
if (getEntryGroup ().isReadOnly ()) {
new MessageDialog (getParentFrame (),
"one of the current entries or features is " +
"read-only - connot continue");
return;
}
final MarkerRange range = getSelection ().getMarkerRange ();
// XXX add an InputStreamProgressListener
final EntrySourceVector entry_sources =
Utilities.getEntrySources (getParentFrame (), null);
EntrySource filesystem_entry_source = null;
for (int source_index = 0 ;
source_index < entry_sources.size () ;
++source_index) {
final EntrySource this_source =
entry_sources.elementAt (source_index);
if (this_source.isFullEntrySource ()) {
continue;
}
if (this_source.getSourceName ().equals ("Filesystem")) {
filesystem_entry_source = this_source;
}
}
if (filesystem_entry_source == null) {
throw new Error ("internal error - can't find a file system to read " +
"from");
}
try {
final Entry new_entry = filesystem_entry_source.getEntry (true);
final Bases bases = new_entry.getBases ();
final String bases_string = bases.toString ();
if (bases_string.length () == 0) {
new MessageDialog (getParentFrame (), "no bases inserted");
return;
}
// addBases () is static and uses the strand reference from the
// start Marker to decide which Strand to edit
Strand.addBases (range.getStart (), bases_string);
} catch (ReadOnlyException e) {
new MessageDialog (getParentFrame (),
"sorry the bases are read only");
return;
} catch (IOException e) {
new MessageDialog (getParentFrame (),
"error while reading: " + e.getMessage ());
return;
} catch (OutOfRangeException e) {
new MessageDialog (getParentFrame (),
"out of range exception while reading: " +
e.getMessage ());
return;
} catch (NoSequenceException e) {
new MessageDialog (getParentFrame (),
"sorry the file did not contain any sequence");
return;
} catch (org.biojava.bio.symbol.IllegalSymbolException e) {
new MessageDialog (getParentFrame (),
"sorry - new sequence contains non-IUB base " +
"codes");
return;
}
}
/**
* Add a qualifier to the given features. The qualifier will normally be a
* gene name.
* @param prefix_string prefix of the new qualifier eg. SPAC
* @param start_number The number to start counting at eg. 1 give SPAC0001
* for the first CDS
* @param increment The amount to increment by at each gene.
* @param qualifier_name The name of the qualifier to add
* @param tag_complement_names If True a lowercase "c" will be appended to
* the new qualifier values on the reverse strand.
**/
private void autoGeneNameHelper (final FeatureVector features_to_name,
final String prefix_string,
final int start_number,
final int increment,
final String qualifier_name,
final boolean tag_complement_names,
final int format_value) {
String fmt = "";
for(int i=0; i<format_value; i++)
fmt = fmt.concat("0");
NumberFormat formatter = new DecimalFormat(fmt);
int current_number = start_number;
for (int i = 0 ; i < features_to_name.size () ; ++i) {
final Feature this_feature = features_to_name.elementAt (i);
final String number_string = formatter.format(current_number);
/*if (current_number < 10) {
number_string = "000" + current_number;
} else {
if (current_number < 100) {
number_string = "00" + current_number;
} else {
if (current_number < 1000) {
number_string = "0" + current_number;
} else {
number_string = String.valueOf (current_number);
}
}
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
try {
final Qualifier new_qualifier =
new Qualifier (qualifier_name, prefix_string +
number_string +
(!tag_complement_names ||
this_feature.isForwardFeature () ?
"" :
"c"));
this_feature.addQualifierValues (new_qualifier);
} catch (EntryInformationException e) {
new MessageDialog (getParentFrame (),
"/" + qualifier_name +
" not supported by this entry " +
"- cannot continue");
return;
} catch (ReadOnlyException e) {
new MessageDialog (getParentFrame (),
"one of the features is in a read-only " +
"entry - cannot continue");
return;
}
current_number += increment;
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
}
} finally {
entry_group.getActionController ().endAction ();
}
}
/**
* Automatically create gene names for all CDS features in the active
* entries.
**/
private void autoGeneName () {
if (!checkForSelectionFeatures (getParentFrame (), getSelection ())) {
return;
}
final FeatureVector features_to_name = getSelection ().getAllFeatures ();
if (getReadOnlyFeatures (features_to_name).size () > 0) {
new MessageDialog (getParentFrame (),
"one or more of the current features is " +
"read-only - cannot continue");
return;
}
final TextDialog prefix_dialog =
new TextDialog (getParentFrame (),
"enter the start characters of the new gene names:",
18, "");
final String prefix_text = prefix_dialog.getText ();
if (prefix_text == null) {
return;
}
final String prefix_string = prefix_text.trim ();
if (prefix_string.length () == 0) {
new MessageDialog (getParentFrame (), "no prefix given");
return;
}
final TextDialog start_number_dialog =
new TextDialog (getParentFrame (),
"start counting at:", 18, "1");
final String start_number_text = start_number_dialog.getText ();
if (start_number_text == null) {
return;
}
String start_string = start_number_text.trim ();
if (start_string.length () == 0) {
new MessageDialog (getParentFrame (), "no start given");
return;
}
final int start_value;
try {
start_value = Integer.valueOf (start_string).intValue ();
} catch (NumberFormatException e) {
new MessageDialog (getParentFrame (),
"this is not a number: " + start_string);
return;
}
final TextDialog increment_dialog =
new TextDialog (getParentFrame (),
"increment number by:", 18, "1");
final String increment_text = increment_dialog.getText ();
if (increment_text == null) {
return;
}
String increment_string = increment_text.trim ();
if (increment_string.length () == 0) {
new MessageDialog (getParentFrame (), "no increment given");
return;
}
final int increment_value;
try {
increment_value = Integer.valueOf (increment_string).intValue ();
} catch (NumberFormatException e) {
new MessageDialog (getParentFrame (),
"this is not a number: " + increment_string);
return;
}
final TextDialog qualifier_name_dialog =
new TextDialog (getParentFrame (),
"enter a qualifier name to use",
18, "gene");
final String qualifier_name_text = qualifier_name_dialog.getText ();
if (qualifier_name_text == null) {
return;
}
final String qualifier_name_string = qualifier_name_text.trim ();
if (qualifier_name_string.length () == 0) {
new MessageDialog (getParentFrame (), "no qualifier name given");
return;
}
final YesNoDialog complement_tag_dialog =
new YesNoDialog (getParentFrame (),
"append \"c\" to names of reverse strand features?");
final TextDialog format_dialog =
new TextDialog (getParentFrame (),
"number of digits in the name, e.g. 5, pads with " +
"zeros: 00009, 00010 ....",
18, "5");
int format_value;
try {
format_value = Integer.valueOf (format_dialog.getText().trim()).intValue ();
} catch (NumberFormatException e) {
new MessageDialog (getParentFrame (),
"this is not a number: " + format_dialog.getText());
return;
}
if(format_value < 0)
format_value = -format_value;
autoGeneNameHelper(features_to_name,
prefix_string, start_value, increment_value,
qualifier_name_string,
}
/**
* Helper function for fixGeneNames(). Add the gene name from the CDS to
* neighbouring/overlapping mRNA, intron, exon, gene, 5'UTR and 3'UTR
* features. Warn about inconsistencies.
* @return true if all went well, false if fixing should stop immediately
**/
private static boolean fixGeneNamesHelper(final JFrame frame,
final EntryGroup entry_group,
final Feature cds_to_fix,
final String name)
{
if(cds_to_fix.isReadOnly())
{
final String message =
"one or more of the of the selected features are read only " +
"- cannot continue";
new MessageDialog(frame, message);
try
{
final Strand cds_to_fix_strand = cds_to_fix.getStrand();
Marker cds_start_marker = cds_to_fix.getFirstBaseMarker();
Marker cds_end_marker = cds_to_fix.getLastBaseMarker();
// move the start one base back and the end one base forward so that
// when we call getFeaturesInRange() we get the UTRs
try
{
cds_start_marker = cds_start_marker.moveBy(-1);
}
catch(OutOfRangeException _)
{
try
{
cds_end_marker = cds_end_marker.moveBy(1);
}
catch(OutOfRangeException _)
{
// ignore and use the original cds_end_marker
}
final Range search_range;
if(cds_start_marker.getRawPosition() < cds_end_marker.getRawPosition())
{
search_range =
new Range(cds_start_marker.getRawPosition(),
cds_end_marker.getRawPosition());
}
else
{
new Range(cds_end_marker.getRawPosition(),
cds_start_marker.getRawPosition());
}
entry_group.getFeaturesInRange(search_range);
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
new FeatureVector();
for(int i = 0 ; i < features_in_range.size() ; ++i)
{
final Feature this_feature = features_in_range.elementAt(i);
if(this_feature.getStrand() == cds_to_fix_strand &&
(this_feature.isCDS() ||
this_feature.getKey().equals("mRNA") ||
this_feature.getKey().equals("intron") ||
this_feature.getKey().equals("exon") ||
this_feature.getKey().equals("5'UTR") &&
(cds_to_fix.getFirstBase() ==
this_feature.getLastBase() + 1) ||
this_feature.getKey().equals("3'UTR") &&
(cds_to_fix.getLastBase() + 1 ==
this_feature.getFirstBase()) ||
this_feature.getKey().equals("gene")))
{
if(this_feature.isReadOnly())
{
final String message =
"one or more of the of the overlapping features are read only " +
"- cannot continue";
new MessageDialog(frame, message);
// for exons check they are in this cds's range
if(this_feature.getKey().equals("exon"))
{
Range exon_range = this_feature.getMaxRawRange();
RangeVector ranges = cds_to_fix.getLocation().getRanges();
for(int j=0; j<ranges.size(); j++)
{
Range range = (Range)ranges.get(j);
if(exon_range.equals(range))
{
features_to_change.add(this_feature);
break;
}
}
}
else
features_to_change.add(this_feature);
final FeatureVector overlapping_cds_features = new FeatureVector();
for(int i = 0 ; i < features_to_change.size() ; ++i)
{
final Feature this_test_feature = features_to_change.elementAt(i);
if(this_test_feature != cds_to_fix && this_test_feature.isCDS())
{
overlapping_cds_features.add(this_test_feature);
features_to_change.remove(this_test_feature);
if(overlapping_cds_features.size() > 0)
{
"your CDS (" + cds_to_fix.getIDString() +
") overlaps " + overlapping_cds_features.size() +
(overlapping_cds_features.size() == 1 ?
new YesNoDialog(frame, message);
if(!dialog.getResult())
}
for(int i = 0; i < features_to_change.size(); ++i)
{
features_to_change.elementAt(i);
test_feature.getValuesOfQualifier(name);
if(test_feature_gene_names != null)
{
for(int j = 0; j < test_feature_gene_names.size(); ++j)
{
if(!gene_names.contains(this_gene_name))
// ignore this feature, but continue with the other features
if (gene_names.size () == 0)
for(int i = 0; i < features_to_change.size(); ++i)
{
final Feature this_feature = features_to_change.elementAt(i);
final Qualifier qualifier = new Qualifier(name, gene_names);
this_feature.setQualifier(qualifier);
}
}
catch(OutOfRangeException e)
{
throw new Error("internal error - unexpected exception: " + e);
}
catch(InvalidRelationException e)
{
throw new Error("internal error - unexpected exception: " + e);
}
catch(EntryInformationException e)
{
throw new Error("internal error - unexpected exception: " + e);
}
catch(ReadOnlyException e)
{
throw new Error("internal error - unexpected exception: " + e);
}
return true;
}
/**
* For each selected CDS, add the gene name from the CDS to
* neighbouring/overlapping mRNA, intron, exon, gene, 5'UTR and 3'UTR
* features. Warn about inconsistencies.
* @param frame The Frame to use for MessageDialog components.
* @param selection The Selection that the commands in the menu will
* operate on.
**/
private static void fixGeneNames(final JFrame frame,
final EntryGroup entry_group,
final Selection selection)
{
try
{
entry_group.getActionController().startAction();
final FeatureVector features_to_fix = selection.getAllFeatures();
StringVector names = Options.getOptions().getSystematicQualifierNames();
JList types = new JList(names);
types.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
types.setSelectedValue("gene", true);
JOptionPane.showMessageDialog(frame, types,
"Qualifier to Transfer", JOptionPane.QUESTION_MESSAGE);
String name = (String) types.getSelectedValue();
for(int i = 0; i < features_to_fix.size(); ++i)
{
final Feature selection_feature = features_to_fix.elementAt(i);
if(selection_feature.isCDS())
{
if(!fixGeneNamesHelper(frame, entry_group, selection_feature, name))
if(cds_features_found == 0)
new MessageDialog(frame, "no CDS features selected");
}
finally
{
entry_group.getActionController ().endAction ();
}
}
/**
* Return the EntryGroup that was passed to the constructor.
**/
private EntryGroup getEntryGroup()
{
return entry_group;
}
/**
* This method sends an GotoEvent to all the GotoEvent listeners that will
* make the first base of the selection visible.
**/
private void makeSelectionStartVisible()
{
final GotoEvent new_event = new GotoEvent(this,
getSelection().getStartBaseOfSelection());
goto_event_source.sendGotoEvent(new_event);
}
/**
* Returns a Vector containing those features in the given vector of
* features which are read only or are in a read only entry.
**/
private static FeatureVector getReadOnlyFeatures(final FeatureVector features)
{
final FeatureVector return_vector = new FeatureVector();
for(int i = 0; i < features.size(); ++i)
{
final Feature this_feature = features.elementAt(i);
if(this_feature.isReadOnly())
return_vector.add(this_feature);