Updating a file rondom access
To work with a memory-mapped file, you must create a view of the entire memory-mapped file or a part of it.
You can also create multiple views to the same part of the memory-mapped file, thereby creating concurrent memory.
The random seek methods will overwhelmingly pick out the long record.
(perhaps there should be), and existing answers suggest a lot of munging.
If you are writing production code, then you probably want to take extra precautions. This would get you the log(n) lookup time you want. You could 2-bit encode the bases and quantize the quals to save some space, but that'd be lossy and is perhaps not what you're looking for.
If more than one record is to be retrieved, then the index needs to be stored in memory, perhaps with a framework such as pysam or htslib.output.grabix index output.# retrieve 5-th record (1-based) in log(n) time # requires some math to convert indices (4*4 1, 4*4 4) = (17, 20) grabix grab output.17 20 # Count the number of records for part two of this question export N_LINES=$(gzip -dc output.| wc -l) output.tabix -s 1 -b 2 -e 2 output.# now retrieve the 5th record (1-based) in log(n) time tabix output.dummy:5-5 # This command will retrieve the 5th record and convert it record back into FASTQ format tabix output.dummy:5-5 | perl -pe 's/^dummy\t\d \t//' | tr '\t' '\n' # Count the number of records for part two of this question export N_RECORDS=$(gzip -dc output.| wc -l) # random_import os import random n_records = int(os.environ["N_LINES"]) // 4 rand_record_start = random.randrange(0, n_records) * 4 1 rand_record_end = rand_record_start 3 os.system("grabix grab output.".format(rand_record_start, rand_record_end)) # random_import os import random n_records = int(os.environ["N_RECORDS"]) rand_record_index = random.randrange(0, n_records) 1 # super ugly, but works...os.system( "tabix output.dummy:- | perl -pe 's/^dummy\t\d \t//' | tr '\t' '\n'".format( rand_record_index) ) calls a system shell and is vulnerable to shell injection vulnerabilities.To retrieve access or audit rules from an existing file, use the Get Access Control method. Size Of(Get Type(My Color)) Dim color As My Color Dim i As Long = 0 ' Make changes to the view. The following sequence of actions occur: Imports System. Create View Stream() Dim writer As Binary Writer = New Binary Writer(Stream) writer. Create View Stream() Dim reader As Binary Reader = New Binary Reader(Stream) Console.
The Create From File methods create a memory-mapped file from an existing file on disk.
Whilst they probably work, some appear cumbersome and have many steps in which you could make a mistake.