-
- /**
- * Method to calculate a 'base pair consensus row', very similar
- * to nucleotide consensus but takes into account a given structure
- * @param sequences
- * @param start
- * @param end
- * @param result
- * @param profile
- * @param rnaStruc
- */
- public static final void calculate(SequenceI[] sequences, int start,
- int end, Hashtable[] result, boolean profile, AlignmentAnnotation rnaStruc){
- //TODO Consider to use AlignmentAnnotation instead of structure string
-
- Hashtable residueHash;
-
- char[] seq, struc=rnaStruc.getRNAStruc().toCharArray();
- SequenceFeature[] rna =rnaStruc._rnasecstr;
- char c,s,cEnd;
- int count,nonGap,i,j,jSize = sequences.length;
- int[] values = new int[255];
- float percentage;
-
-
- for (i = start; i < end; i++) //foreach column
- {
- residueHash = new Hashtable();
- for (j = 0; j < jSize; j++) //foreach row
- {
- if (sequences[j]==null)
- {
- System.err.println("WARNING: Consensus skipping null sequence - possible race condition.");
- continue;
- }
- seq = sequences[j].getSequence();
- if (seq.length > i)
- {
- c = seq[i];
- s = struc[i];
- nonGap=0;
-
- //standard representation for gaps in sequence and structure
- if (c == '.' || c == ' ')
- {
- c = '-';
- }
- if (s == '.' || s == ' ')
- {
- s = '-';
- }
-
- if (c == '-')
- {
- values['-']++;
- continue;
- }
- if(s == '-'){
- values['-']++;
- continue;
- }
- nonGap++;
- cEnd=seq[rna[i].getEnd()];
- if(checkBpType(c,cEnd)){
- values['H']++; //H means it's a helix (structured)
- }
- }
- }
- /*UPDATE this for new values
- if (profile)
- {
- residueHash.put(PROFILE, new int[][]
- { values, new int[]
- { jSize, nongap } });
- }
- */
-
- count=values['H'];
-
- percentage = ((float) count * 100) / (float) jSize;
- residueHash.put(PID_GAPS, new Float(percentage));
-
- //percentage = ((float) count * 100) / (float) nongap;
- //residueHash.put(PID_NOGAPS, new Float(percentage));
- result[i] = residueHash;
-
- }
- }
-
-
- /**
- * Method to check if a base-pair is a canonical or a wobble bp
- * @param up 5' base
- * @param down 3' base
- * @return True if it is a canonical/wobble bp
- */
- public static boolean checkBpType(char up, char down){
- if(up>'Z'){up-=32;}
- if(down>'Z'){down-=32;}
-
- switch (up){
- case 'A':
- switch (down){
- case 'T': return true;
- case 'U': return true;
- }
- break;
- case 'C':
- switch (down){
- case 'G': return true;
- }
- break;
- case 'T':
- switch (down){
- case 'A': return true;
- case 'G': return true;
- }
- break;
- case 'G':
- switch (down){
- case 'C': return true;
- case 'T': return true;
- case 'U': return true;
- }
- break;
- case 'U':
- switch (down){
- case 'A': return true;
- case 'G': return true;
- }
- break;
- }
- return false;
- }
-