File: SummaryFile.java

package info (click to toggle)
bbmap 39.20%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,024 kB
  • sloc: java: 312,743; sh: 18,099; python: 5,247; ansic: 2,074; perl: 96; makefile: 39; xml: 38
file content (174 lines) | stat: -rwxr-xr-x 5,262 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package fileIO;

import java.io.File;

import dna.Data;
import shared.Parse;
import shared.PreParser;

/**
 * Tests to see if a summary file matches a reference fasta file, based on date, size, and name
 * @author Brian Bushnell
 * @date Mar 11, 2013
 *
 */
public class SummaryFile {
	
	public static void main(String[] args){
		if(args.length==0){
			System.out.println("Usage: SummaryFile <summary file> <reference fasta>");
			System.exit(0);
		}

		{//Preparse block for help, config files, and outstream
			PreParser pp=new PreParser(args, new Object() { }.getClass().getEnclosingClass(), false);
			args=pp.args;
			//outstream=pp.outstream;
		}
		
		String summary=null, ref=null;
		
		for(int i=0; i<args.length; i++){

			if(args[i].contains("=")){
				final String arg=args[i];
				final String[] split=arg.split("=");
				String a=split[0].toLowerCase();
				String b=split.length>1 ? split[1] : null;
				
				if(a.equals("summary")){
					summary=b;
				}else if(a.equals("ref") || a.equals("reference")){
					ref=b;
				}else{
					throw new RuntimeException("Unknown parameter: "+args[i]);
				}

			}else{
				if(args[i].endsWith("summary.txt")){
					summary=args[i];
				}else{
					ref=args[i];
				}
			}
		}
		
		if(summary==null && args.length>0){
			summary=args[0];
		}
		
		if(summary==null){
			System.out.println("Usage: SummaryFile <summary file> <reference fasta>");
			System.exit(0);
		}
		
		if(ref==null){
			
		}
	}
	
	public boolean compare(final String refName){
		try {
			File ref=new File(refName);
			if(!ref.exists()){
				if(refName.startsWith("stdin")){return false;}
				else{
					assert(false) : "No such file: "+refName;
				}
			}
//			if(!refName.equals(source) && !Files.isSameFile(ref.toPath(), new File(source).toPath())){ //This is Java-7 specific.
////				assert(false) : refName+", "+source+": "+(Files.isSameFile(ref.toPath(), new File(source).toPath()))+
////						"\n"+ref.getCanonicalPath()+", "+new File(source).getCanonicalPath()+": "+(ref.getCanonicalPath().equals(new File(source).getCanonicalPath()));
//				return false;
//
//			}
			if(!refName.equals(source) && !ref.getCanonicalPath().equals(new File(source).getCanonicalPath())){
//				assert(false) : refName+", "+source+": "+(Files.isSameFile(ref.toPath(), new File(source).toPath()))+
//						"\n"+ref.getCanonicalPath()+", "+new File(source).getCanonicalPath()+": "+(ref.getCanonicalPath().equals(new File(source).getCanonicalPath()));
				return false;
				
			}
			if(bytes!=ref.length()){
//				assert(false) : bytes+", "+ref.length();
				return false;
			}
			if(modified!=ref.lastModified()){
//				assert(false) : modified+", "+ref.lastModified();
				return false;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		return true;
	}
	
	public static boolean compare(final String summaryName, final String refName){
		assert(refName!=null) : "Null reference file name.";
		if(!new File(summaryName).exists()){
//			assert(false);
			return false;
		}
		SummaryFile sf=new SummaryFile(summaryName);
		return sf.compare(refName);
	}
	
	public static String getName(){
		return getName(Data.GENOME_BUILD);
	}
	
	public static String getName(int build){
		return Data.ROOT_GENOME+build+"/summary.txt";
	}
	
	public SummaryFile(String path){
		summaryFname=path;
		String s;
		TextFile tf=new TextFile(summaryFname, false);
		for(s=tf.nextLine(); s!=null; s=tf.nextLine()){
			if(s.charAt(0)=='#'){
				if(s.startsWith("#Version")){
					String[] split=s.split("\t");
					version=(split.length>1 ? Integer.parseInt(split[1]) : 0);
				}
			}else{
				String[] split=s.split("\t");
				String a=split[0];
				String b=split[1];
				if(a.equalsIgnoreCase("chroms")){chroms=(int)Long.parseLong(b);}
				else if(a.equalsIgnoreCase("bases")){bases=Long.parseLong(b);}
				else if(a.equalsIgnoreCase("version")){version=Integer.parseInt(b);}
				else if(a.equalsIgnoreCase("defined")){definedBases=Long.parseLong(b);}
				else if(a.equalsIgnoreCase("contigs")){contigs=Integer.parseInt(b);}
				else if(a.equalsIgnoreCase("scaffolds")){scaffolds=Integer.parseInt(b);}
				else if(a.equalsIgnoreCase("interpad")){interpad=Integer.parseInt(b);}
				else if(a.equalsIgnoreCase("undefined")){undefinedBases=Long.parseLong(b);}
				else if(a.equalsIgnoreCase("name")){name=b;}
				else if(a.equalsIgnoreCase("source")){source=b;}
				else if(a.equalsIgnoreCase("bytes")){bytes=Long.parseLong(b);}
				else if(a.equalsIgnoreCase("last modified")){modified=Long.parseLong(b);}
				else if(a.equalsIgnoreCase("scafprefixes")){scafprefixes=Parse.parseBoolean(b);}
				else{throw new RuntimeException("In file "+tf.name+": Unknown term "+s);}
			}
		}
		tf.close();
	}

	public final String summaryFname;

	public int chroms;
	public long contigs;
	public long scaffolds;
	public int interpad;
	public long bases;
	public long definedBases;
	public long undefinedBases;
	public String name;
	public String source;
	public int version;
	public long bytes;
	public long modified;
	public boolean scafprefixes;
	
}