Results 1 to 12 of 12
Like Tree1Likes
  • 1 Post By kjkrum

Thread: new in java, need help in running a java script

  1. #1
    ashokpatowary is offline Member
    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0

    Default new in java, need help in running a java script

    Hi I have no basic knowledge in java. I am biologist who need to use a java script. While runing the script i am getting the following error. Some once can please help me in resolving this. I might be a very basic error also. I am sorry for that.

    import: unable to open image `java.io.*': @ error/blob.c/OpenBlob/2587.
    import: no encode delegate for this image format `java.io.*' @ error/constitute.c/WriteImage/1188.
    import: unable to open image `java.util.*': @ error/blob.c/OpenBlob/2587.
    import: no encode delegate for this image format `java.util.*' @ error/constitute.c/WriteImage/1188.
    VCF2IBS.java: line 6: /bin: Is a directory
    VCF2IBS.java: line 7: ControlPanel: command not found
    VCF2IBS.java: line 8: ControlPanel: command not found
    VCF2IBS.java: line 9: ControlPanel: command not found
    VCF2IBS.java: line 10: ControlPanel: command not found
    VCF2IBS.java: line 11: ControlPanel: command not found
    VCF2IBS.java: line 12: ControlPanel: command not found
    VCF2IBS.java: line 13: ControlPanel: command not found
    VCF2IBS.java: line 14: ControlPanel: command not found
    VCF2IBS.java: line 15: ControlPanel: command not found
    VCF2IBS.java: line 16: syntax error near unexpected token `('
    VCF2IBS.java: line 16: ` * all of the sequenced individuals show identity by state (1), otherwise'


    Thanks and regards
    Ashok

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: new in java, need help in running a java script

    It appears that you are trying to run a Java source file as it it were some kind of script. Java source files need to be compiled. On the command line, try something like this:

    Java Code:
    javac VCF2IBS.java
    java VCF2IBS
    If that doesn't work, post the source and the error.
    ashokpatowary likes this.
    Get in the habit of using standard Java naming conventions!

  3. #3
    ashokpatowary is offline Member
    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0

    Default Re: new in java, need help in running a java script

    Hi kjkrum

    Thanks for your reply and the help. Now I am getting some other error and again I am not understanding it.

    Exception in thread "main" java.lang.NoClassDefFoundError: VCF2IBS
    Caused by: java.lang.ClassNotFoundException: VCF2IBS
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 21)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 66)
    Could not find the main class: VCF2IBS. Program will exit.

    Thanks and regards
    Ashok

  4. #4
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    384
    Rep Power
    4

    Default Re: new in java, need help in running a java script

    First of all, Java is not Javascript. They're two completely different things. If you need help with Javascripts, I'm sure there are forums for that, but this one isn't one.

  5. #5
    ashokpatowary is offline Member
    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0

    Default Re: new in java, need help in running a java script

    Hi Toll,

    I am sorry for it. Thanks for your advice.

    Regards
    Ashok

  6. #6
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: new in java, need help in running a java script

    So 'javac VCF2IBS.java' ran without errors? If so, that means it compiled OK. The error you posted looks like a classpath issue. I'm guessing the class you just compiled isn't in the default package. Could you post the java file?
    Get in the habit of using standard Java naming conventions!

  7. #7
    ashokpatowary is offline Member
    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0

    Default Re: new in java, need help in running a java script

    Hi kjkrum,

    Yah it work. I use java VCF2IBS. Please find the file bellow.


    Java Code:
    import java.io.*;
    import java.util.*;
    
    
    
    /**
     * VCF2IBS.java
     * This is a program designed to convert the VCF files from 2 or more
     * individuals into ibs-format files, which have the format
     * chr1    000867672       0
     * chr1    000877423       1
     * ...     ...		   ...
     * The first two columns indicate the chromosomal location of a variant.
     * The third column indicates whether each of the VCF files has the same
     * heterozygous or homozygous variant. If this is the case, then
     * all of the sequenced individuals show identity by state (1), otherwise
     * they are not IBS (0).
     * Copyright (C) Peter N. Robinson 2010
     * This program is free software. you can redistribute it and/or
     * modify it under the terms of the GNU Lesser General Public
     * License as published by the Free Software Foundation; either
     * version 2.1 of the License, or (at your option) any later version. 
     */
    public class VCF2IBS {
    
        /** Number of individuals analyzed (equal to number of VCF files). */
        private int n;
        /** codes for X and Y chromosome */
        static final int X_CHROMOSOME = 23;
        static final int Y_CHROMOSOME = 24;
        /** Name of output file */
        private String outfile = "out.ibs";
        /** Name of log file */
        private String logfile = "ibs.log";
        /** Number of ibs SNVs */
        private int n_ibs;
        /** Total number of SNVs. */
        private int n_snv;
    
    
        /* A class that will be used like a C struct to
           hold information about the individual calls.
           Note that if a given SNV is found at a given position
           in one proband, and a different call is found at the same
           position, we will just skip it over (not increment n).
           This will ensure that IBS*=0 for this position as
           required.
        */
        private class SNV implements Comparable  {
    	/** chromosome; 23=X, 24=Y */
    	public int chrom;
    	/** position along chromosome; */
    	public int pos;
    	/** Number of times this variant observed */
    	public int n;
    	/** Variant, encoded as in method 'getVariantCall' */
    	public char var;
    	public SNV(int c, int p, char v) {
    	    this.chrom = c; this.pos=p;this.n=1;this.var=v;
    	}
    	public int compareTo(Object o) {
    	    SNV other = (SNV) o;
    	    if (other.chrom>this.chrom) return -1;
    	    else if (other.chrom<this.chrom) return 1;
    	    else if (other.pos > this.pos) return -1;
    	    else if (other.pos < this.pos) return 1;
    	    else return 0;
    	}
        }
    
        private HashMap<String,SNV> snv;
    
    
        public static void main(String args[]) {
    	System.out.println("VCF2IBS");
    	VCF2IBS vcf2ibs = new VCF2IBS(args);
    	vcf2ibs.outputIBSfile();
    	vcf2ibs.outputLog();
        }
    
        public static void usage() {
    	System.out.println("Usage: java VCFIBS vcf1 vcf2 vcf3 ...");
    	System.out.println("Enter the names of all VCFfiles that should be included" +
    			   " in the IBS* determination");
    	System.out.println("The program will output a file called \"out.ibs\" that " +
    			   "contains one line for each variant/IBS* call");
    	System.out.println("You need to enter the names of at least two VCF files");
    	System.out.println("The program will also output a file called \"ibs.log\" "+
    			   "with a summary of the IBS data");
    	System.exit(0);
    				   
    
        }
    
        public VCF2IBS(String filenames[]) {
    	
    	if (filenames.length<2)
    	    usage();
    	snv = new HashMap<String,SNV>();
    
    	parseVCFfiles(filenames);
        }
    
        /**
         * Parse the VCF files and record all variants.
         * Format of vcf files:
         * VCF files start with comment lines. The data is then white-space separated.
         * 1) CHROM: chr10
         * 2) POS:   84026
         * 3) ID:    .
         * 4) REF:   G  (the reference nucleotide at the indicated position.
         * 5) ALT:   A  (the observed variant call)
         * 6) QUAL:  1530.20 (quality score)
         * 7) FILTER: .
         * 8) INFO:
         * 9) FORMAT:
         * 10) hs:
         * This function puts all of the variants into a HashMap that will
         * be sorted later in the parogram.
         */
        private void parseVCFfiles(String vcffiles[]) {
    	this.n = vcffiles.length;
    	for (String s: vcffiles) {
    	    if (! s.endsWith("vcf") && !s.endsWith("VCF") )
    		usage();
    	    try{
    		FileInputStream fstream = new FileInputStream(s);
    		DataInputStream dstream = new DataInputStream(fstream);
    		BufferedReader br = new BufferedReader(new InputStreamReader(dstream));
    		String line;
    		while ((line = br.readLine())!=null) {
    		    int chromosome,position=0;
    		    if (line.startsWith("#")) continue;
    		    //System.out.println(line);
    		    String A[] = line.split("\\s");
    		    String chr = A[0].substring(3); /* part of string after 'chr' */
    		    if (chr.equals("X")) chromosome = X_CHROMOSOME;
    		    else if (chr.equals("Y")) chromosome = Y_CHROMOSOME;
    		    else {
    			chromosome = Integer.parseInt(chr);
    		    }
    		    position   = Integer.parseInt(A[1]);
    		    String id = A[0].concat(A[1]); /* make index of chromosome and position */
    		    char v = getVariantCall(A[3],A[4],A[9]);	
    		    //System.out.println(A[0] + ":" + chromosome + ":" + position); //chr
    		    /* 1) Check if a variant at this position exists already. */
    		    if (snv.containsKey(id)) {
    			SNV sv = snv.get(id);
    			if (sv.var == v) sv.n++;
    		    } else {
    			snv.put(id, new SNV(chromosome,position,v));
    		    }	
    		   
    		    //System.out.println(A[0] + ":" + v); //chr
    		}
    		dstream.close();
    	    }catch(IOException e) {
    		System.err.println("Could not open file " + s + " for reading.\n"
    				   + e.getMessage());
    		usage();
    	    }
    	}
    
    
        }
    
    
        /**
         * Returns the summarized variant call.
         * A standard nucleotide (ACGT), means there was a homozygous SNV.
         * A IUPAC ambiguity code nucleotide means there was a heterozygous
         * SNV. For instance, 'R' means there was a heterozygous SNV A/G.
         * @return char the called SNV.
         */
        private char getVariantCall(String ref, String alt, String hs) {
    	if(hs.substring(0,3).equals("1/1")) {
    	    return alt.charAt(0);
    	} else if (hs.substring(0,3).equals("0/1")) {
    	    String dinucl = ref.substring(0,1).concat(alt.substring(0,1)).toUpperCase();
    	    if (dinucl.equals("AG") || dinucl.equals("GA")) return 'R';
    	    if (dinucl.equals("CT") || dinucl.equals("TC")) return 'Y';
    	    if (dinucl.equals("GT") || dinucl.equals("TG")) return 'K';
    	    if (dinucl.equals("AC") || dinucl.equals("CA")) return 'M';
    	    if (dinucl.equals("CG") || dinucl.equals("GC")) return 'S';
    	    if (dinucl.equals("AT") || dinucl.equals("TA")) return 'W';
    	}
    	/* We should never reach here */
    	System.err.println("Error: Could not parse hs string: \n" + hs
    		   + "\n for inputs ref=" + ref + ", alt=" +alt);
    	System.exit(1);
    	return 'x';
        }	
    
    
        private void outputLog() {
    	Object[] vals = snv.values().toArray(); /* No need to sort here */
    	this.n_ibs=0;
    	this.n_snv=0;
    	for (Object obj : vals) {
    	    SNV sv = (SNV) obj;
    	    n_snv++;
    	    if  (sv.n == this.n)
    		n_ibs++;
    	}
    
    	try {
    	    FileWriter fstream = new FileWriter(this.logfile);
    	    BufferedWriter out = new BufferedWriter(fstream);
    	    out.write("Number of VCF files: " + n + "\n");
    	    out.write("Number of called variants: " + n_snv + "\n");
    	    out.write("Number of variants called IBS*: " + n_ibs + "\n");
    	    out.close();
    	} catch (IOException e) {
    	    System.err.println("Could not write results to log file." + e.getMessage());
    	}
    
        }
        
    
        private void outputIBSfile() {
    	Object[] vals = snv.values().toArray();
    	Arrays.sort(vals);
    
    	try{
    	    FileWriter fstream = new FileWriter(this.outfile);
    	    BufferedWriter out = new BufferedWriter(fstream);
    	    for (Object obj : vals) {
    		SNV sv = (SNV) obj;
    		StringBuffer sb = new StringBuffer();
    		if (sv.chrom == 23) sb.append("chrX\t");
    		else if (sv.chrom == 24) sb.append("chrY\t");
    		else {
    		    sb.append("chr");
    		    sb.append(sv.chrom + "\t");
    		}
    		sb.append(sv.pos);
    		if (sv.n == this.n)
    		    sb.append("\t1\n");
    		else
    		    sb.append("\t0\n");
    		//System.out.println(sb.toString());
    		out.write(sb.toString());
    	    }
    	    out.close();
    	} catch (IOException e) {
    	    System.err.println("Could not write results to File." + e.getMessage());
    	}
        }
    
    
    
    }
    Last edited by ashokpatowary; 07-19-2013 at 10:26 PM.

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: new in java, need help in running a java script

    Forum Rules -- particularly the third paragraph.
    Guide For New Members
    BB Code List - Java Programming Forum - Learn Java Programming

    Read those and edit your posts accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    ashokpatowary is offline Member
    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0

    Default Re: new in java, need help in running a java script

    Hi Darry

    I am sorry for that. I will careful from next.

  10. #10
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: new in java, need help in running a java script

    After you run 'javac VCF2IBS.java', is there a file named VCF2IBS.class in the current directory?

    If so, try this command: 'java -cp . VCF2IBS'

    If that works, read PATH and CLASSPATH (The Java™ Tutorials > Essential Classes > The Platform Environment) to understand what classpath is and set up your system so you don't have to specify it all the time.
    Get in the habit of using standard Java naming conventions!

  11. #11
    ashokpatowary is offline Member
    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0

    Default Re: new in java, need help in running a java script

    Hi kjkrum

    Thanks for your help. Still I am getting the following error; but i think i will give a try to resolve it.

    Thanks and regards
    Ashok

    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -2
    at java.lang.String.substring(String.java:1949)
    at java.lang.String.substring(String.java:1916)
    at VCF2IBS.parseVCFfiles(VCF2IBS.java:136)
    at VCF2IBS.<init>(VCF2IBS.java:101)
    at VCF2IBS.main(VCF2IBS.java:76)

  12. #12
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: new in java, need help in running a java script

    Well, at least that means it's compiled and running! I don't understand where it's getting the index -2, though. On line 136, the index is a literal 3.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Replies: 0
    Last Post: 09-28-2011, 01:04 PM
  2. Running a Python Script in Java
    By JavaN00bie in forum New To Java
    Replies: 6
    Last Post: 06-22-2011, 09:23 PM
  3. Running a script until [quit]
    By berfuzz in forum Java Applets
    Replies: 1
    Last Post: 04-13-2011, 08:48 PM
  4. Running a script within IE
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-25-2008, 02:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •