本文整理汇总了Java中htsjdk.tribble.index.tabix.TabixFormat.GFF属性的典型用法代码示例。如果您正苦于以下问题:Java TabixFormat.GFF属性的具体用法?Java TabixFormat.GFF怎么用?Java TabixFormat.GFF使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类htsjdk.tribble.index.tabix.TabixFormat
的用法示例。
在下文中一共展示了TabixFormat.GFF属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: trackFormatToTabixFormat
public static TabixFormat trackFormatToTabixFormat(TrackFormat fmt){
TabixFormat tbx= null;
if(fmt.equals(TrackFormat.BAM)){
tbx= TabixFormat.SAM;
} else if (fmt.equals(TrackFormat.BED) || fmt.equals(TrackFormat.BEDGRAPH)){
tbx= TabixFormat.BED;
} else if (fmt.equals(TrackFormat.GFF) || fmt.equals(TrackFormat.GTF)){
tbx= TabixFormat.GFF;
} else if (fmt.equals(TrackFormat.VCF)){
tbx= TabixFormat.VCF;
} else {
throw new RuntimeException();
}
return tbx;
}
示例2: canCompressAndIndexSortedGzipFile
@Test
public void canCompressAndIndexSortedGzipFile() throws IOException, InvalidRecordException, ClassNotFoundException, SQLException {
String infile= "test_data/hg19_genes.gtf.gz";
File outfile= new File("test_data/tmp2.bed.gz");
outfile.deleteOnExit();
File expectedTbi= new File(outfile.getAbsolutePath() + TabixUtils.STANDARD_INDEX_EXTENSION);
expectedTbi.deleteOnExit();
new MakeTabixIndex(infile, outfile, TabixFormat.GFF);
assertTrue(outfile.exists());
assertTrue(outfile.length() > 7000000);
assertTrue(expectedTbi.exists());
assertTrue(expectedTbi.length() > 500000);
TabixReader tbx = new TabixReader(outfile.getAbsolutePath());
Iterator x = tbx.query("chr1", 1, 1000000);
assertTrue(x.next().startsWith("chr1"));
}
示例3: createGeneCompressedIndex
private void createGeneCompressedIndex(File indexFile, File file, GffCodec.GffType gffType) throws IOException {
AsciiFeatureCodec<GeneFeature> codec = new GffCodec(gffType);
TabixIndexCreator indexCreator = new TabixIndexCreator(TabixFormat.GFF);
try (
BlockCompressedInputStream inputStream = new BlockCompressedInputStream(new FileInputStream(file));
LittleEndianOutputStream outputStream = new LittleEndianOutputStream(
new BlockCompressedOutputStream(indexFile))
) {
long p = 0;
String line = inputStream.readLine();
while (line != null) {
//add the feature to the index
GeneFeature decode = codec.decode(line);
if (decode != null) {
indexCreator.addFeature(decode, p);
}
// read the next line if available
p = inputStream.getFilePointer();
line = inputStream.readLine();
}
// write the index to a file
Index index = indexCreator.finalizeIndex(p);
// VERY important! either use write based on input file or pass the little endian a BGZF stream
index.write(outputStream);
}
}
示例4: TrackBookmark
public TrackBookmark(GenomicCoords gc, String nameForBookmark) throws IOException, ClassNotFoundException, InvalidRecordException, SQLException, InvalidGenomicCoordsException{
super(gc);
this.setTrackTag(trackName);
// Prepare bookmark file
// =====================
// First write out the current position as plain text. Then gzip and index.
File bookmarkPlain= Utils.createTempFile(".asciigenome.bookmarks.", ".gff");
bookmarkPlain.deleteOnExit();
BufferedWriter wr = new BufferedWriter(new FileWriter(bookmarkPlain));
wr.write(this.positionToGffLine(gc, nameForBookmark) + "\n"); // gc.getChrom() + "\t" + (gc.getFrom() - 1) + "\t" + gc.getTo() + "\t" + nameForBookmark + "\n");
wr.close();
File bookmark= new File(bookmarkPlain + ".gz");
bookmark.deleteOnExit();
(new File(bookmark.getAbsolutePath() + ".tbi")).deleteOnExit();
this.setFilename(bookmark.getAbsolutePath());
this.setWorkFilename(bookmark.getAbsolutePath());
new MakeTabixIndex(bookmarkPlain.getAbsolutePath(), bookmark, TabixFormat.GFF);
bookmarkPlain.delete();
this.setTabixReader(new TabixReader(bookmark.getAbsolutePath()));
this.setTrackFormat(TrackFormat.GTF);
this.setGc(gc);
}
示例5: addBookmark
/** Add current genomic position to track.
* @throws IOException
* @throws SQLException
* @throws InvalidRecordException
* @throws ClassNotFoundException
* @throws InvalidGenomicCoordsException
* */
@Override
public void addBookmark(GenomicCoords gc, String nameForBookmark) throws IOException, ClassNotFoundException, InvalidRecordException, SQLException, InvalidGenomicCoordsException{
// Adding a bookmark means re-preparing the bgzip file again.
// First write the current position to a new tmp file, then append to this file
// all the bookmarks previously added. Then bgzip and compress replacing the old bookmark file.
File plainNew= new File(this.getWorkFilename() + ".add");
plainNew.deleteOnExit();
BufferedWriter wr = new BufferedWriter(new FileWriter(plainNew));
InputStream fileStream = new FileInputStream(this.getWorkFilename());
Reader decoder = new InputStreamReader(new GZIPInputStream(fileStream), "UTF-8");
BufferedReader br= new BufferedReader(decoder);
String line;
while( (line = br.readLine()) != null) {
if(line.contains("\t__ignore_me__")){ // Hack to circumvent issue #38
continue;
}
wr.write(line + "\n");
}
// Add new bookamrk
wr.write(this.positionToGffLine(gc, nameForBookmark) + "\n");
br.close();
wr.close();
// Recompress and index replacing the original bgzip file
new MakeTabixIndex(plainNew.getAbsolutePath(), new File(this.getWorkFilename()), TabixFormat.GFF);
plainNew.delete();
this.tabixReader= new TabixReader(this.getWorkFilename());
// Update track.
this.update();
}
示例6: removeBookmark
/** Remove the bookmark matching the exact coordinates of the current position.
* Bookmarks partially overlapping are not removed.
* @param bookmarkRegion
* @throws IOException
* @throws SQLException
* @throws InvalidRecordException
* @throws ClassNotFoundException
* @throws InvalidGenomicCoordsException
* */
public void removeBookmark(GenomicCoords bookmarkRegion) throws IOException, ClassNotFoundException, InvalidRecordException, SQLException, InvalidGenomicCoordsException {
// To remove a bookmark, iterate through the bgzip file writing records to a tmp file.
// The record(s) matching this position is not written.
//
File plainNew= new File(this.getWorkFilename() + ".remove");
plainNew.deleteOnExit();
BufferedWriter wr = new BufferedWriter(new FileWriter(plainNew));
InputStream fileStream = new FileInputStream(this.getWorkFilename());
Reader decoder = new InputStreamReader(new GZIPInputStream(fileStream), "UTF-8");
BufferedReader br= new BufferedReader(decoder);
String line;
while( (line = br.readLine()) != null) {
if( ! line.startsWith("#")){ // In case of comment lines
List<String>pos= Lists.newArrayList(Splitter.on("\t").split(line));
if(bookmarkRegion.getChrom().equals(pos.get(0)) &&
bookmarkRegion.getFrom() == Integer.parseInt(pos.get(3)) &&
bookmarkRegion.getTo() == Integer.parseInt(pos.get(4))){
continue;
}
}
wr.write(line + "\n");
}
wr.close();
br.close();
// Recompress and index replacing the original bgzip file
new MakeTabixIndex(plainNew.getAbsolutePath(), new File(this.getWorkFilename()), TabixFormat.GFF);
plainNew.delete();
this.tabixReader= new TabixReader(this.getWorkFilename());
// Update track.
this.update();
}
示例7: blockCompressAndIndex
/**
* Block compress input file and create associated tabix index. Newly created file and index are
* deleted on exit if deleteOnExit true.
* @throws IOException
* @throws InvalidRecordException
* */
private void blockCompressAndIndex(String in, String bgzfOut, boolean deleteOnExit) throws IOException, InvalidRecordException {
File inFile= new File(in);
File outFile= new File(bgzfOut);
LineIterator lin= utils.IOUtils.openURIForLineIterator(inFile.getAbsolutePath());
BlockCompressedOutputStream writer = new BlockCompressedOutputStream(outFile);
long filePosition= writer.getFilePointer();
TabixIndexCreator indexCreator=new TabixIndexCreator(TabixFormat.GFF);
while(lin.hasNext()){
String line = lin.next();
GtfLine gtf= new GtfLine(line.split("\t"));
writer.write(line.getBytes());
writer.write('\n');
indexCreator.addFeature(gtf, filePosition);
filePosition = writer.getFilePointer();
}
writer.flush();
File tbi= new File(bgzfOut + TabixUtils.STANDARD_INDEX_EXTENSION);
if(tbi.exists() && tbi.isFile()){
writer.close();
throw new RuntimeException("Index file exists: " + tbi);
}
Index index = indexCreator.finalizeIndex(writer.getFilePointer());
index.writeBasedOnFeatureFile(outFile);
writer.close();
if(deleteOnExit){
outFile.deleteOnExit();
File idx= new File(outFile.getAbsolutePath() + TabixUtils.STANDARD_INDEX_EXTENSION);
idx.deleteOnExit();
}
}
示例8: UcscGenePred
/** Fetch genePred data and convert it to tabix indexed GTF.
* @param maxRecords stop reading after this many records. If maxRecrods < 0 read entire data.
* Use this option to test whether connection is suitable genePred input.
* */
public UcscGenePred(String databaseTableOrFile, int maxRecords) throws IOException, InvalidCommandLineException, InvalidGenomicCoordsException, ClassNotFoundException, InvalidRecordException, SQLException{
if(maxRecords < 0){
maxRecords= Integer.MAX_VALUE;
}
// Prepare reader
File genePred= new File(databaseTableOrFile);
BufferedReader br;
if(genePred.isFile()){
try{
InputStream fileStream = new FileInputStream(genePred);
Reader decoder = new InputStreamReader(new GZIPInputStream(fileStream), "UTF-8");
br= new BufferedReader(decoder);
} catch (Exception e){
br= new BufferedReader(new FileReader(genePred));
}
} else if(Utils.urlFileExists(databaseTableOrFile)) {
br= this.readFromUrl(databaseTableOrFile);
} else {
// Read from UCSC if not local file or remote file.
List<String> conn= Lists.newArrayList((Splitter.on(":").omitEmptyStrings().split(databaseTableOrFile)));
if(conn.size() != 2){
System.err.println(databaseTableOrFile + " is not a local file and does not look like a string in the form database:table");
throw new InvalidCommandLineException();
}
br= this.readGenePredFromUcsc(conn.get(0), conn.get(1));
}
// Prepare output gtf file
String source= (new File(databaseTableOrFile).getName()).replaceAll(".txt.gz$|.txt$", "");
File tmpGtf= File.createTempFile("asciigenome.", ".ucsc." + source + ".gtf");
tmpGtf.deleteOnExit();
BufferedWriter wr= new BufferedWriter(new FileWriter(tmpGtf));
String line= null;
int i= 0;
while((line = br.readLine()) != null && i < maxRecords){
if(line.startsWith("#")){ // Are comment lines allowed at all?
continue;
}
List<IntervalFeature> gene= this.genePredRecordToGene(line, source);
i++;
for(IntervalFeature x : gene){
wr.write(x.getRaw() + "\n");
}
}
if(maxRecords == Integer.MAX_VALUE){
// System.err.println(i + " genePred records converted to " + j + " GTF features (" + Math.rint((t1-t0) / 1000) + " s).");
}
br.close();
wr.close();
// Tabix conversion
String infile= tmpGtf.getAbsolutePath();
File outfile= new File(infile + ".gz");
outfile.deleteOnExit();
File expectedTbi= new File(outfile.getAbsolutePath() + ".tbi");
expectedTbi.deleteOnExit();
new MakeTabixIndex(infile, outfile, TabixFormat.GFF);
tmpGtf.delete();
this.tabixFile= outfile.getAbsolutePath();
}