📄 alignjframe.java
字号:
JCheckBoxMenuItem sizeColor = new JCheckBoxMenuItem("Red=Tiny, Green=Small, Blue=Large"); propertyMenu.add(sizeColor); group.add(sizeColor); sizeColor.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { gsc.setColorScheme(SequenceProperties.sizeColor); jspSequence.setViewportView(gsc); currentColour = SequenceProperties.sizeColor; colourScheme("Red=Tiny, Green=Small, Blue=Large"); } });// other colour schemes JCheckBoxMenuItem taylor = new JCheckBoxMenuItem("Taylor Colour"); viewMenu.add(taylor); group.add(taylor); taylor.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { gsc.setColorScheme(SequenceProperties.taylorColor); jspSequence.setViewportView(gsc); currentColour = SequenceProperties.taylorColor; colourScheme("Taylor"); } }); residueColor = new JCheckBoxMenuItem("Residue Colour"); viewMenu.add(residueColor); group.add(residueColor); residueColor.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { gsc.setColorScheme(SequenceProperties.residueColor); jspSequence.setViewportView(gsc); currentColour = SequenceProperties.residueColor; colourScheme("Residue"); } }); JCheckBoxMenuItem rasmolColor = new JCheckBoxMenuItem("Rasmol Colour"); viewMenu.add(rasmolColor); group.add(rasmolColor); rasmolColor.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { gsc.setColorScheme(SequenceProperties.rasmolColor); jspSequence.setViewportView(gsc); currentColour = SequenceProperties.rasmolColor; colourScheme("Rasmol"); } }); JCheckBoxMenuItem nuc = new JCheckBoxMenuItem("Nucleotide Colour"); viewMenu.add(nuc); group.add(nuc); nuc.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { gsc.setColorScheme(SequenceProperties.baseColor); jspSequence.setViewportView(gsc); currentColour = SequenceProperties.baseColor; colourScheme("Nucleotide"); } }); viewMenu.add(new JSeparator()); } /** * * * red, blue, cyan, darkGray, gray , green, lightGray, * magenta , orange, pink, white, yellow, black * */ private static Color resolveColor(String[] args,int index) { if(args[index].equalsIgnoreCase("red")) return Color.red; else if(args[index].equalsIgnoreCase("blue")) return Color.blue; else if(args[index].equalsIgnoreCase("black")) return Color.black; else if(args[index].equalsIgnoreCase("cyan")) return Color.cyan; else if(args[index].equalsIgnoreCase("darkGray")) return Color.darkGray; else if(args[index].equalsIgnoreCase("gray")) return Color.gray; else if(args[index].equalsIgnoreCase("green")) return Color.green; else if(args[index].equalsIgnoreCase("lightGray")) return Color.lightGray; else if(args[index].equalsIgnoreCase("magenta")) return Color.magenta; else if(args[index].equalsIgnoreCase("orange")) return Color.orange; else if(args[index].equalsIgnoreCase("pink")) return Color.pink; else if(args[index].equalsIgnoreCase("white")) return Color.white; else if(args[index].equalsIgnoreCase("yellow")) return Color.yellow; else if(args[index].equalsIgnoreCase("black")) return Color.black; return null; } /** * * Extends WindowAdapter to close window * */ class winExit extends WindowAdapter { public void windowClosing(WindowEvent we) { dispose(); } } public static void main(String args[]) { AlignJFrame ajFrame = null; if( args.length > 0 ) { for(int i=0;i<args.length;i++) { if(args[i].indexOf("-help") > -1) { System.out.println( "\n Jemboss Alignment Editor\n\n"+ "DESCRIPTION\n"+ "The Jemboss Alignment Editor can be used interactively to\n"+ "edit a sequence alignment (read in fasta or MSF format). It can\n"+ "also be used from the command line to produce image files\n"+ "of the alignment.\n\nUSAGE\n"+ "java org/emboss/jemboss/editor/AlignJFrame file [options]\n\n"+ "file This is the multiple sequence alignment in\n"+ " fasta or MSF format.\n\n"+ "OPTIONS\n"+ "-calc Calculate consensus and display under the alignment.\n"+ " The following 3 flags can be used to define values\n"+ " used in the calculations.\n"+ " -plu (plurality) minimum positive match score\n"+ " value for there to be a consensus.\n"+ " -numid minimum number of identities for there to\n"+ " be a consensus.\n"+ " -case minimum positive match score for setting\n"+ " the consensus to upper-case.\n"+ "-color Used to define a colour scheme, below is the list of\n"+ " available colour schemes:\n"+ " taylor\n"+ " residue\n"+ " rasmol\n"+ " acid\n"+ " polar\n"+ " hydrophobic\n"+ " aromatic\n"+ " surface\n"+ " charge\n"+ " size\n"+ " base\n\n"+ " java org.emboss.jemboss.editor.AlignJFrame file -color size\n\n"+ "-font Set the font size.\n"+ "-id Display a percentage ID pair table.\n"+ "-noshow Turns of the alignment display.\n"+ "-nres Number of residues to each line is a print out.\n"+ "-pretty EMBOSS prettyplot colour scheme. The -matrix flag option\n"+ " can be used to define a scoring matrix for identifying\n"+ " positive matches.\n"+ " -noBox switch off box drawing around identical and\n"+ " positive matches.\n"+ " -minID define the minimum number of identities. The\n"+ " default for this is the number of sequences\n"+ " in the file.\n"+ " -match define a threshold value for the number of\n"+ " positive matches, the default is half the\n"+ " total wgt.\n"+ " -colID define a lettering colour for the identities.\n"+ " -colIDBack define a background colour for identities.\n"+ " -colMatch define a lettering colour for positive matches.\n"+ " -colMatchBack define a background colour for positive\n"+ " matches.\n"+ " Available colour options:\n"+ " red, blue, cyan, darkGray, gray , green, lightGray,\n"+ " magenta , orange, pink, white, yellow, black\n"+ "-print Print the alignment image. The following 2 flags can be\n"+ " used along with the print flag\n"+ " -prefix prefix for image output file.\n"+ " -onePage fit the alignment to one page. This option must be\n"+ " be used with the -nres flag to define the residues\n"+ " per line.\n"+ " -type png or jpeg (default is jpeg).\n"+ " -antialias turn anti-aliasing on.\n"+ " -landscape Print as landscape (the default is portrait).\n"+ " -margin Define the left, right, top and bottom margin\n"+ " (in cm).\n"+ " java org.emboss.jemboss.editor.AlignJFrame file -matrix EBLOSUM62 \\\n"+ " -noshow -print -margin 0.5 0.5 0.5 0.5\n\n"+ "-matrix To define a scoring matrix. Used with the -pretty and -calc\n"+ " option.\n"+ "-list List the available scoring matrix files.\n\n"+ "EXAMPLE\n"+ "java org.emboss.jemboss.editor.AlignJFrame file -matrix EBLOSUM80 \\\n"+ " -pretty -noshow -id -print -type png\n\n"+ "java org.emboss.jemboss.editor.AlignJFrame file -matrix EPAM250 \\\n"+ " -pretty -colIDBack black -colID white -print \\\n"+ " -margin 0.5 0.5 0.5 0.0 -noshow\n"); System.exit(0); } } File seqFile = new File(args[0]); if(seqFile.canRead()) { ajFrame = new AlignJFrame(true); SequenceReader sr = new SequenceReader(seqFile); sr.getSequenceFile(); ajFrame.openMethod(sr.getSequenceVector()); ajFrame.setTitle("Jemboss Alignment Viewer :: "+ seqFile.getName()); gsc.setMatrix(mat); } String prefix = "output"; String type = "jpeg"; boolean show = true; boolean print = false; int nresiduesPerLine = 0; float wgt = getTotalWeight(gsc.getSequenceCollection()); double lmargin = -0.5; // left margin double rmargin = -0.5; // right margin double tmargin = -0.5; // top margin double bmargin = -0.5; // bottom margin float plu = wgt/2.f; float cas = wgt/2.f; int ident = 0; int minID = gsc.getNumberSequences(); float match = wgt/2.f; Color colID = Color.red; Color colMatch = Color.blue; Color colIDBack = Color.white; Color colMatchBack = Color.white; boolean prettyBox = true; boolean landscape = false; boolean onePage = false; boolean antialias = false; for(int i=0;i<args.length;i++) { if(args[i].indexOf("-matrix") > -1) { mat = new Matrix("resources/resources.jar", args[i+1]); gsc.setMatrix(mat); statusField.setText("Current matrix: "+args[i+1]); } else if(args[i].indexOf("-plu") > -1) plu = Float.parseFloat(args[i+1]); else if(args[i].indexOf("-match") > -1) match = Float.parseFloat(args[i+1]); else if(args[i].indexOf("-case") > -1) cas = Float.parseFloat(args[i+1]); else if(args[i].indexOf("-numid") > -1) ident = Integer.parseInt(args[i+1]); else if(args[i].indexOf("-colIDBack") > -1) { Color col = resolveColor(args,i+1); if(col != null) colIDBack = col; } else if(args[i].indexOf("-colMatchBack") > -1) { Color col = resolveColor(args,i+1); if(col != null) colMatchBack = col; } else if(args[i].indexOf("-colMatch") > -1) { Color col = resolveColor(args,i+1); if(col != null) colMatch = col; } else if(args[i].indexOf("-colID") > -1) { Color col = resolveColor(args,i+1); if(col != null) colID = col; } else if(args[i].indexOf("-minID") > -1) minID = Integer.parseInt(args[i+1]); else if(args[i].indexOf("-noBox") > -1) prettyBox = false; else if(args[i].indexOf("-font") > -1) gsc.setFontSizeForCollection(Integer.parseInt(args[i+1])); else if(args[i].indexOf("-landscape") > -1) landscape = true; else if(args[i].indexOf("-margin") > -1) { lmargin = Double.parseDouble(args[i+1]); rmargin = Double.parseDouble(args[i+2]); tmargin = Double.parseDouble(args[i+3]); bmargin = Double.parseDouble(args[i+4]); } else if(args[i].indexOf("-onePage") > -1) onePage = true; else if(args[i].indexOf("-antialias") > -1) antialias = true; } for(int i=0;i<args.length;i++) { if(args[i].indexOf("-color") > -1) { i++; if(args[i].startsWith("taylor")) gsc.setColorScheme(SequenceProperties.taylorColor); else if(args[i].startsWith("residue")) gsc.setColorScheme(SequenceProperties.residueColor); else if(args[i].startsWith("rasmol")) gsc.setColorScheme(SequenceProperties.rasmolColor); else if(args[i].startsWith("acid")) gsc.setColorScheme(SequenceProperties.acidColor); else if(args[i].startsWith("polar")) gsc.setColorScheme(SequenceProperties.polarColor); else if(args[i].startsWith("hydro")) gsc.setColorScheme(SequenceProperties.hydrophobicColor); else if(args[i].startsWith("aromatic")) gsc.setColorScheme(SequenceProperties.aromaticColor); else if(args[i].startsWith("surface")) gsc.setColorScheme(SequenceProperties.surfaceColor); else if(args[i].startsWith("charge")) gsc.setColorScheme(SequenceProperties.chargeColor); else if(args[i].startsWith("size")) gsc.setColorScheme(SequenceProperties.sizeColor); else if(args[i].startsWith("base")) gsc.setColorScheme(SequenceProperties.baseColor); } else if(args[i].indexOf("-calc") > -1) { Consensus conseq = new Consensus(mat, gsc.getSequenceCollection(), plu,cas,ident); int fontSize = gsc.getFontSize(); gsc.addSequence(conseq.getConsensusSequence(),true,5,fontSize); Dimension dpane = gsc.getPanelSize(); gsc.setPreferredSize(dpane); gsc.setNamePanelWidth(gsc.getNameWidth()); } else if(args[i].indexOf("-list") > -1) System.out.println("AVAILABLE DATABASES:\n"+ mat.getKeyNamesString()); else if(args[i].indexOf("-id") > -1) { IDTableJFrame idtab = new IDTableJFrame(gsc.getSequenceCollection()); idtab.printTable(); } else if(args[i].indexOf("-noshow") > -1) show = false; else if(args[i].indexOf("-print") > -1) print = true; else if(args[i].indexOf("-nres") > -1) nresiduesPerLine = Integer.parseInt(args[i+1]); else if(args[i].indexOf("-pretty") > -1) { PrettyPlotJFrame pretty = new PrettyPlotJFrame(minID, match,colID,colMatch, colIDBack,colMatchBack,prettyBox); gsc.setPrettyPlot(true,pretty); gsc.setDrawBoxes(false); gsc.setDrawColor(false); } else if(args[i].indexOf("-preview") > -1) { PrintAlignmentImage pai = new PrintAlignmentImage(gsc); pai.printPreview(); show = true; } else if(args[i].indexOf("-type") > -1) { if( args[i+1].equalsIgnoreCase("png") || args[i+1].equalsIgnoreCase("jpeg") ) type = args[i+1]; else System.out.println("UNKOWN PRINT FORMAT: "+args[i+1]+ " reverting to default format "+type); } else if(args[i].indexOf("-prefix") > -1) prefix = args[i+1]; } if(print) { if(onePage) { PrintAlignmentImage pai = new PrintAlignmentImage(gsc); if(antialias) pai.setAntiAlias(true); pai.print(nresiduesPerLine,type,prefix, lmargin,rmargin,tmargin,bmargin); } else { PrintAlignmentImage pai = new PrintAlignmentImage(gsc); if(antialias) pai.setAntiAlias(true); pai.print(nresiduesPerLine,type,prefix,landscape, lmargin,rmargin,tmargin,bmargin); } } if(!show) System.exit(0); } else { ajFrame = new AlignJFrame(true); } ajFrame.setVisible(true); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -