-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
515 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...bigdata-app/src/test/java/org/opencb/hpg/bigdata/app/cli/local/VariantRvTestsCLITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.opencb.hpg.bigdata.app.cli.local; | ||
|
||
import org.junit.Test; | ||
|
||
import java.net.URISyntaxException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* Created by joaquin on 1/19/17. | ||
*/ | ||
public class VariantRvTestsCLITest { | ||
Path inPath; | ||
Path outPath; | ||
Path confPath; | ||
|
||
private void init() throws URISyntaxException { | ||
inPath = Paths.get("/home/jtarraga/data/vcf/skat/example.vcf.avro"); | ||
outPath = Paths.get("/home/jtarraga/data/vcf/skat/out"); | ||
confPath = Paths.get("/home/jtarraga/data/vcf/skat/skat.params"); | ||
} | ||
|
||
@Test | ||
public void skat() { | ||
|
||
try { | ||
init(); | ||
|
||
StringBuilder commandLine = new StringBuilder(); | ||
commandLine.append(" variant rvtests"); | ||
commandLine.append(" --log-level ERROR"); | ||
commandLine.append(" -i ").append(inPath); | ||
commandLine.append(" -o ").append(outPath); | ||
commandLine.append(" -c ").append(confPath); | ||
commandLine.append(" --dataset noname"); | ||
|
||
VariantQueryCLITest.execute(commandLine.toString()); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
...ta-tools/src/main/java/org/opencb/hpg/bigdata/tools/variant/analysis/RvTestsAnalysis.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package org.opencb.hpg.bigdata.tools.variant.analysis; | ||
|
||
import org.apache.spark.SparkConf; | ||
import org.apache.spark.SparkContext; | ||
import org.apache.spark.sql.Dataset; | ||
import org.apache.spark.sql.Encoders; | ||
import org.apache.spark.sql.Row; | ||
import org.apache.spark.sql.SparkSession; | ||
import org.opencb.biodata.formats.pedigree.PedigreeManager; | ||
import org.opencb.biodata.models.core.Region; | ||
import org.opencb.biodata.models.variant.VariantMetadataManager; | ||
import org.opencb.biodata.models.variant.avro.VariantAvro; | ||
import org.opencb.commons.utils.FileUtils; | ||
import org.opencb.hpg.bigdata.core.lib.SparkConfCreator; | ||
import org.opencb.hpg.bigdata.core.lib.VariantDataset; | ||
|
||
import java.io.*; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Created by joaquin on 1/19/17. | ||
*/ | ||
public class RvTestsAnalysis { | ||
private String inFilename; | ||
private String outDirname; | ||
private String confFilename; | ||
|
||
private final String RVTEST_BIN = "/home/jtarraga/softs/rvtests/executable/rvtest"; | ||
private final String BGZIP_BIN = "/home/joaquin/softs/htslib/bgzip"; | ||
private final String TABIX_BIN = "/home/joaquin/softs/htslib/tabix"; | ||
|
||
public RvTestsAnalysis(String inFilename, String outDirname, String confFilename) { | ||
this.inFilename = inFilename; | ||
this.outDirname = outDirname; | ||
this.confFilename = confFilename; | ||
} | ||
|
||
// ./build/bin/hpg-bigdata-local2.sh variant rvtests -i ~/data/vcf/skat/example.vcf.avro -o ~/data/vcf/skat/out --dataset noname -c ~/data/vcf/skat/skat.params | ||
|
||
public void run(String dataset) throws Exception { | ||
// create spark session | ||
SparkConf sparkConf = SparkConfCreator.getConf("variant rvtests", "local", 1, true); | ||
SparkSession sparkSession = new SparkSession(new SparkContext(sparkConf)); | ||
|
||
// load dataset | ||
VariantDataset vd = new VariantDataset(sparkSession); | ||
vd.load(inFilename); | ||
vd.createOrReplaceTempView("vcf"); | ||
|
||
// load rvtests parameters | ||
Properties prop = new Properties(); | ||
InputStream confStream = new FileInputStream(confFilename); | ||
prop.load(confStream); | ||
confStream.close(); | ||
|
||
for (Object key: prop.keySet()) { | ||
System.out.println((String) key + " = " + (String) prop.get(key)); | ||
} | ||
|
||
// create temporary directory | ||
File tmpDir = new File(outDirname + "/tmp"); | ||
tmpDir.mkdir(); | ||
|
||
// create temporary file for --pheno | ||
File phenoFile = new File(tmpDir.getAbsolutePath() + "/pheno"); | ||
VariantMetadataManager metadataManager = new VariantMetadataManager(); | ||
metadataManager.load(inFilename + ".meta.json"); | ||
new PedigreeManager().save(metadataManager.getPedigree(dataset), phenoFile.toPath()); | ||
|
||
// loop for regions | ||
String line; | ||
BufferedReader reader = FileUtils.newBufferedReader(Paths.get(prop.getProperty("setFile"))); | ||
int i = 0; | ||
StringBuilder cmdline = new StringBuilder(); | ||
while ((line = reader.readLine()) != null) { | ||
String[] fields = line.split("[\t ]"); | ||
System.out.println(fields[0]); | ||
String regionName = fields[0]; | ||
Region region = new Region(fields[1]); | ||
|
||
// create temporary files for --inVcf and --setFile | ||
File setFile = new File(tmpDir.getAbsolutePath() + "/setFile." + i); | ||
BufferedWriter writer = FileUtils.newBufferedWriter(setFile.toPath()); | ||
writer.write(fields[0] + "\t" + fields[1] + "\n"); | ||
writer.close(); | ||
|
||
// create temporary vcf file fot the region variants | ||
VariantDataset ds = (VariantDataset) vd.regionFilter(region); | ||
Dataset<VariantAvro> variantDS = ds.as(Encoders.bean(VariantAvro.class)); | ||
|
||
List<Row> rows = ds.collectAsList(); | ||
for (Row row: rows) { | ||
row.g | ||
System.out.println(row); | ||
} | ||
File vcfFile = new File(tmpDir.getAbsolutePath() + "/variants." + i + ".vcf"); | ||
|
||
// compress vcf to bgz | ||
cmdline.setLength(0); | ||
cmdline.append(this.BGZIP_BIN).append(" ").append(vcfFile.getAbsolutePath()); | ||
execute(cmdline.toString()); | ||
|
||
// and create tabix index | ||
cmdline.setLength(0); | ||
cmdline.append(this.TABIX_BIN).append(" -p vcf ").append(vcfFile.getAbsolutePath()).append(".gz"); | ||
execute(cmdline.toString()); | ||
|
||
// rvtests command line | ||
cmdline.setLength(0); | ||
cmdline.append(this.RVTEST_BIN).append(" --kernel skat --pheno ").append(phenoFile.getAbsolutePath()) | ||
.append(" --inVcf ").append(vcfFile.getAbsolutePath()).append(".gz") | ||
.append(" --setFile ").append(setFile.getAbsolutePath()) | ||
.append(" --out ").append(tmpDir.getAbsolutePath()).append("/out.").append(i); | ||
execute(cmdline.toString()); | ||
|
||
i++; | ||
} | ||
reader.close(); | ||
} | ||
|
||
|
||
private void execute(String cmdline) { | ||
try { | ||
System.out.println("Executing: " + cmdline); | ||
Process p = Runtime.getRuntime().exec(cmdline); | ||
|
||
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); | ||
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); | ||
|
||
// read the output from the command | ||
String s; | ||
System.out.println("Here is the standard output of the command:\n"); | ||
while ((s = stdInput.readLine()) != null) { | ||
System.out.println(s); | ||
} | ||
|
||
// read any errors from the attempted command | ||
System.out.println("Here is the standard error of the command (if any):\n"); | ||
while ((s = stdError.readLine()) != null) { | ||
System.out.println(s); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.