Skip to content
Snippets Groups Projects
CircularGenomeController.java 19.8 KiB
Newer Older
  • Learn to ignore specific revisions
  • tjc's avatar
    tjc committed
    /*
     * Copyright (C) 2009  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.circular.digest;
    
    import uk.ac.sanger.artemis.Entry;
    import uk.ac.sanger.artemis.EntryGroup;
    import uk.ac.sanger.artemis.Options;
    import uk.ac.sanger.artemis.SimpleEntryGroup;
    import uk.ac.sanger.artemis.circular.Block;
    import uk.ac.sanger.artemis.circular.DNADraw;
    
    tjc's avatar
    tjc committed
    import uk.ac.sanger.artemis.components.ArtemisMain;
    import uk.ac.sanger.artemis.components.EntryEdit;
    
    tjc's avatar
    tjc committed
    import uk.ac.sanger.artemis.components.EntryFileDialog;
    import uk.ac.sanger.artemis.components.MessageDialog;
    
    tjc's avatar
    tjc committed
    import uk.ac.sanger.artemis.components.StickyFileChooser;
    
    tjc's avatar
    tjc committed
    import uk.ac.sanger.artemis.io.EntryInformation;
    
    tjc's avatar
    tjc committed
    import uk.ac.sanger.artemis.io.Range;
    
    tjc's avatar
    tjc committed
    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.OutOfRangeException;
    
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    
    
    tjc's avatar
    tjc committed
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import java.awt.event.MouseAdapter;
    
    tjc's avatar
    tjc committed
    import java.awt.event.MouseEvent;
    
    import java.awt.event.MouseListener;
    
    tjc's avatar
    tjc committed
    import java.awt.event.MouseMotionAdapter;
    import java.awt.event.MouseMotionListener;
    
    tjc's avatar
    tjc committed
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    
    tjc's avatar
    tjc committed
    import java.io.File;
    
    import java.io.FileNotFoundException;
    
    import java.io.FileReader;
    
    tjc's avatar
    tjc committed
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.List;
    
    import java.util.Vector;
    
    tjc's avatar
    tjc committed
    
    
    import javax.swing.Box;
    import javax.swing.JCheckBox;
    
    tjc's avatar
    tjc committed
    import javax.swing.JFrame;
    
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    
    tjc's avatar
    tjc committed
    import javax.swing.JMenuItem;
    
    tjc's avatar
    tjc committed
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    
    import javax.swing.JPopupMenu;
    
    tjc's avatar
    tjc committed
    import javax.swing.JScrollPane;
    
    tjc's avatar
    tjc committed
    import javax.swing.JSplitPane;
    
    import javax.swing.JTabbedPane;
    
    import javax.swing.JTextField;
    
    tjc's avatar
    tjc committed
    import javax.swing.SwingUtilities;
    
    tjc's avatar
    tjc committed
    
    /**
     * 
     */
    public class CircularGenomeController
    {
    
    tjc's avatar
    tjc committed
      private Block lastBlock = null;
    
    tjc's avatar
    tjc committed
      private JPanel gelPanel;
      private int hgt;
      private JFrame frame = new JFrame();
    
      private boolean methylation = false;
    
    tjc's avatar
    tjc committed
    
      public CircularGenomeController()
      {
      }
    
      /**
       * Create in-silico Pulse Field Gel Electrophoresis from a restriction enzyme
       * digest and draw alongside DNAPlotter
    
       * @param enzymes
       * @param sequenceFiles
       * @param restrictOutputs
    
       * @param methylation if true then RE recognition sites will not match methylated bases
    
       * @throws Exception
    
    tjc's avatar
    tjc committed
       */
    
      protected void setup(String enzymes, 
                           List<File> sequenceFiles,
    
                           List<File> restrictOutputs,
                           boolean methylation)
    
    tjc's avatar
    tjc committed
          throws Exception
      {
    
        this.methylation = methylation;
    
    tjc's avatar
    tjc committed
        // add each sequence file to a different entry group
        List<EntryGroup> entries = new Vector<EntryGroup>();
        if (sequenceFiles != null && sequenceFiles.size() > 0)
        {
          for (int i = 0; i < sequenceFiles.size(); i++)
          {
            EntryGroup entryGroup = getEntryGroupFromFile(sequenceFiles.get(i));
            entries.add(entryGroup);
          }
        }
        else
        {
          EntryGroup entryGroup = getEntryGroupFromFile(null);
          File sequenceFile = new File(((File) entryGroup.getSequenceEntry()
              .getRootDocument().getLocation()).getAbsolutePath()
              + File.separator + entryGroup.getSequenceEntry().getName());
    
    tjc's avatar
    tjc committed
          
          if(sequenceFiles == null)
            sequenceFiles = new Vector();
    
    tjc's avatar
    tjc committed
          sequenceFiles.add(sequenceFile);
          entries.add(entryGroup);
        }
    
        if (enzymes == null)
          enzymes = promptForEnzymes();
    
        // run restrict
    
        if(restrictOutputs == null)
    
    tjc's avatar
    tjc committed
        {
    
          restrictOutputs = new Vector<File>(sequenceFiles.size());
          for (int i = 0; i < sequenceFiles.size(); i++)
          {
            File sequenceFile = sequenceFiles.get(i);
            File restrictOutput = File.createTempFile("restrict_"
                + sequenceFile.getName(), ".txt");
            restrictOutputs.add(restrictOutput);
            runEmbossRestrict(sequenceFile.getAbsolutePath(), enzymes,
                restrictOutput);
          }
    
    tjc's avatar
    tjc committed
        }
        drawResults(restrictOutputs, entries, sequenceFiles, enzymes);
      }
    
      /**
       * Run the EMBOSS application restrict. This uses the EMBOSS_ROOT property to
       * define the location of EMBOSS>
       * 
       * @param fileName
       * @param cgcb
       * @param restrictOutput
       * @throws IOException
       * @throws InterruptedException
       */
    
      private void runEmbossRestrict(final String fileName, 
                                     final String enzymes,
                                     final File restrictOutput) throws IOException, InterruptedException
    
    tjc's avatar
    tjc committed
      {
        String[] args = { 
            System.getProperty("EMBOSS_ROOT") + "/bin/restrict", fileName, "-auto",
    
            "-limit", "y", "-enzymes", enzymes, 
            methylation ? "-methylation" : "", 
            "-out",
    
    tjc's avatar
    tjc committed
            restrictOutput.getCanonicalPath() };
    
        ProcessBuilder pb = new ProcessBuilder(args);
        pb.redirectErrorStream(true);
        Process p = pb.start();
    
        System.err.print("** Running restrict");
    
    tjc's avatar
    tjc committed
        try
        {
          InputStream is = p.getInputStream();
          int inchar;
          while ((inchar = is.read()) != -1)
          {
            char c = (char) inchar;
            System.err.print(c);
          }
          System.err.println("**");
          p.waitFor();
          System.err.println("Process exited with '" + p.exitValue() + "'");
        }
        catch (InterruptedException exp)
        {
          exp.printStackTrace();
        }
        p.waitFor();
      }
    
      /**
       * Display the result in DNAPlotter and the virtual digest.
       * 
       * @param restrictOutput
       * @param entryGroup
       * @param fileName
       * @param cgcb
       * @throws FileNotFoundException
       * @throws IOException
       */
      private void drawResults(final List<File> restrictOutputs,
          final List<EntryGroup> entries, final List<File> sequenceFiles,
          final String enzymes) throws FileNotFoundException, IOException
      {
        JTabbedPane tabbedPane = new JTabbedPane();
    
    tjc's avatar
    tjc committed
        gelPanel= new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
    
    tjc's avatar
    tjc committed
        Dimension preferredSize = null;
    
    tjc's avatar
    tjc committed
        for (int i = 0; i < entries.size(); i++)
        {
          final ReportDetails rd = Utils.findCutSitesFromEmbossReport(
              new FileReader(restrictOutputs.get(i).getCanonicalPath()));
    
    
    tjc's avatar
    tjc committed
          if(rd.cutSites.size() == 0)
    
          {
            JOptionPane.showMessageDialog(null, 
                "No cut site found for "+sequenceFiles.get(i).getName(),
    
    tjc's avatar
    tjc committed
                "RE Digest Results", JOptionPane.INFORMATION_MESSAGE);
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
          final DNADraw dna = Utils.createDNADrawFromReportDetails(
              rd, entries.get(i));
    
    tjc's avatar
    tjc committed
          tabbedPane.add(sequenceFiles.get(i).getName(), dna);
    
    tjc's avatar
    tjc committed
          
          hgt = dna.getHeight();
    
    tjc's avatar
    tjc committed
          final InSilicoGelPanel inSilicoGelPanel = new InSilicoGelPanel(rd.length,
    
    tjc's avatar
    tjc committed
              rd.cutSites, hgt, restrictOutputs.get(i),
              sequenceFiles.get(i).getName());
    
    tjc's avatar
    tjc committed
          gelPanel.add(inSilicoGelPanel);
    
    tjc's avatar
    tjc committed
          preferredSize = inSilicoGelPanel.getPreferredSize();
    
    tjc's avatar
    tjc committed
          addMouseListener(rd, dna, inSilicoGelPanel);
        }
    
    
    tjc's avatar
    tjc committed
        frame.setTitle ("Sandpiper :: "+enzymes);
    
    tjc's avatar
    tjc committed
        addMenuBar(frame);
        Dimension d = frame.getToolkit().getScreenSize();
    
    tjc's avatar
    tjc committed
        JScrollPane jspGel = new JScrollPane(gelPanel);
        
        Dimension dgel = new Dimension(
            preferredSize.width* (entries.size()>1 ? 2 : 1), preferredSize.height);
        jspGel.setPreferredSize(dgel);
        gelPanel.setMinimumSize(dgel);
        gelPanel.setBackground(Color.white);
        
        JScrollPane jspTabbedPane = new JScrollPane(tabbedPane);
        JSplitPane mainPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, 
            jspGel, jspTabbedPane);
    
        mainPanel.setBackground(Color.white);
    
    tjc's avatar
    tjc committed
    
    
        JScrollPane jsp = new JScrollPane(mainPanel);
        jsp.getViewport().setBackground(Color.white);
    
    tjc's avatar
    tjc committed
        frame.getContentPane().add(jsp);
    
    tjc's avatar
    tjc committed
        frame.pack();
        frame.setLocation(((int) d.getWidth() - frame.getWidth()) / 4,
            ((int) d.getHeight() - frame.getHeight()) / 2);
        frame.setVisible(true);
    
    tjc's avatar
    tjc committed
      }
    
      /**
       * Add the menu bar
       * 
       * @param f
       */
      private void addMenuBar(final JFrame f)
      {
        f.addWindowListener(new WindowAdapter()
    
    tjc's avatar
    tjc committed
        {
    
    tjc's avatar
    tjc committed
          public void windowClosing(WindowEvent event)
    
    tjc's avatar
    tjc committed
          {
            exitApp(f);
          }
        });
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
        JMenuBar menuBar = new JMenuBar();
    
        JMenu fileMenu = new JMenu("File");
        menuBar.add(fileMenu);
    
    tjc's avatar
    tjc committed
        
        JMenuItem loadExpData = new JMenuItem("Load experimental data...");
        loadExpData.addActionListener(new ActionListener()
        {
          public void actionPerformed(ActionEvent e)
          {
            StickyFileChooser fileChooser = new StickyFileChooser();
            int ret = fileChooser.showOpenDialog(null);
            if(ret == StickyFileChooser.CANCEL_OPTION)
              return;
            
            File expFile = fileChooser.getSelectedFile();
            FileReader reader;
            try
            {
              reader = new FileReader(expFile);
              final List<FragmentBand> bands = Utils.findCutSitesFromExperiment(reader);
    
    tjc's avatar
    tjc committed
              final InSilicoGelPanel inSilicoGelPanel = new InSilicoGelPanel(
                  bands, hgt, expFile, expFile.getName()); 
    
    tjc's avatar
    tjc committed
              gelPanel.add(inSilicoGelPanel);
              frame.validate();
            }
            catch (FileNotFoundException e1)
            {
              // TODO Auto-generated catch block
              e1.printStackTrace();
            }
            catch (IOException e2)
            {
              // TODO Auto-generated catch block
              e2.printStackTrace();
            }
          }
        });
        fileMenu.add(loadExpData);
        fileMenu.addSeparator();
        
    
    tjc's avatar
    tjc committed
        JMenuItem exitMenu = new JMenuItem("Exit");
        exitMenu.addActionListener(new ActionListener()
        {
    
    tjc's avatar
    tjc committed
          public void actionPerformed(ActionEvent e)
          {
    
    tjc's avatar
    tjc committed
            exitApp(f);
    
    tjc's avatar
    tjc committed
          }
    
    tjc's avatar
    tjc committed
        });
        fileMenu.add(exitMenu);
    
    tjc's avatar
    tjc committed
        f.setJMenuBar(menuBar);
    
    tjc's avatar
    tjc committed
      }
    
      /**
       * 
       * @param f
       */
      private void exitApp(JFrame f)
      {
        f.dispose();
    
    tjc's avatar
    tjc committed
        System.exit(0);
    
    tjc's avatar
    tjc committed
      }
    
    
    tjc's avatar
    tjc committed
       * Add mouse lister to highlight bands on the virtual digest when the mouse is
       * over the corresponding feature in the circular plot.
       * 
    
       * @param rd
       * @param dna
       * @param inSilicoGelPanel
       */
    
    tjc's avatar
    tjc committed
      private void addMouseListener(final ReportDetails rd, final DNADraw dna,
                                    final InSilicoGelPanel inSilicoGelPanel)
      {
        final JPopupMenu popup = new JPopupMenu();
    
        final JMenuBar menuBar = dna.createMenuBar();
    
        JMenu[] menus = new JMenu[menuBar.getMenuCount()];
    
    tjc's avatar
    tjc committed
        for (int i = 0; i < menuBar.getMenuCount(); i++)
          menus[i] = menuBar.getMenu(i);
    
        for (int i = 0; i < menus.length; i++)
    
          popup.add(menus[i]);
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
        final JMenuItem openArtemis = new JMenuItem("Open in Artemis...");
        openArtemis.addActionListener(new ActionListener()
        {
    
    tjc's avatar
    tjc committed
          public void actionPerformed(ActionEvent e)
          {
    
    tjc's avatar
    tjc committed
            Range range = null;
            try
    
    tjc's avatar
    tjc committed
            {
    
    tjc's avatar
    tjc committed
              if (lastBlock == null)
                range = new Range(1, dna.getArtemisEntryGroup().getBases()
                    .getLength());
              else
                range = new Range(lastBlock.getBstart(), lastBlock.getBend());
    
    tjc's avatar
    tjc committed
            }
    
    tjc's avatar
    tjc committed
            catch (OutOfRangeException e1)
    
    tjc's avatar
    tjc committed
            {
    
    tjc's avatar
    tjc committed
              e1.printStackTrace();
              return;
            } 
            final ArtemisMain main_window = new ArtemisMain(null);
            main_window.setVisible(false);
            final EntryGroup entryGroup = dna.getArtemisEntryGroup().truncate(
                range);
            final EntryEdit entryEdit = new EntryEdit(entryGroup);
            entryEdit.setVisible(true);
    
    tjc's avatar
    tjc committed
          }
    
    tjc's avatar
    tjc committed
        });
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
        popup.add(openArtemis);
    
    tjc's avatar
    tjc committed
    
        MouseMotionListener mouseMotionListener = new MouseMotionAdapter()
        {
          public void mouseMoved(MouseEvent me)
          {
            List<CutSite> cutSites = rd.cutSites;
            final Block b = dna.getBlockAtLocation(me.getPoint());
            if (b != null && b.isOverMe(me.getX(), me.getY()))
            {
              int bend = b.getBend();
              // int bstart = b.getBstart();
    
              if (bend == rd.length)
              {
                ((CutSite) cutSites.get(0)).setHighlighted(true);
                for (int i = 1; i < cutSites.size(); i++)
                  ((CutSite) cutSites.get(i)).setHighlighted(false);
              }
              else
              {
                for (int i = 0; i < cutSites.size(); i++)
                {
                  CutSite cutSite = (CutSite) cutSites.get(i);
                  if (bend == cutSite.getFivePrime())
                    cutSite.setHighlighted(true);
                  else
                    cutSite.setHighlighted(false);
                }
              }
    
    tjc's avatar
    tjc committed
              for (int i = 0; i < cutSites.size(); i++)
              {
                CutSite cutSite = (CutSite) cutSites.get(i);
                cutSite.setHighlighted(false);
              }
    
            }
            inSilicoGelPanel.repaint();
    
    tjc's avatar
    tjc committed
          }
    
        };
        dna.addMouseMotionListener(mouseMotionListener);
    
    tjc's avatar
    tjc committed
    
        MouseListener popupListener = new MouseAdapter()
        {
          public void mousePressed(MouseEvent e)
    
          {
            maybeShowPopup(e);
          }
    
    tjc's avatar
    tjc committed
    
          public void mouseReleased(MouseEvent e)
    
          {
            maybeShowPopup(e);
          }
    
    tjc's avatar
    tjc committed
    
    
          private void maybeShowPopup(MouseEvent e)
          {
    
    tjc's avatar
    tjc committed
            if (e.isPopupTrigger())
    
    tjc's avatar
    tjc committed
            {
    
    tjc's avatar
    tjc committed
              lastBlock = dna.getBlockAtLocation(e.getPoint());
    
              if (lastBlock == null)
                openArtemis.setText("Open in Artemis...");
              else
                openArtemis.setText("Open in Artemis [" + lastBlock.getBstart()
                    + ".." + lastBlock.getBend() + "]...");
    
              popup.show(e.getComponent(), e.getX(), e.getY());
    
    tjc's avatar
    tjc committed
            }
    
          }
        };
        dna.addMouseListener(popupListener);
    
    tjc's avatar
    tjc committed
    
        MouseMotionListener gelMouseMotionListener = new MouseMotionAdapter()
        {
          Block lastBlock = null;
          Color lastBlockColour = null;
          public void mouseMoved(MouseEvent me)
          {
            final FragmentBand band = inSilicoGelPanel.getBandAtLocation(me.getPoint());
            if(lastBlock != null)
            {
              lastBlock.setColour(lastBlockColour);
              dna.repaint();
            }
            if(band != null)
            {
              CutSite cs = band.bandCutSite;
              lastBlock = dna.getBlockAtBasePosition(cs.getFivePrime());
              lastBlockColour = lastBlock.getColour();
              lastBlock.setColour(Color.GREEN);
              dna.repaint();
            }
            else
              lastBlock = null;
          }
        };
        inSilicoGelPanel.addMouseMotionListener(gelMouseMotionListener);
    
    tjc's avatar
    tjc committed
    
      /**
       * Create a DNADraw panel from a file
    
    tjc's avatar
    tjc committed
       * 
    
    tjc's avatar
    tjc committed
       * @param dna_current
       * @return
       */
    
      private static EntryGroup getEntryGroupFromFile(File fileName)
    
    tjc's avatar
    tjc committed
      {
        Options.getOptions();
    
    tjc's avatar
    tjc committed
        final EntryGroup entryGroup;
    
    
    tjc's avatar
    tjc committed
        try
        {
    
    tjc's avatar
    tjc committed
          Entry entry = getEntry(fileName);
    
          if (entry.getBases() != null)
            entryGroup = new SimpleEntryGroup(entry.getBases());
          else
            entryGroup = new SimpleEntryGroup();
    
    tjc's avatar
    tjc committed
          entryGroup.add(entry);
          return entryGroup;
        }
    
    tjc's avatar
    tjc committed
        catch (OutOfRangeException e)
    
    tjc's avatar
    tjc committed
        {
          e.printStackTrace();
        }
    
    tjc's avatar
    tjc committed
        catch (NoSequenceException e)
    
    tjc's avatar
    tjc committed
        {
    
    tjc's avatar
    tjc committed
          JOptionPane.showMessageDialog(null, "No sequence found!",
    
    tjc's avatar
    tjc committed
              "Sequence Missing", JOptionPane.WARNING_MESSAGE);
        }
        return null;
      }
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
      /**
    
    tjc's avatar
    tjc committed
       * Return an Artemis entry from a file
       * 
    
    tjc's avatar
    tjc committed
       * @param entryFileName
       * @param entryGroup
       * @return
       * @throws NoSequenceException
    
    tjc's avatar
    tjc committed
       * @throws OutOfRangeException
    
    tjc's avatar
    tjc committed
       */
    
    tjc's avatar
    tjc committed
      private static Entry getEntry(final File entryFileName)
          throws NoSequenceException, OutOfRangeException
    
    tjc's avatar
    tjc committed
      {
    
    
    tjc's avatar
    tjc committed
        if (entryFileName == null)
        {
          // no file - prompt for a file
          uk.ac.sanger.artemis.components.FileDialogEntrySource entrySource = new uk.ac.sanger.artemis.components.FileDialogEntrySource(
              null, null);
    
    tjc's avatar
    tjc committed
          Entry entry = entrySource.getEntry(true);
          return entry;
    
    tjc's avatar
    tjc committed
        }
    
        final Document entry_document = DocumentFactory.makeDocument(entryFileName
            .getAbsolutePath());
        final EntryInformation artemis_entry_information = Options
            .getArtemisEntryInformation();
    
        final uk.ac.sanger.artemis.io.Entry new_embl_entry = EntryFileDialog
            .getEntryFromFile(null, entry_document, artemis_entry_information,
                false);
    
        if (new_embl_entry == null) // the read failed
    
    tjc's avatar
    tjc committed
          return null;
    
        Entry entry = null;
        try
        {
          entry = new Entry(new_embl_entry);
    
    tjc's avatar
    tjc committed
        }
        catch (OutOfRangeException e)
    
    tjc's avatar
    tjc committed
        {
    
    tjc's avatar
    tjc committed
          new MessageDialog(null, "read failed: one of the features in "
              + entryFileName + " has an out of range " + "location: "
              + e.getMessage());
    
    tjc's avatar
    tjc committed
        }
        return entry;
      }
    
    tjc's avatar
    tjc committed
    
    
      /**
       * Prompt for the enzyme list.
       * @return
       */
    
      private String promptForEnzymes()
    
    tjc's avatar
    tjc committed
      {
    
        Box yBox = Box.createVerticalBox();
        JTextField enzymeList = new JTextField("HincII,hinfI,ppiI,hindiii");
        yBox.add(enzymeList);
    
    tjc's avatar
    tjc committed
        JCheckBox methylationCheckBox = new JCheckBox(
            "RE sites will not match methylated bases", methylation);
    
        yBox.add(methylationCheckBox);
        
        JOptionPane.showMessageDialog(null, yBox, "Enzyme", JOptionPane.QUESTION_MESSAGE);
        methylation = methylationCheckBox.isSelected();
        return enzymeList.getText().trim();
    
    tjc's avatar
    tjc committed
      }
    
    
    tjc's avatar
    tjc committed
      public static void main(String args[])
      {
        if (System.getProperty("EMBOSS_ROOT") == null)
        {
          String embossRoot = JOptionPane.showInputDialog(null,
              "Input the EMBOSS installation directory", "/usr/local/emboss");
          System.setProperty("EMBOSS_ROOT", embossRoot.trim());
        }
    
        String enzymes = null;
        CircularGenomeController controller = new CircularGenomeController();
    
        boolean methylation = false;
    
    tjc's avatar
    tjc committed
        try
        {
          List<File> fileNames = null;
    
          List<File> restrictOutputs = null;
    
    tjc's avatar
    tjc committed
          if (args != null && args.length > 0)
          {
            if (args.length == 1)
            {
    
              if(args[0].startsWith("-h"))
              {
                System.out.println("-h\t\tshow help");
                System.out.println("-enz\t\tcomma separated list of digest enzymes (optional)");
                System.out.println("-seq\t\tspace separated list of sequences (optional)");
    
                System.out.println(
                    "-methylation\tif this is set then RE recognition sites "+
                    "will not match methylated bases.");
    
                System.out.println(
                    "-restrict\tspace separated lists of EMBOSS restrict output "+
                    "in the same order as the sequences (optional).");
                System.exit(0); 
              }
    
    tjc's avatar
    tjc committed
              fileNames = new Vector<File>();
              fileNames.add(new File(args[0]));
            }
    
            for (int i = 0; i < args.length; i++)
            {
              if (args[i].startsWith("-enz"))
                enzymes = args[i + 1];
    
              else if (args[i].startsWith("-meth"))
                methylation = true;
    
    tjc's avatar
    tjc committed
              else if (args[i].startsWith("-seq"))
              {
                if (fileNames == null)
                  fileNames = new Vector<File>();
    
                
                for(int j = i + 1; j < args.length; j++)
                {
                  if(args[j].startsWith("-"))
                    break;
                  fileNames.add(new File(args[j]));
                }
              }
              else if (args[i].startsWith("-restrict"))
              {
                if (restrictOutputs == null)
                  restrictOutputs = new Vector<File>();
                
                for(int j = i + 1; j < args.length; j++)
                {
                  if(args[j].startsWith("-"))
                    break;
                  restrictOutputs.add(new File(args[j]));
                }
    
    tjc's avatar
    tjc committed
              }
            }
          }
    
          controller.setup(enzymes, fileNames, restrictOutputs, methylation);
    
    tjc's avatar
    tjc committed
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }
    
    tjc's avatar
    tjc committed
    
    };