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 |
|
---|
15 | package de.ugoe.cs.autoquest.plugin.alignment.commands;
|
---|
16 |
|
---|
17 | import java.util.ArrayList;
|
---|
18 | import java.util.Collection;
|
---|
19 | import java.util.Collections;
|
---|
20 | import java.util.Comparator;
|
---|
21 | import java.util.Iterator;
|
---|
22 | import java.util.LinkedList;
|
---|
23 | import java.util.List;
|
---|
24 | import java.util.logging.Level;
|
---|
25 |
|
---|
26 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
27 | import de.ugoe.cs.autoquest.plugin.alignment.SmithWaterman;
|
---|
28 | import de.ugoe.cs.autoquest.plugin.alignment.seqgen.SimpleSequenceGenerator;
|
---|
29 | import de.ugoe.cs.autoquest.plugin.alignment.substitution.NearbySubstitutionMatrix;
|
---|
30 | import de.ugoe.cs.autoquest.plugin.alignment.substitution.ObjectDistanceSubstitionMatrix;
|
---|
31 | import de.ugoe.cs.util.console.Command;
|
---|
32 | import de.ugoe.cs.util.console.Console;
|
---|
33 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * <p>
|
---|
37 | * Command to generate a binary alignment of two sequences
|
---|
38 | * </p>
|
---|
39 | *
|
---|
40 | * @author Ralph Krimmel
|
---|
41 | * @version 1.0
|
---|
42 | */
|
---|
43 | public class CMDsequenceStats implements Command {
|
---|
44 |
|
---|
45 | /*
|
---|
46 | * (non-Javadoc)
|
---|
47 | *
|
---|
48 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
49 | */
|
---|
50 | @SuppressWarnings("unchecked")
|
---|
51 | public void run(List<Object> parameters) {
|
---|
52 | String sequencesName = "sequences";
|
---|
53 | double standarddev = 0.0;
|
---|
54 | double mean = 0;
|
---|
55 | double median = 0;
|
---|
56 | double sum = 0;
|
---|
57 |
|
---|
58 | try {
|
---|
59 | sequencesName = (String) parameters.get(0);
|
---|
60 | } catch (Exception e) {
|
---|
61 | throw new IllegalArgumentException();
|
---|
62 | }
|
---|
63 |
|
---|
64 | Collection<List<Event>> sequences = new LinkedList<List<Event>>();
|
---|
65 | Object obj = GlobalDataContainer.getInstance().getData(sequencesName);
|
---|
66 | if (obj != null) {
|
---|
67 |
|
---|
68 | if (obj.getClass().equals(sequences.getClass())) {
|
---|
69 | sequences = (Collection<List<Event>>) obj;
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 | Console.println("Number of sequences: " + sequences.size());
|
---|
74 | //Calculate the mean size
|
---|
75 | for(Iterator<List<Event>> iter = sequences.iterator();iter.hasNext();) {
|
---|
76 | sum += iter.next().size();
|
---|
77 |
|
---|
78 | }
|
---|
79 | mean = sum/sequences.size();
|
---|
80 |
|
---|
81 |
|
---|
82 | //Calculate the median
|
---|
83 | List<List<Event>> list = new ArrayList<List<Event>>(sequences);
|
---|
84 | Collections.sort(list,new SizeComparator());
|
---|
85 |
|
---|
86 | Console.println("Mean size: " +mean);
|
---|
87 | Console.println("Median size: " + list.get(Math.round(list.size()/2)).size());
|
---|
88 |
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | class SizeComparator implements Comparator<List<Event>> {
|
---|
93 | @Override
|
---|
94 | public int compare(List<Event> a, List<Event> b) {
|
---|
95 | return a.size() < b.size() ? -1 : a.size() == b.size() ? 0 : 1;
|
---|
96 | }
|
---|
97 | }
|
---|
98 | /*
|
---|
99 | * (non-Javadoc)
|
---|
100 | *
|
---|
101 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
102 | */
|
---|
103 | @Override
|
---|
104 | public String help() {
|
---|
105 | return "sequenceStats <sequence name>";
|
---|
106 | }
|
---|
107 |
|
---|
108 | }
|
---|