comparison NGSrich_0.5.5/src/datastructures/Read.java @ 0:89ad0a9cca52 default tip

Uploaded
author pfrommolt
date Mon, 21 Nov 2011 08:12:19 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:89ad0a9cca52
1 package datastructures;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.lang.InterruptedException;
6 import java.util.Scanner;
7 import java.util.Vector;
8
9 public class Read implements Comparable<Object> {
10
11 String query;
12 int flag;
13 String rname;
14 int pos;
15 int mapq;
16 String cigar;
17 String rnext;
18 int pnext;
19 int tlen;
20 String seq;
21 String qual;
22 Vector<String> optional;
23
24 public Read(String line) {
25 Scanner s = new Scanner(line);
26 query = s.next();
27 flag = s.nextInt();
28 rname = s.next();
29 pos = s.nextInt();
30 mapq = s.nextInt();
31 cigar = s.next();
32 rnext = s.next();
33 pnext = s.nextInt();
34 tlen = s.nextInt();
35 seq = s.next();
36 qual = s.next();
37 if (s.hasNext()) {
38 optional = new Vector<String>();
39 while (s.hasNext()) {
40 optional.add(s.next());
41 }
42 }
43 }
44
45 public String getRname() {
46 return rname;
47 }
48
49 public int getPos() {
50 return pos;
51 }
52
53 @Override
54 public int compareTo(Object o) {
55 return 0;
56 }
57
58 public static void sort(File input) {
59 Runtime rt = Runtime.getRuntime();
60 try {
61 String rawOutput = input.getAbsolutePath(),
62 tmpD = input.getParentFile().getAbsolutePath(),
63 outputName = input.getName(),
64 pathname = input.getParentFile().getAbsolutePath() + "/" +
65 outputName + "Sorted";
66
67 input = new File(pathname);
68
69 if (!input.exists())
70 input.createNewFile();
71
72 String command = "sort -k3,3 -k4n,4 -T " + tmpD + " " + rawOutput+" > "+pathname;
73 Process p = rt.exec(command);
74 try{p.waitFor();}
75 catch(InterruptedException e){e.printStackTrace();}
76 System.out.println("Fertig");
77 /* Scanner ps = new Scanner(p.getInputStream());
78 FileWriter fw = new FileWriter(input);
79
80 while (ps.hasNextLine()) {
81 String nextLine = ps.nextLine();
82 fw.write(nextLine + "\r\n");
83 }
84
85 fw.close(); */
86
87 new File(rawOutput).delete();
88 new File(pathname).renameTo(new File(rawOutput));
89 System.out.println("File " + new File(rawOutput).getAbsolutePath()
90 + " sorted\n");
91
92 } catch (IOException e1) {
93 e1.printStackTrace();
94 }
95 }
96 }