|
| 1 | +package demo; |
| 2 | + |
| 3 | +import java.net.URL; |
| 4 | + |
| 5 | + |
| 6 | +import org.biojava3.alignment.Alignments; |
| 7 | +import org.biojava3.alignment.SimpleGapPenalty; |
| 8 | +import org.biojava3.alignment.SubstitutionMatrixHelper; |
| 9 | +import org.biojava3.alignment.Alignments.PairwiseSequenceAlignerType; |
| 10 | +import org.biojava3.alignment.template.GapPenalty; |
| 11 | +import org.biojava3.alignment.template.PairwiseSequenceAligner; |
| 12 | +import org.biojava3.alignment.template.SequencePair; |
| 13 | +import org.biojava3.alignment.template.SubstitutionMatrix; |
| 14 | +import org.biojava3.core.sequence.ProteinSequence; |
| 15 | +import org.biojava3.core.sequence.compound.AminoAcidCompound; |
| 16 | +import org.biojava3.core.sequence.io.FastaReaderHelper; |
| 17 | + |
| 18 | +public class DemoAlignProteins { |
| 19 | + |
| 20 | + public static void main(String[] args) { |
| 21 | + |
| 22 | + try { |
| 23 | + String uniprotID1 = "P69905"; |
| 24 | + String uniprotID2 = "P68871"; |
| 25 | + |
| 26 | + ProteinSequence s1 = getSequenceForId(uniprotID1); |
| 27 | + ProteinSequence s2 = getSequenceForId(uniprotID2); |
| 28 | + |
| 29 | + SubstitutionMatrix<AminoAcidCompound> matrix = SubstitutionMatrixHelper.getBlosum65(); |
| 30 | + |
| 31 | + GapPenalty penalty = new SimpleGapPenalty(); |
| 32 | + |
| 33 | + short gop = 8; |
| 34 | + short extend = 1; |
| 35 | + penalty.setOpenPenalty(gop); |
| 36 | + penalty.setExtensionPenalty(extend); |
| 37 | + |
| 38 | + |
| 39 | + PairwiseSequenceAligner<ProteinSequence, AminoAcidCompound> smithWaterman = |
| 40 | + Alignments.getPairwiseAligner(s1, s2, PairwiseSequenceAlignerType.LOCAL, penalty, matrix); |
| 41 | + |
| 42 | + SequencePair<ProteinSequence, AminoAcidCompound> pair = smithWaterman.getPair(); |
| 43 | + |
| 44 | + |
| 45 | + System.out.println(pair.toString(60)); |
| 46 | + |
| 47 | + } catch (Exception e){ |
| 48 | + e.printStackTrace(); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + private static ProteinSequence getSequenceForId(String uniProtId) throws Exception { |
| 53 | + URL uniprotFasta = new URL(String.format("http://www.uniprot.org/uniprot/%s.fasta", uniProtId)); |
| 54 | + ProteinSequence seq = FastaReaderHelper.readFastaProteinSequence(uniprotFasta.openStream()).get(uniProtId); |
| 55 | + System.out.printf("id : %s %s%n%s%n", uniProtId, seq, seq.getOriginalHeader()); |
| 56 | + return seq; |
| 57 | + } |
| 58 | + |
| 59 | +} |
0 commit comments