Heh - I didn't test the copy/paste to excel part... here's a better
version, that will create a TSV file. See the comments for how to change
it to a CSV! As a tip, in Excel, there's also the 'Data to columns'
function in the Tools menu that allows you to process commas and tabs in
cut/pasted data that was incorrectly pasted into a single column.
// Requested by David M Garcia (v2)
// very messy script to output the scores in annotation rows
// for the first sequence in a selection on the topmost alignment
def curviewport =
Jalview.getAlignframes()[Jalview.getAlignframes().length-1].getViewport();
// TSV output by default.
// change "\t" to "," to output CSV file
def sep = "\t";
if (curviewport.getSelectionGroup()) {
// gets selection for topmost alignment
def selreg = curviewport.getSelectionGroup();
// get aligned positions of first sequence selected
def gaps = selreg.getSequenceAt(0).gapMap();
String csvfile="";
curviewport.getAlignment().getAlignmentAnnotation().eachWithIndex{ aa,
apos ->
String csv=""
gaps.eachWithIndex{col,spos -> if (col>=selreg.getStartRes() &&
col<=selreg.getEndRes()) {
// output height of histogram
csv+=sep+aa.annotations[col].value;
// Uncomment to output string shown in tooltip
// csv+=sep+aa.annotations[col].description;
}}
if (csv.length()>0) {
csvfile+=aa.label+sep+csv+"\n"
}
}
print csvfile;
} else {
"Select a region in the alignment window.";
}
On 05/06/2014 11:37, David M Garcia wrote:
Hi Jim,
Thanks very much for the script! I use the Desktop version of Jalview.
I selected the top sequence of an alignment I had open, and ran the
script through groovy, and got an output at the bottom of the window,
highlighted in yellow. If I copy and paste this into excel, it doesn't
seem to be in a tab delimited form. Is there an easy way to convert?
Or does the script also make a .csv file? I couldn't find one dropped
anywhere. My computational experience is limited so from the script I
couldn't tell exactly what the format of the potential .csv file
should be in terms of its name or location where it would end up.
Thanks!
David
On Thu, Jun 5, 2014 at 2:23 AM, Jim Procter
<[email protected] <mailto:[email protected]>>
wrote:
Hi David.
On 04/06/2014 18:33, David M Garcia wrote:
Is there a way I can extract the conservation values
corresponding to one of the other proteins in the alignment? I
would like to be able to extract conservation scores for the
residues only present in certain proteins in my alignment (in
an excel friendly format), without all the gaps.
I've lodged a feature request about this
(http://issues.jalview.org/browse/JAL-1516). I also came up with a
fairly messy script that might do what you need:
Open Jalview's groovy console
(http://www.jalview.org/help/html/features/groovy.html) and paste
in the following:
// very messy script to output the scores in annotation rows for
the first sequence in a selection on the topmost alignment
def curviewport =
Jalview.getAlignframes()[Jalview.getAlignframes().length-1].getViewport();
if (curviewport.getSelectionGroup()) {
// gets selection for 'first' alignment - note this is the
'oldest' one - can't access the current alignment as yet
def selreg = curviewport.getSelectionGroup();
def gaps = selreg.getSequenceAt(0).gapMap(); // aligned
positions of first sequence selected
String csvfile="";
curviewport.getAlignment().getAlignmentAnnotation().eachWithIndex{
aa, apos ->
String csv=""
gaps.eachWithIndex{col,spos -> if (col>=selreg.getStartRes()
&& col<=selreg.getEndRes()) {
// output height of histogram
csv+=","+aa.annotations[col].value;
// Uncomment to output string shown in tooltip
// csv+=","+aa.annotations[col].description;
}}
if (csv.length()>0) {
csvfile+=aa.label+csv+"\n"
}
}
print csvfile;
} else {
"Select a region in the alignment window.";
}
///
Hope that helps!
Jim
ps. You can also find this script in a comment on the feature
request:
http://issues.jalview.org/browse/JAL-1516?focusedCommentId=13296&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13296
_______________________________________________
Jalview-discuss mailing list
[email protected]
http://www.compbio.dundee.ac.uk/mailman/listinfo/jalview-discuss