source: trunk/autoquest-plugin-alignment/src/main/java/de/ugoe/cs/autoquest/plugin/alignment/commands/CMDdeleteShortSequences.java @ 1544

Last change on this file since 1544 was 1447, checked in by rkrimmel, 10 years ago

Added new command to delete short sequences up to a limit

File size: 3.0 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.plugin.alignment.commands;
16
17import java.util.Collection;
18import java.util.Iterator;
19import java.util.LinkedList;
20import java.util.List;
21import java.util.logging.Level;
22
23import de.ugoe.cs.autoquest.eventcore.Event;
24import de.ugoe.cs.autoquest.plugin.alignment.SmithWaterman;
25import de.ugoe.cs.autoquest.plugin.alignment.seqgen.SimpleSequenceGenerator;
26import de.ugoe.cs.autoquest.plugin.alignment.substitution.NearbySubstitutionMatrix;
27import de.ugoe.cs.autoquest.plugin.alignment.substitution.ObjectDistanceSubstitionMatrix;
28import de.ugoe.cs.util.console.Command;
29import de.ugoe.cs.util.console.Console;
30import de.ugoe.cs.util.console.GlobalDataContainer;
31
32/**
33 * <p>
34 * Command to generate a binary alignment of two sequences
35 * </p>
36 *
37 * @author Ralph Krimmel
38 * @version 1.0
39 */
40public class CMDdeleteShortSequences implements Command {
41
42        /*
43         * (non-Javadoc)
44         *
45         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
46         */
47        @SuppressWarnings("unchecked")
48        public void run(List<Object> parameters) {
49                String sequencesName = "sequences";
50                int delcount = 0;
51                int limit = 10;
52                try {
53                        sequencesName = (String) parameters.get(0);
54                        if (parameters.size() > 1) {
55                                try {
56                                        limit = Integer.parseInt((String) parameters.get(1));
57                                        }
58                                catch (NumberFormatException e)
59                                {
60                                        Console.traceln(Level.WARNING,"Parameter not an integer. Using the default value.");
61                                }
62                        }
63                } catch (Exception e) {
64                        throw new IllegalArgumentException();
65                }
66
67                Collection<List<Event>> sequences = new LinkedList<List<Event>>();
68                Object obj = GlobalDataContainer.getInstance().getData(sequencesName);
69                if (obj.getClass().equals(sequences.getClass())) {
70                        sequences = (Collection<List<Event>>) obj;
71                }
72
73                if (sequences != null) {
74                        Console.println("Number of sequences: " + sequences.size());
75                        Iterator<List<Event>> iter = sequences.iterator();
76                        while(iter.hasNext()) {
77                            if (iter.next().size() < limit) {
78                                iter.remove();
79                                delcount++;
80                            }
81                        }
82                       
83                        Console.traceln(Level.INFO, "Deleted "+ delcount + " short sequences from " + sequencesName);
84                }
85        }
86
87        /*
88         * (non-Javadoc)
89         *
90         * @see de.ugoe.cs.util.console.Command#help()
91         */
92        @Override
93        public String help() {
94                return "deleteShortSequences <sequence name>";
95        }
96
97}
Note: See TracBrowser for help on using the repository browser.