Comments (4)
The tabix_write
example can indeed be applied to create a tabix index for VFC on the fly. noodles-vcf/examples/vcf_index.rs
shows how to create one from a file and what record information is need to build the index.
For the latter case, we could also add a fn index<P: AsRef<Path>>(src: P) -> io::Result<csi::Index>
convenience function, if that would be useful.
from noodles.
@zaeleus , I am trying to do this with the following code, but the index does not seem to be correct. what do I miss?
Thanks in advance:
use noodles::core;
use noodles::csi::{self as csi, index::reference_sequence::bin::Chunk};
use noodles::vcf::header::record::value::{map::Contig, Map};
use noodles::vcf::record::Position;
use tempfile::tempdir;
fn write_vcf(
temp_dir: &PathBuf,
chrom: String,
start: usize,
reference: &str,
alternate: &str,
) -> String {
let vcf_path = temp_dir.join("test.vcf.gz");
let fs = File::create(&vcf_path).expect("error creating file");
let mut wtr = bgzf::Writer::new(&fs);
let mut writer = vcf::Writer::new(&mut wtr);
let id = chrom.parse().expect("error parsing chrom");
let contig = Map::<Contig>::new();
let header = vcf::Header::builder().add_contig(id, contig.clone()).build();
writer.write_header(&header).expect("error writing header");
let start_position = writer.get_ref().virtual_position();
let chrom = chrom.parse().expect("error parsing chrom");
let record = vcf::Record::builder()
.set_chromosome(chrom)
.set_position(Position::from(start))
.set_reference_bases(reference.parse().expect("error parsing reference"))
.set_alternate_bases(alternate.parse().expect("error parsing alternate"))
.set_info("AF=0.1".parse().expect("error parsing AF"))
.build()
.expect("error building record");
writer.write_record(&header, &record).expect("error writing test record");
let end_position = writer.get_ref().virtual_position();
let chunk = Chunk::new(start_position, end_position);
let alignment_context = Some((
0 as usize,
core::Position::try_from(start).expect("bad start in test"),
core::Position::try_from(start + reference.len()).expect("bad end in test"),
true,
));
let mut indexer =
csi::index::Indexer::default().set_header(csi::index::header::Builder::vcf().build());
indexer.add_record(alignment_context, chunk).expect("error indexing");
let index = indexer.build(1 as usize);
let index_path = vcf_path.clone().into_os_string().into_string().unwrap() + ".csi";
let index_file = File::create(&index_path).expect("error creating index file");
let mut index_writer = csi::Writer::new(index_file);
index_writer.write_index(&index).expect("error writing index");
wtr.finish().expect("error finishing bgzf");
return vcf_path.into_os_string().into_string().unwrap();
}
from noodles.
I am trying to do this with the following code, but the index does not seem to be correct. what do I miss?
Thanks for the example. The output is indeed incorrect, and the issues for these are being tracked in #215 and #216.
from noodles.
For the latter case, we could also add a
fn index<P: AsRef<Path>>(src: P) -> io::Result<csi::Index>
convenience function, if that would be useful.
@nh13, this is added in noodles 0.58.0 / noodles-vcf 0.46.0 as vcf::index
.
from noodles.
Related Issues (20)
- Unexpected EOF on BCF File HOT 2
- `sam::header::programs` module is private HOT 1
- How to set tag with value in noodles::bam? HOT 2
- Missing newlines in `header::record::write_other` when writing collections HOT 1
- Reading entries of file into preallocated buffer HOT 3
- Add Async GFF Reader and/or expose lazy record from string? HOT 2
- `gff::AsyncReader` gated by async feature HOT 2
- BCF and VCF `record_bufs` return different `RecordBuf`s HOT 2
- IUPAC codes in VCF REF field HOT 1
- Can support flush method on writer ? HOT 3
- BED name column limit HOT 1
- bgzf/async/reader: Add seeking to an uncompressed position
- How to write custom bam records HOT 1
- Help request: using the noodles async FASTQ writer with async compression without corrupting the output HOT 1
- QualityScore conversion from fastq HOT 2
- Create test SAM data HOT 2
- Performance question
- Explicitly state the indexing of alignment start and end HOT 1
- Trait bounds changes in noodles_sam 0.62.0 HOT 1
- sam/alignment/record/sequence: Add a method signature to return a single base at a given index HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from noodles.