/* * This file is part of Artemis * * Copyright(C) 2013 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. * */ package uk.ac.sanger.artemis.io; import java.io.File; import java.io.IOException; import java.util.HashSet; import java.util.Vector; import javax.swing.JOptionPane; import uk.ac.sanger.artemis.EntryGroup; import uk.ac.sanger.artemis.Options; import uk.ac.sanger.artemis.SimpleEntryGroup; import uk.ac.sanger.artemis.sequence.NoSequenceException; import uk.ac.sanger.artemis.util.Document; import uk.ac.sanger.artemis.util.DocumentFactory; import uk.ac.sanger.artemis.util.FileDocument; import uk.ac.sanger.artemis.util.OutOfRangeException; import uk.ac.sanger.artemis.util.ReadOnlyException; class GffToEMBL { /** * Convert GFF to EMBL * @param inGff * @param outDir * @param emblSubmission * @param flatten * @param gzip */ public GffToEMBL(final String inGff, final String outDir, final boolean emblSubmission, final boolean flatten, final boolean gzip) { final Entry entry = getEntry(inGff); if(entry == null || !(entry instanceof GFFDocumentEntry) ) { JOptionPane.showMessageDialog(null, "No GFF entry found.", "Error", JOptionPane.ERROR_MESSAGE); return; } EntryGroup egrp = null; try { uk.ac.sanger.artemis.Entry artEntry = new uk.ac.sanger.artemis.Entry(entry); egrp = new SimpleEntryGroup(artEntry.getBases()); egrp.add(artEntry); } catch (OutOfRangeException e) { e.printStackTrace(); } catch (NoSequenceException e) {} // no sequence if(egrp == null) // no sequence found { final FeatureVector features = entry.getAllFeatures(); final HashSet seqNames = new HashSet(); for(Feature f: features) seqNames.add(((GFFStreamFeature)f).getGffSeqName()); for(String seq: seqNames) { Entry newEntry = getEntryForSeqName(seq, features); writeEMBL(newEntry, seq, outDir, emblSubmission, flatten, gzip); } } else { writeEMBL(entry, entry.getName(), outDir, emblSubmission, flatten, gzip); } } /** * Write EMBL file * @param entry * @param seqName * @param outDir * @param emblSubmission * @param gzip */ private void writeEMBL( final Entry entry, final String seqName, final String outDir, final boolean emblSubmission, final boolean flatten, final boolean gzip) { final EntryInformation entryInfo; if(emblSubmission) entryInfo =Options.getDBEntryInformation(); else entryInfo = Options.getArtemisEntryInformation(); if(!flatten) { final FeatureVector features = entry.getAllFeatures(); for(int i=0; i files = new java.util.Vector();; String outDir = System.getProperty("user.dir"); // working directory for(int i=0; i