/* Copyright (c) 2011 Peter Troshin * * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0 * * This library is free software; you can redistribute it and/or modify it under the terms of the * Apache License version 2 as published by the Apache Software Foundation * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache * License for more details. * * A copy of the license is in apache_license.txt. It is also available here: * @see: http://www.apache.org/licenses/LICENSE-2.0.txt * * Any republication or derived work distributed in source code form * must include this copyright and license notice. */ package compbio.pipeline._jpred; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashSet; import java.util.List; import java.util.Set; import compbio.data.sequence.FastaSequence; import compbio.data.sequence.SequenceUtil; public class Pairwise { private final List sequences; final Set pscores; public Pairwise(List sequences) { this.sequences = sequences; pscores = new HashSet(); } void compare() { for (int i = 0; i < sequences.size(); i++) { FastaSequence seq1 = sequences.get(i); System.out.println(seq1.getId()); for (int j = i+1; j < sequences.size(); j++) { FastaSequence seq2 = sequences.get(j); PScore pscore = new PScore(); pscore.name = seq1.getId(); pscore.otherName = seq2.getId(); pscores.add(pscore); compare(pscore, seq1.getSequence(), seq2.getSequence()); } } } void compare(PScore pscore, String seq1, String seq2) { char[] chars1 = seq1.trim().toUpperCase().toCharArray(); char[] chars2 = seq2.trim().toUpperCase().toCharArray(); if(chars1.length != chars2.length) { throw new IllegalArgumentException("Different lenght sequence are provided but same expected! \n Sequence 1: \n" + pscore.name+ "\n Length:"+chars1.length +"\n "+ "Sequence 2: \n " + pscore.otherName + " \n Lenght: " + chars2.length ); } compare(pscore, chars1, chars2); } void compare(PScore pscore, char[] seq1, char[] seq2) { int sameResedue = 0; for (int i = 0; i < seq1.length; i++) { if(seq1[i]==seq2[i]) { sameResedue++; } } pscore.score = (double)sameResedue /seq1.length; System.out.println(pscore.score*100); } public static final void main(String[] args) throws FileNotFoundException, IOException { File in = new File(args[0]); List fslist = SequenceUtil.readFasta(new BufferedInputStream(new FileInputStream(in))); Pairwise pair = new Pairwise(fslist); pair.compare(); System.out.println(pair.pscores); } }