average Hydrophobicity - Java java.lang

Java examples for java.lang:Math Trigonometric Function

Description

average Hydrophobicity

Demo Code


//package com.java2s;
import java.util.HashMap;
import java.util.Map;

public class Main {
    private static final Map<Character, Double> scale = new HashMap<>(40);

    public static double averageHydrophobicity(String sequence, int index,
            int windowSize) {
        float result = 0F;
        if ((index >= 0) && (index < sequence.length())) {
            float sum = 0F;
            int halfSize = (int) Math.floor(windowSize / 2.0D);
            int residueCount = 0;

            int start = Math.max(0, index - halfSize);
            int end = Math.min(sequence.length(), index + halfSize + 1);
            for (int i = start; i < end; ++i) {
                char residue = sequence.charAt(i);
                double hydrophobicity = ((Double) scale.get(Character
                        .valueOf(residue))).doubleValue();
                sum = (float) (sum + hydrophobicity);
                ++residueCount;/* w  w w  . j  a v  a 2  s  . c  o m*/
            }
            result = sum / residueCount;
        }

        return result;
    }
}

Related Tutorials