| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 
 |  
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
 
import javax.swing.JCheckBox;
import javax.swing.JPanel;
 
 
public class AlignementMap extends JPanel{
 
	ArrayList _mapResults;
	AlignMapParamSet _param; 
	MapMain _parent;
	private static final long serialVersionUID = 49L;
 
	AlignementMap(AlignMapParamSet param, MapMain parent)
	{
		_param = param;
		_parent = parent;
 
		MapCalcul();
	}
 
	private void MapCalcul()
	{
		_mapResults = new ArrayList();
		int period;
 
		System.out.println(System.currentTimeMillis());
		int i = 0 ;
		while( i< 60)
		{
			period = 100;
			ArrayList distribution = createDistribution(period);
			_mapResults.add(distibutionResults(distribution, period));
			i++;
		}
		System.out.println(System.currentTimeMillis());
	}
 
	private ArrayList createDistribution(int period)
	{
		ArrayList genes = _parent.getGeneList();
		ArrayList distribution = new ArrayList();
		for (int i = 0; i< genes.size(); i++)
		{
			int modulo = ((GenePoint)genes.get(i)).getPosition() % period;
			distribution.add(modulo/(double)period);	
		}
 
		return distribution;
	}
 
	private BestAlignementParamSet[] distibutionResults(ArrayList distribution, int period)
	{
		double error = 0.01;
		BestAlignementParamSet[] errorsBA = new BestAlignementParamSet[100];
 
		for (int i = 0; i<99 ; i++)
		{
			score best = BestAlignementfor(distribution, error);
			ArrayList baArea = new ArrayList();
			double pValue = pValue(best._score,_parent.getGeneList().size(), error );
			float phase = (float)(best._position+ error/2);
			baArea.add(new BAAreaParam(_param.getStart(),_param.getEnd(), (float)error, phase, pValue ));
			if (phase > 1) phase = phase - 1;
			errorsBA[i] = new BestAlignementParamSet(period, _param.getStart(), _param.getEnd() ,pValue, false, phase, _param.getStart(), baArea, period+"/"+error);
			error = error + 0.01;
		}
 
		return errorsBA;
	}
 
	private score BestAlignementfor(ArrayList distribution, double error)
	{
		ArrayList sumList = new ArrayList();
		ArrayList scoreList = new ArrayList();
		int sum = 0;
 
		for (int i = 0 ; i< distribution.size(); i++)
		{
			double pos =  (Double)distribution.get(i);
			sumList.add(new score(pos,-1));
			sumList.add(new score(pos - error, 1));
			if (pos <= error)  sum++; // initilization with the gene in the first error window
		}
		Collections.sort(sumList);
		scoreList.add(new score(0, sum));
		double medPosition;
		int max = sum;
		int maxIndice = 0;
		for (int i = 1 ; i < sumList.size(); i ++)
		{
			sum = sum + ((score)sumList.get(i-1))._score;
			medPosition = ((score)sumList.get(i-1))._position +  (((score)sumList.get(i))._position -  ((score)sumList.get(i-1))._position)/2;
			scoreList.add(new score(medPosition, sum));
			if (sum> max)
			{
				max = sum;
				maxIndice = i;
			}
		}
		sum = sum + ((score)sumList.get( sumList.size()-1))._score;
		medPosition = ((score)sumList.get( sumList.size()-1))._position +  (1 -  ((score)sumList.get( sumList.size()-1))._position)/2;
		scoreList.add(new score(medPosition, sum));
		if (sum> max)
		{
			max = sum;
			maxIndice =  sumList.size();
		}
 
		return	(score)scoreList.get(maxIndice);
	}
 
	private double pValue(int nbGenes, int nbGenesIn, double error)
	{
	double logPVal = 0;
 
	double sum = 0;
	for (int i = 1 ; i<= nbGenes; i++)
	{
		sum = sum + i;
	}
	logPVal = sum;
 
	sum = 0;
	for (int i = 1 ; i<= nbGenesIn; i++)
	{
		sum = sum + i;
	}
	logPVal = logPVal - sum;
 
	sum = 0;
	for (int i = 1 ; i<= (nbGenes - nbGenesIn); i++)
	{
		sum = sum + i;
	}
	logPVal = logPVal - sum;
 
	logPVal = logPVal+nbGenesIn* Math.log(error) + (nbGenes - nbGenesIn) * Math.log(1 - error);
	return Math.exp(logPVal);
	}
 
 
	private class score implements Comparable
	{
		double _position;
		int _score;
		score(double position, int score)
		{
			if (position < 0) position = 1 + position;
			_position = position;
			_score = score;
		}
 
		public int compareTo(Object o) {
			return( Double.compare(_position, ((score)o)._position));
		}
	}
} | 
Partager