Search in sources :

Example 1 with ImportException

use of dr.evolution.io.Importer.ImportException in project beast-mcmc by beast-dev.

the class TreeSpaceLogger method readTrees.

private void readTrees(String filename) {
    try {
        FileReader fr = new FileReader(new File(filename));
        BufferedReader br = new BufferedReader(fr);
        String line;
        List<Tree> trees = new ArrayList<Tree>();
        List<Integer> islands = new ArrayList<Integer>();
        while ((line = br.readLine()) != null) {
            // read trees
            String[] tokens = line.split("\\s++");
            NewickImporter importer = new NewickImporter(line);
            Tree t = importer.importNextTree();
            trees.add(t);
            islands.add(Integer.parseInt(tokens[0]));
        }
        br.close();
        fr.close();
        this.trees = new String[trees.size()];
        this.islands = new int[trees.size()];
        int maxIsland = 0;
        for (int i = 0; i < trees.size(); i++) {
            Tree tree = trees.get(i);
            String newick = TreeUtils.uniqueNewick(tree, tree.getRoot());
            this.trees[i] = newick;
            this.islands[i] = islands.get(i) - 1;
            if (islands.get(i) > maxIsland) {
                maxIsland = islands.get(i);
            }
        }
        transitions = new int[trees.size()][trees.size()];
        steps = new int[trees.size()][trees.size()];
        islandTransitions = new int[maxIsland][maxIsland];
        islandDwellTimes = new int[maxIsland];
    // pathes = new HashMap[trees.size()][trees.size()];
    // for (int i = 0; i < trees.size(); i++) {
    // for (int j = 0; j < trees.size(); j++) {
    // pathes[i][j] = new HashMap<String, Integer>();
    // }
    // }
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ImportException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ArrayList(java.util.ArrayList) ImportException(dr.evolution.io.Importer.ImportException) NewickImporter(dr.evolution.io.NewickImporter) Tree(dr.evolution.tree.Tree)

Example 2 with ImportException

use of dr.evolution.io.Importer.ImportException in project beast-mcmc by beast-dev.

the class DataModelImporter method importFastaFile.

// FASTA
private void importFastaFile(File file, DateGuesser guesser, Map dataModel) throws IOException, ImportException {
    try {
        FileReader reader = new FileReader(file);
        FastaImporter importer = new FastaImporter(reader, Nucleotides.INSTANCE);
        Alignment alignment = importer.importAlignment();
        reader.close();
        setData(dataModel, guesser, file.getName(), alignment, null, alignment, null, null, null);
    } catch (ImportException e) {
        throw new ImportException(e.getMessage());
    } catch (IOException e) {
        throw new IOException(e.getMessage());
    }
}
Also used : ImportException(dr.evolution.io.Importer.ImportException) Alignment(dr.evolution.alignment.Alignment) SimpleAlignment(dr.evolution.alignment.SimpleAlignment) FastaImporter(dr.evolution.io.FastaImporter)

Example 3 with ImportException

use of dr.evolution.io.Importer.ImportException in project beast-mcmc by beast-dev.

the class BeautiFrame method importFiles.

private void importFiles(File[] files) {
    for (File file : files) {
        if (file == null || file.getName().equals("")) {
            JOptionPane.showMessageDialog(this, "Invalid file name", "Invalid file name", JOptionPane.ERROR_MESSAGE);
        } else {
            try {
                BEAUTiImporter beautiImporter = new BEAUTiImporter(this, options);
                beautiImporter.importFromFile(file);
                setDirty();
            // } catch (FileNotFoundException fnfe) {
            // JOptionPane.showMessageDialog(this, "Unable to open file: File not found",
            // "Unable to open file", JOptionPane.ERROR_MESSAGE);
            } catch (IOException ioe) {
                JOptionPane.showMessageDialog(this, "File I/O Error unable to read file: " + ioe.getMessage(), "Unable to read file", JOptionPane.ERROR_MESSAGE);
                ioe.printStackTrace();
            // there may be other files in the list so don't return
            // return;
            } catch (MissingBlockException ex) {
                JOptionPane.showMessageDialog(this, "TAXON, DATA or CHARACTERS block is missing in Nexus file: " + ex, "Missing Block in Nexus File", JOptionPane.ERROR_MESSAGE);
                ex.printStackTrace();
            } catch (ImportException ime) {
                JOptionPane.showMessageDialog(this, "Error parsing imported file: " + ime, "Error reading file", JOptionPane.ERROR_MESSAGE);
                ime.printStackTrace();
            } catch (JDOMException jde) {
                JOptionPane.showMessageDialog(this, "Error parsing imported file: " + jde, "Error reading file", JOptionPane.ERROR_MESSAGE);
                jde.printStackTrace();
            }
        }
    }
    if (!options.hasIdenticalTaxa()) {
        // need this to refresh panels otherwise it will throw exception
        setAllOptions();
        dataPanel.selectAll();
        dataPanel.unlinkTreeModels();
    }
    setAllOptions();
}
Also used : ImportException(dr.evolution.io.Importer.ImportException) JDOMException(org.jdom.JDOMException) BEAUTiImporter(dr.app.beauti.util.BEAUTiImporter) MissingBlockException(dr.evolution.io.NexusImporter.MissingBlockException)

Example 4 with ImportException

use of dr.evolution.io.Importer.ImportException in project beast-mcmc by beast-dev.

the class DataModelImporter method checkTaxonList.

private void checkTaxonList(TaxonList taxonList, DateGuesser guesser) throws ImportException {
    // check the taxon names for invalid characters
    boolean foundAmp = false;
    for (Taxon taxon : taxonList) {
        String name = taxon.getId();
        if (name.indexOf('&') >= 0) {
            foundAmp = true;
        }
    }
    if (foundAmp) {
        throw new ImportException("One or more taxon names include an illegal character ('&').\n" + "These characters will prevent BEAST from reading the resulting XML file.\n\n" + "Please edit the taxon name(s) before reloading the data file.");
    }
    if (guesser != null) {
        guesser.guessDates(taxonList);
    } else {
        // make sure they all have dates...
        for (int i = 0; i < taxonList.getTaxonCount(); i++) {
            if (taxonList.getTaxonAttribute(i, "date") == null) {
                Date origin = new Date(0);
                dr.evolution.util.Date date = dr.evolution.util.Date.createTimeSinceOrigin(0.0, Units.Type.YEARS, origin);
                taxonList.getTaxon(i).setAttribute("date", date);
            }
        }
    }
}
Also used : ImportException(dr.evolution.io.Importer.ImportException) java.util(java.util) Taxon(dr.evolution.util.Taxon)

Example 5 with ImportException

use of dr.evolution.io.Importer.ImportException in project beast-mcmc by beast-dev.

the class BEAUTiImporter method importMicroSatFile.

// micro-sat
private void importMicroSatFile(File file) throws IOException, ImportException {
    try {
        Reader reader = new FileReader(file);
        BufferedReader bufferedReader = new BufferedReader(reader);
        MicroSatImporter importer = new MicroSatImporter(bufferedReader);
        List<Patterns> microsatPatList = importer.importPatterns();
        Taxa unionSetTaxonList = importer.getUnionSetTaxonList();
        Microsatellite microsatellite = importer.getMicrosatellite();
        // options.allowDifferentTaxa = importer.isHasDifferentTaxon();
        bufferedReader.close();
        PartitionSubstitutionModel substModel = new PartitionSubstitutionModel(options, microsatPatList.get(0).getId());
        substModel.setMicrosatellite(microsatellite);
        for (Patterns patterns : microsatPatList) {
            setData(file.getName(), unionSetTaxonList, patterns, substModel, null);
        }
        // has to call after data is imported
        options.microsatelliteOptions.initModelParametersAndOpererators();
    } catch (ImportException e) {
        throw new ImportException(e.getMessage());
    } catch (IOException e) {
        throw new IOException(e.getMessage());
    }
}
Also used : ImportException(dr.evolution.io.Importer.ImportException) Taxa(dr.evolution.util.Taxa) Microsatellite(dr.evolution.datatype.Microsatellite) MicroSatImporter(dr.evolution.io.MicroSatImporter) Patterns(dr.evolution.alignment.Patterns)

Aggregations

ImportException (dr.evolution.io.Importer.ImportException)14 SimpleAlignment (dr.evolution.alignment.SimpleAlignment)7 Tree (dr.evolution.tree.Tree)5 Alignment (dr.evolution.alignment.Alignment)4 TaxonList (dr.evolution.util.TaxonList)4 MissingBlockException (dr.evolution.io.NexusImporter.MissingBlockException)3 Taxa (dr.evolution.util.Taxa)3 JDOMException (org.jdom.JDOMException)3 FastaImporter (dr.evolution.io.FastaImporter)2 NewickImporter (dr.evolution.io.NewickImporter)2 NexusBlock (dr.evolution.io.NexusImporter.NexusBlock)2 Taxon (dr.evolution.util.Taxon)2 IOException (java.io.IOException)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 BeagleSequenceSimulator (dr.app.beagle.tools.BeagleSequenceSimulator)1 Partition (dr.app.beagle.tools.Partition)1 BEAUTiImporter (dr.app.beauti.util.BEAUTiImporter)1 ArgumentException (dr.app.util.Arguments.ArgumentException)1 Patterns (dr.evolution.alignment.Patterns)1