From 1a6d20b15b2ba810bc807f76eb44ab1b9cc4482a Mon Sep 17 00:00:00 2001 From: jprocter Date: Sun, 3 Jul 2011 13:05:24 +0100 Subject: [PATCH] groovy scripting examples (JAL-???) --- examples/groovy/annotationsascsv.groovy | 9 ++++++++ examples/groovy/closures.groovy | 5 +++++ examples/groovy/iterateOverAlignments.groovy | 20 +++++++++++++++++ examples/groovy/parseproperties.groovy | 13 +++++++++++ examples/groovy/printtitle.groovy | 12 ++++++++++ examples/groovy/removeFeaturesByGroup.groovy | 31 ++++++++++++++++++++++++++ examples/groovy/stripUniprotPrefixes.groovy | 31 ++++++++++++++++++++++++++ 7 files changed, 121 insertions(+) create mode 100644 examples/groovy/annotationsascsv.groovy create mode 100644 examples/groovy/closures.groovy create mode 100644 examples/groovy/iterateOverAlignments.groovy create mode 100644 examples/groovy/parseproperties.groovy create mode 100644 examples/groovy/printtitle.groovy create mode 100644 examples/groovy/removeFeaturesByGroup.groovy create mode 100644 examples/groovy/stripUniprotPrefixes.groovy diff --git a/examples/groovy/annotationsascsv.groovy b/examples/groovy/annotationsascsv.groovy new file mode 100644 index 0000000..5f0a66a --- /dev/null +++ b/examples/groovy/annotationsascsv.groovy @@ -0,0 +1,9 @@ +// do something groovy in jalview +print "Hello World.\n"; +def alf = Jalview.getAlignframes(); +for (ala in alf) +{ + def alignment = ala.viewport.alignment; + // ala is an jalview.gui.AlignFrame object + print new jalview.io.AnnotationFile().printCSVAnnotations(alignment.getAlignmentAnnotation())+"\n"; +} \ No newline at end of file diff --git a/examples/groovy/closures.groovy b/examples/groovy/closures.groovy new file mode 100644 index 0000000..9e4dd52 --- /dev/null +++ b/examples/groovy/closures.groovy @@ -0,0 +1,5 @@ +writeAnnot = { + new File(it).append(new jalview.io.AnnotationFile().printAnnotations(Jalview.getAlignframes()[0].getViewport().getAlignment().getAlignmentAnnotation(),null,null)) +} + + diff --git a/examples/groovy/iterateOverAlignments.groovy b/examples/groovy/iterateOverAlignments.groovy new file mode 100644 index 0000000..83c4169 --- /dev/null +++ b/examples/groovy/iterateOverAlignments.groovy @@ -0,0 +1,20 @@ +import jalview.analysis.*; +import jalview.datamodel.*; +import jalview.gui.AlignFrame; +import jalview.gui.AlignViewport; + +def af = Jalview.getAlignframes(); + +for (ala in af) +{ + def al = ala.viewport.alignment; + if (al!=null && al.getCodonFrames()!=null) + { + al.getCodonFrames().each { + it.getdnaToProt().each { + it2 -> println it2.fromShifts+"\n" + } + } + } +} + diff --git a/examples/groovy/parseproperties.groovy b/examples/groovy/parseproperties.groovy new file mode 100644 index 0000000..646ebf8 --- /dev/null +++ b/examples/groovy/parseproperties.groovy @@ -0,0 +1,13 @@ +import jalview.analysis.*; +import jalview.datamodel.*; +import jalview.gui.AlignFrame; +import jalview.gui.AlignViewport; + +def af = Jalview.getAlignframes(); +def al = af[0].viewport.alignment; +ParseProperties pp = new ParseProperties(al); +pp.getScoresFromDescription("Score", "ScanPS Raw Score", "([-0-9.+]+)"); +def sqs = al.getSequenceAt(0); +def annots = sqs.getAnnotation(); + + diff --git a/examples/groovy/printtitle.groovy b/examples/groovy/printtitle.groovy new file mode 100644 index 0000000..8fe91db --- /dev/null +++ b/examples/groovy/printtitle.groovy @@ -0,0 +1,12 @@ +// do something groovy in jalview +print "Hello World.\n"; +def alf = Jalview.getAlignframes(); +for (ala in alf) +{ + // ala is an jalview.gui.AlignFrame object + print ala.getTitle()+"\n"; + // get the parent jalview.datamodel.Alignment from the alignment viewport + def alignment = ala.viewport.alignment; + // get the first sequence from the jalview.datamodel.Alignment object + def seq = alignment.getSequenceAt(0); +} diff --git a/examples/groovy/removeFeaturesByGroup.groovy b/examples/groovy/removeFeaturesByGroup.groovy new file mode 100644 index 0000000..bf7f74d --- /dev/null +++ b/examples/groovy/removeFeaturesByGroup.groovy @@ -0,0 +1,31 @@ +import jalview.analysis.*; +import jalview.datamodel.*; +import jalview.gui.AlignFrame; +import jalview.gui.AlignViewport; + +def af = Jalview.getAlignframes(); + +def todie = "PDBFile"; // about to delete this type of group +for (ala in af) +{ + def al = ala.viewport.alignment.getDataset(); + if (al!=null) + { + SequenceI[] seqs = al.getSequencesArray(); + for (sq in seqs) + { + if (sq!=null) { + SequenceFeature[] sf = sq.getSequenceFeatures(); + for (sfpos in sf) + { + if (sfpos!=null && sfpos.getFeatureGroup().equals(todie)) + { + sq.deleteFeature(sfpos); + } + } + } + } + } +} + + diff --git a/examples/groovy/stripUniprotPrefixes.groovy b/examples/groovy/stripUniprotPrefixes.groovy new file mode 100644 index 0000000..e2bb129 --- /dev/null +++ b/examples/groovy/stripUniprotPrefixes.groovy @@ -0,0 +1,31 @@ +import jalview.analysis.*; +import jalview.datamodel.*; +import jalview.gui.AlignFrame; +import jalview.gui.AlignViewport; + +def af = Jalview.getAlignframes(); + +// walk through all alignments, stripping off all text prior to and including last '|' symbol in sequence IDs + +for (ala in af) +{ + def al = ala.viewport.alignment; + if (al!=null) + { + SequenceI[] seqs = al.getSequencesArray(); + for (sq in seqs) + { + if (sq!=null) { + if (sq.getName().indexOf("|")>-1) + { + sq.setName(sq.getName().substring(sq.getName().lastIndexOf("|")+1)); + if (sq.getDatasetSequence()!=null) + { + sq.getDatasetSequence().setName(sq.getName()); + } + } + } + } + } +} + \ No newline at end of file -- 1.7.10.2