forked from mcgml/ImportToNeo4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
90 lines (67 loc) · 2.8 KB
/
Main.java
File metadata and controls
90 lines (67 loc) · 2.8 KB
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
package nhs.genetics.cardiff;
import htsjdk.variant.vcf.VCFFileReader;
import org.neo4j.graphdb.ConstraintViolationException;
import org.neo4j.io.fs.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.InvalidPropertiesFormatException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Main {
//todo update dbSNP
private static final Logger log = Logger.getLogger(Main.class.getName());
private static final String version = "1.0.4";
private static boolean newDatabase = false, addAnnotations = false;
public static void main(String[] args) throws InvalidPropertiesFormatException {
if (args.length < 2 || args.length > 3) {
System.err.println("ImportToNeo4j v" + version);
System.err.println("Usage: <VCF> <db>");
System.err.println("Options: -n New database, -a Annotated VCF");
System.exit(1);
}
log.log(Level.INFO, "ImportToNeo4j v" + version);
//update or overwrite, genotype or annotations?
for (String arg : args){
if (arg.equals("-n")){
newDatabase = true;
} else if (arg.equals("-a")){
addAnnotations = true;
}
}
if (newDatabase && addAnnotations){
log.log(Level.SEVERE, "Cannot create new database and add annotations simultaneously. Check arguments.");
System.exit(1);
}
if (newDatabase) {
log.log(Level.INFO, "Deleting existing database");
try{
FileUtils.deleteRecursively(new File(args[1]));
} catch (IOException e){
log.log(Level.SEVERE, "Could not delete database: " + e.getMessage());
System.exit(1);
}
}
log.log(Level.INFO, "Importing " + args[0] + " to " + args[1]);
//create VCF file parser
VCFFileReader vcfFileReader = new VCFFileReader(new File(args[0]), new File(args[0] + ".idx"));
//create database object
VariantDatabase variantDatabase = new VariantDatabase(vcfFileReader, new File(args[1]));
variantDatabase.startDatabase();
//add genotypes
if (!addAnnotations){
if (newDatabase) variantDatabase.createIndexes();
try {
variantDatabase.addSampleAndRunInfoNodes();
} catch (ConstraintViolationException e){
log.log(Level.SEVERE, "One or more analyses already exist in the database, check input.");
System.exit(1);
}
variantDatabase.importVariants();
variantDatabase.writeNewVariantsToVCF();
} else {
variantDatabase.importAnnotations();
}
variantDatabase.shutdownDatabase();
vcfFileReader.close();
}
}