From 7476d4a39fc5840955b57289b862bf08b8419fd7 Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Thu, 17 May 2012 05:10:38 +0000 Subject: [PATCH] in progress --- .../src/org/forester/application/msa_quality.java | 8 ++++---- forester/java/src/org/forester/msa/MsaMethods.java | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/forester/java/src/org/forester/application/msa_quality.java b/forester/java/src/org/forester/application/msa_quality.java index 0ffd63d..3f3d745 100644 --- a/forester/java/src/org/forester/application/msa_quality.java +++ b/forester/java/src/org/forester/application/msa_quality.java @@ -5,12 +5,13 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; -import java.util.SortedMap; import org.forester.io.parsers.GeneralMsaParser; import org.forester.msa.Msa; import org.forester.msa.MsaMethods; +import org.forester.util.BasicDescriptiveStatistics; import org.forester.util.CommandLineArguments; +import org.forester.util.DescriptiveStatistics; public class msa_quality { @@ -41,10 +42,9 @@ public class msa_quality { } final int end = 2; final int start = 6; + final DescriptiveStatistics stats = new BasicDescriptiveStatistics(); for( int c = start; c <= end; ++c ) { - final SortedMap dist = MsaMethods.calculateResidueDestributionPerColumn( msa, c ); - final char majority_char = ' '; - final int majority_count = 0; + stats.addValue( MsaMethods.calculateIdentityRatio( msa, c ) ); } } } diff --git a/forester/java/src/org/forester/msa/MsaMethods.java b/forester/java/src/org/forester/msa/MsaMethods.java index e252efe..716c843 100644 --- a/forester/java/src/org/forester/msa/MsaMethods.java +++ b/forester/java/src/org/forester/msa/MsaMethods.java @@ -26,7 +26,9 @@ package org.forester.msa; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; @@ -118,9 +120,22 @@ public final class MsaMethods { return BasicMsa.createInstance( seqs ); } - public static SortedMap calculateResidueDestributionPerColumn( final Msa msa, final int c ) { + public static double calculateIdentityRatio( final Msa msa, final int column ) { + final SortedMap dist = calculateResidueDestributionPerColumn( msa, column ); + int majority_count = 0; + final Iterator> it = dist.entrySet().iterator(); + while ( it.hasNext() ) { + final Map.Entry pair = it.next(); + if ( pair.getValue() > majority_count ) { + majority_count = pair.getValue(); + } + } + return ( double ) majority_count / msa.getNumberOfSequences(); + } + + public static SortedMap calculateResidueDestributionPerColumn( final Msa msa, final int column ) { final SortedMap map = new TreeMap(); - for( final Character r : msa.getColumnAt( c ) ) { + for( final Character r : msa.getColumnAt( column ) ) { if ( !map.containsKey( r ) ) { map.put( r, 1 ); } -- 1.7.10.2