3 import jalview.analysis.AAFrequency;
4 import jalview.analysis.Conservation;
5 import jalview.datamodel.AlignmentAnnotation;
6 import jalview.datamodel.AlignmentI;
7 import jalview.datamodel.Annotation;
8 import jalview.datamodel.ProfilesI;
9 import jalview.datamodel.SequenceI;
11 public class AnnotationUtil
14 public static AlignmentAnnotation getConsensusAnnotationFromFile(
17 AlignmentI alignment = readAlignmentFile(file);
18 // AlignFrame af = new AlignFrame(alignment, 5, 5);
19 // af.setVisible(false);
20 // AlignmentAnnotation consensus = af.getViewport()
21 // .getAlignmentConsensusAnnotation();
23 // System.out.println(consensus);
25 SequenceI[] alignmentSeqs = alignment.getSequencesArray();
26 int width = alignment.getWidth();
27 long nseq = alignmentSeqs.length;
28 boolean ignoreGapsConsensus = true;
29 boolean showSequenceLogo = false;
31 AlignmentAnnotation consensusAnnotation = new AlignmentAnnotation(
33 "PID", new Annotation[1], 0f, 100f,
34 AlignmentAnnotation.BAR_GRAPH);
35 consensusAnnotation.hasText = true;
36 consensusAnnotation.autoCalculated = true;
38 alignment.addAnnotation(consensusAnnotation);
39 ProfilesI hconsensus = AAFrequency.calculate(alignmentSeqs, width, 0,
43 AAFrequency.completeConsensus(consensusAnnotation, hconsensus,
44 hconsensus.getStartColumn(), hconsensus.getEndColumn() + 1,
45 ignoreGapsConsensus, showSequenceLogo, nseq);
47 System.out.println(">>>>> Consensus Annotation : "
48 + consensusAnnotation);
49 return consensusAnnotation;
52 public static AlignmentAnnotation getConservationAnnotationFromFile(
53 String file, SequenceI seqRef)
55 AlignmentAnnotation conservationAnnotation = null;
56 int foundAnnotCount = seqRef.getAnnotation().length;
57 if (seqRef != null && foundAnnotCount < 3)
59 AlignmentI alignment = readAlignmentFile("/Users/tcnofoegbu/Desktop/query.jal");
60 // AlignmentI alignment = readAlignmentFile(file);
61 // ColumnSelection cs = new ColumnSelection();
62 // SequenceI querySeq = alignment.getSequenceAt(0);
63 // cs.hideInsertionsFor(querySeq);
64 // AlignViewport av = new AlignViewport(alignment);
65 // av.setColumnSelection(cs);
67 // alignment = av.getAlignment();
68 int alWidth = alignment.getWidth();
69 int ConsPercGaps = 25;
71 AlignmentAnnotation quality = new AlignmentAnnotation("Quality",
72 "Alignment Quality based on Blosum62 scores",
73 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
74 quality.hasText = true;
75 quality.autoCalculated = true;
77 conservationAnnotation = new AlignmentAnnotation("Conservation",
78 "PID", new Annotation[1], 0f, 100f,
79 AlignmentAnnotation.BAR_GRAPH);
80 conservationAnnotation.hasText = true;
81 conservationAnnotation.autoCalculated = true;
82 alignment.addAnnotation(conservationAnnotation);
83 Conservation cons = Conservation.calculateConservation("All",
84 alignment.getSequences(), 0, alWidth - 1, false,
85 ConsPercGaps, quality != null);
86 cons.completeAnnotations(conservationAnnotation, quality, 0, alWidth);
87 System.out.println(">>>");
89 conservationAnnotation.createSequenceMapping(seqRef, 1, true);
90 seqRef.addAlignmentAnnotation(conservationAnnotation);
92 // conservationAnnotation.createSequenceMapping(
93 // seqRef.getDatasetSequence(), 1, true);
94 // seqRef.getDatasetSequence().addAlignmentAnnotation(
95 // conservationAnnotation);
98 return conservationAnnotation;
101 private static AlignmentI readAlignmentFile(String f)
103 System.out.println("Reading file: " + f);
106 FormatAdapter rf = new FormatAdapter();
107 DataSourceType protocol = AppletFormatAdapter.checkProtocol(f);
108 AlignmentI al = rf.readFile(f, protocol,
109 new IdentifyFile().identify(f, protocol));
111 } catch (Exception e)
118 public static void main(String[] args)
120 // getConservationAnnotationFromFile("http://www.sbg.bio.ic.ac.uk/phyre2/phyre2_output/cd1b897af035cdf5/query.jal");
121 getConsensusAnnotationFromFile("http://www.sbg.bio.ic.ac.uk/phyre2/phyre2_output/cd1b897af035cdf5/query.jal");