Newer
Older
writer.close();
}
catch(IOException e)
{
new MessageDialog(getParentFrame(),
"error while writing: " + e.getMessage());
}
catch(NumberFormatException e)
{
new MessageDialog(getParentFrame(),
"this is not a number: " + base_count_string);
text_requester.setVisible(true);
* Helper method for writeFeatureBases(), writeUpstreamBases() and
* writeDownstreamBases().
* @return A string of the form "100:200 reverse" or "1:2222 forward".
**/
{
return (feature.isForwardFeature() ?
feature.getFirstCodingBaseMarker().getRawPosition() + ":" +
feature.getLastBaseMarker().getRawPosition() +
feature.getLastBaseMarker().getRawPosition() + ":" +
feature.getFirstCodingBaseMarker().getRawPosition() +
/**
* Return a sensible file name to write sequence of the given type to.
* @param output_type One of EMBL_FORMAT, RAW_FORMAT etc.
**/
private String getSequenceFileName(final int output_type)
{
switch(output_type)
{
case StreamSequenceFactory.FASTA_FORMAT:
return "sequence.dna";
case StreamSequenceFactory.EMBL_FORMAT:
return "sequence.embl";
case StreamSequenceFactory.GENBANK_FORMAT:
return "sequence.genbank";
case StreamSequenceFactory.RAW_FORMAT:
default:
return "sequence.seq";
}
}
/**
* Write the bases from entry_group as raw sequence.
* @param output_type One of EMBL_FORMAT, RAW_FORMAT etc.
**/
private void writeAllSequence(final int output_type)
{
final String file_name = getSequenceFileName(output_type);
writeBases(entry_group.getBases().toString(),
"all_bases", file_name, output_type);
}
/**
* Popup a requester and ask for a file name to write to. If the file
* exists ask the user whether to overwrite.
* @param title The title of the new FileDialog JFrame.
* @param default_name The name to put in the FileDialog as a default.
**/
private File getWriteFile(final String title, final String default_name,
final JTextField idField)
JCheckBox header = new JCheckBox("Add Header", false);
if(idField != null)
dialog.setAccessory(header);
dialog.setDialogTitle(title);
dialog.setFileSelectionMode(JFileChooser.FILES_ONLY);
dialog.setSelectedFile(new File(default_name));
dialog.setDialogType(JFileChooser.SAVE_DIALOG);
final int status = dialog.showSaveDialog(getParentFrame());
new YesNoDialog(getParentFrame(),
"this file exists: " + write_file +
" overwrite it?");
// request user to provide header
if(idField != null)
{
if(header.isSelected())
{
Box bdown = Box.createVerticalBox();
bdown.add(idField);
int n = JOptionPane.showConfirmDialog(null, bdown,
"Enter the entry ID",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
if(n == JOptionPane.CANCEL_OPTION)
idField.setText("");
}
else
idField.setText("");
}
return write_file;
}
}
/**
* Write a table of codon usage for the selected features to a file choosen
* by the user.
**/
private void writeCodonUsage()
{
if(!checkForSelectionFeatures())
getWriteFile("Select a codon usage output file ...", "usage", null);
try
{
final PrintWriter writer = new PrintWriter(new FileWriter(write_file));
for(int i = 0; i < features_to_write.size(); ++i)
{
final Feature selection_feature = features_to_write.elementAt(i);
for(int base1 = 0 ; base1 < 4 ; ++base1)
{
for(int base2 = 0 ; base2 < 4 ; ++base2)
{
for(int base3 = 0 ; base3 < 4 ; ++base3)
{
for(int base1 = 0 ; base1 < 4 ; ++base1)
{
for(int base3 = 0 ; base3 < 4 ; ++base3)
{
final StringBuffer buffer = new StringBuffer();
for(int base2 = 0 ; base2 < 4 ; ++base2)
{
buffer.append(Bases.letter_index[base1]);
buffer.append(Bases.letter_index[base2]);
buffer.append(Bases.letter_index[base3]);
buffer.append(' ');
per_thousand =
10000 * codon_counts[base1][base2][base3] / codon_total *
1.0F / 10;
buffer.append(per_thousand);
buffer.append("( ").append(codon_counts[base1][base2][base3]);
buffer.append(") ");
writer.close();
}
catch(IOException e)
{
new MessageDialog(getParentFrame(),
"error while writing: " + e.getMessage());