List of usage examples for org.apache.commons.net.ftp FTPClient sendCommand
public int sendCommand(String command, String args) throws IOException
From source file:base.BasePlayer.AddGenome.java
static void updateEnsemblList() { try {/*w w w .java 2s .c o m*/ menu = new JPopupMenu(); area = new JTextArea(); menuscroll = new JScrollPane(); area.setFont(Main.menuFont); menu.add(menuscroll); //menu.setPreferredSize(new Dimension(menu.getFontMetrics(Main.menuFont).stringWidth("0000000000000000000000000000000000000000000000000")+Main.defaultFontSize*10, (int)menu.getFontMetrics(Main.menuFont).getHeight()*4)); menu.setPreferredSize(new Dimension(300, 200)); //area.setMaximumSize(new Dimension(300, 600)); //area.setLineWrap(true); //area.setWrapStyleWord(true); //area.setPreferredSize(new Dimension(300,200)); area.revalidate(); menuscroll.getViewport().add(area); menu.pack(); menu.show(AddGenome.treescroll, 0, 0); /* area.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent arg0) { StringBuffer buf = new StringBuffer(""); for(int i= 0; i<(int)(Math.random()*100); i++) { buf.append("O"); } AddGenome.area.append(buf.toString() +"\n"); AddGenome.area.setCaretPosition(AddGenome.area.getText().length()); AddGenome.area.revalidate(); } @Override public void mouseReleased(MouseEvent arg0) { // TODO Auto-generated method stub } });*/ FTPClient f = new FTPClient(); news = new ArrayList<String[]>(); area.append("Connecting to Ensembl...\n"); //System.out.println("Connecting to Ensembl..."); f.connect("ftp.ensembl.org"); f.enterLocalPassiveMode(); f.login("anonymous", ""); //System.out.println("Connected."); area.append("Connected.\n"); FTPFile[] files = f.listFiles("pub"); String releasedir = ""; String releasenro; for (int i = 0; i < files.length; i++) { if (files[i].isDirectory() && files[i].getName().contains("release")) { releasedir = files[i].getName(); } } files = f.listFiles("pub/" + releasedir + "/fasta/"); releasenro = releasedir.substring(releasedir.indexOf("-") + 1); area.append("Searching for new genomes"); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { FTPFile[] fastafiles = f .listFiles("pub/" + releasedir + "/fasta/" + files[i].getName() + "/dna/"); String[] urls = new String[5]; for (int j = 0; j < fastafiles.length; j++) { if (fastafiles[j].getName().contains(".dna.toplevel.")) { urls[0] = "ftp://ftp.ensembl.org/pub/" + releasedir + "/fasta/" + files[i].getName() + "/dna/" + fastafiles[j].getName(); String filePath = "/pub/" + releasedir + "/fasta/" + files[i].getName() + "/dna/" + fastafiles[j].getName(); f.sendCommand("SIZE", filePath); String reply = f.getReplyString().split("\\s+")[1]; urls[1] = reply; break; } } if (urls[0] == null) { continue; } FTPFile[] annofiles = f.listFiles("pub/" + releasedir + "/gff3/" + files[i].getName()); for (int j = 0; j < annofiles.length; j++) { if (annofiles[j].getName().contains("." + releasenro + ".gff3.gz")) { urls[2] = "ftp://ftp.ensembl.org/pub/" + releasedir + "/gff3/" + files[i].getName() + "/" + annofiles[j].getName(); String filePath = "/pub/" + releasedir + "/gff3/" + files[i].getName() + "/" + annofiles[j].getName(); f.sendCommand("SIZE", filePath); String reply = f.getReplyString().split("\\s+")[1]; urls[3] = reply; break; } } if (urls[2] == null) { continue; } if (files[i].getName().contains("homo_sapiens")) { urls[4] = "http://hgdownload.cse.ucsc.edu/goldenPath/hg19/database/cytoBand.txt.gz"; } else if (files[i].getName().contains("mus_musculus")) { urls[4] = "http://hgdownload.cse.ucsc.edu/goldenPath/mm10/database/cytoBand.txt.gz"; } String name = urls[0].substring(urls[0].lastIndexOf("/") + 1, urls[0].indexOf(".dna.")); //System.out.print(urls[0]+"\t" +urls[1] +"\t" +urls[2] +"\t" +urls[3]); if (genomeHash.containsKey(name) || AddGenome.removables.contains(name)) { //System.out.println(name +" already in the list."); area.append("."); } else { area.append("\nNew genome " + name + " added.\n"); AddGenome.area.setCaretPosition(AddGenome.area.getText().length()); AddGenome.area.revalidate(); //System.out.println("New reference " +name +" found."); organisms.add(name); news.add(urls); if (urls[4] != null) { //System.out.println(urls[0] +" " + urls[2] +" " +urls[4]); URL[] newurls = { new URL(urls[0]), new URL(urls[2]), new URL(urls[4]) }; genomeHash.put(name, newurls); } else { URL[] newurls = { new URL(urls[0]), new URL(urls[2]) }; genomeHash.put(name, newurls); } Integer[] sizes = { Integer.parseInt(urls[1]), Integer.parseInt(urls[3]) }; sizeHash.put(name, sizes); } /*if(urls[4] != null) { System.out.print("\t" +urls[4]); } System.out.println(); */ } } checkGenomes(); if (news.size() > 0) { try { //File file = new File(); FileWriter fw = new FileWriter(Main.genomeDir.getCanonicalPath() + "/ensembl_fetched.txt"); BufferedWriter bw = new BufferedWriter(fw); for (int i = 0; i < news.size(); i++) { for (int j = 0; j < news.get(i).length; j++) { if (news.get(i)[j] == null) { break; } if (j > 0) { bw.write("\t"); } bw.write(news.get(i)[j]); } bw.write("\n"); } bw.close(); fw.close(); } catch (IOException e) { e.printStackTrace(); } } } catch (Exception e) { Main.showError(e.getMessage(), "Error"); e.printStackTrace(); } }