@@ -5,8 +5,8 @@ title: BioJava:CookBook3:MSA
55How to create a Multiple Sequence Alignment in BioJava
66======================================================
77
8- <java >
98
9+ ``` java
1010package org.biojava.nbio.alignment ;
1111
1212import java.net.URL ; import java.util.ArrayList ; import java.util.List ;
@@ -20,32 +20,32 @@ org.biojava.nbio.core.util.ConcurrencyTools;
2020
2121public class CookbookMSA {
2222
23- ` public static void main(String[] args) { `
24- ` String[] ids = new String[] {"Q21691", "A8WS47", "O48771"}; `
25- ` try { `
26- ` multipleSequenceAlignment(ids); `
27- ` } catch (Exception e){ `
28- ` e.printStackTrace(); `
29- ` } `
30- ` } `
31-
32- ` private static void multipleSequenceAlignment(String[] ids) throws Exception { `
33- ` List ` <ProteinSequence >` lst = new ArrayList ` <ProteinSequence >` (); `
34- ` for (String id : ids) { `
35- ` lst.add(getSequenceForId(id)); `
36- ` } `
37- ` Profile ` <ProteinSequence, AminoAcidCompound>` profile = Alignments.getMultipleSequenceAlignment(lst); `
38- ` System.out.printf("Clustalw:%n%s%n", profile); `
39- ` ConcurrencyTools.shutdown(); `
40- ` } `
41-
42- ` private static ProteinSequence getSequenceForId(String uniProtId) throws Exception { `
43- ` URL uniprotFasta = new URL(String.format(" ` [ ` http://www.uniprot.org/uniprot/%s.fasta ` ] ( http://www.uniprot.org/uniprot/%s.fasta ) ` ", uniProtId)); `
44- ` ProteinSequence seq = FastaReaderHelper.readFastaProteinSequence(uniprotFasta.openStream()).get(uniProtId); `
45- ` System.out.printf("id : %s %s%n%s%n", uniProtId, seq, seq.getOriginalHeader()); `
46- ` return seq; `
47- ` } `
23+ public static void main (String [] args ) {
24+ String [] ids = new String [] {" Q21691" , " A8WS47" , " O48771" };
25+ try {
26+ multipleSequenceAlignment(ids);
27+ } catch (Exception e){
28+ e. printStackTrace();
29+ }
30+ }
31+
32+ private static void multipleSequenceAlignment (String [] ids ) throws Exception {
33+ List<ProteinSequence > lst = new ArrayList<ProteinSequence > ();
34+ for (String id : ids) {
35+ lst. add(getSequenceForId(id));
36+ }
37+ Profile<ProteinSequence , AminoAcidCompound > profile = Alignments . getMultipleSequenceAlignment(lst);
38+ System . out. printf(" Clustalw:%n%s%n" , profile);
39+ ConcurrencyTools . shutdown();
40+ }
41+
42+ private static ProteinSequence getSequenceForId (String uniProtId ) throws Exception {
43+ URL uniprotFasta = new URL (String . format(" http://www.uniprot.org/uniprot/%s.fasta" , uniProtId));
44+ ProteinSequence seq = FastaReaderHelper . readFastaProteinSequence(uniprotFasta. openStream()). get(uniProtId);
45+ System . out. printf(" id : %s %s%n%s%n" , uniProtId, seq, seq. getOriginalHeader());
46+ return seq;
47+ }
4848
4949}
5050
51- </ java >
51+ ```
0 commit comments