Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Read CSI region #48

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

anamanolache
Copy link
Contributor

No description provided.

@@ -71,3 +82,73 @@ func BinsForRange(start, end uint32, minShift, depth int32) []uint16 {
func maximumBinWidth(minShift, depth int32) uint32 {
return uint32(1 << uint32(minShift+depth*3))
}

// Read reads index data from csi and returns a set of BGZF chunks covering
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anamanolache This is hard to read. Just say Reads a CSI formatted index file.

@@ -71,3 +82,73 @@ func BinsForRange(start, end uint32, minShift, depth int32) []uint16 {
func maximumBinWidth(minShift, depth int32) uint32 {
return uint32(1 << uint32(minShift+depth*3))
}

// Read reads index data from csi and returns a set of BGZF chunks covering

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

csiFile -> csi (it's a Reader, not a file)

Or just 'r' is fine too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


var minShift int32
if err := binary.Read(gzr, &minShift); err != nil {
return nil, fmt.Errorf("reading # bits for the minimal interval (min_shift): %v", err)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"reading minimum interval width: %v"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N/A, refactored code

return nil, fmt.Errorf("checking magic: %v", err)
}

var minShift int32

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minShift is a detail of the implementation - it's best to talk about widths outside the implementation of the function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return nil, fmt.Errorf("checking magic: %v", err)
}

var minShift int32

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd typically suggest you use a structure and read:

var header struct {
minimumWidth int32
depth int32
auxilaryLength int32
}
if err := binary.Read(gzr, &header) {
...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if err := binary.Read(gzr, &depth); err != nil {
return nil, fmt.Errorf("reading depth of binary index: %v", err)
}
bins := BinsForRange(region.Start, region.End, minShift, depth)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move closer to use

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -71,3 +82,68 @@ func BinsForRange(start, end uint32, minShift, depth int32) []uint16 {
func maximumBinWidth(minShift, depth int32) uint32 {
return uint32(1 << uint32(minShift+depth*3))
}

// Read reads index data from CSI and returns a set of BGZF chunks covering

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read reads CSI formatted index data from r and returns a set of ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if err := binary.Read(csi, &refCount); err != nil {
return nil, fmt.Errorf("reading the number of reference sequences: %v", err)
}
bins := BinsForRange(region.Start, region.End, csiHeader.MinimumWidth, csiHeader.Depth)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we'd factor out the common code between here and the BAM reader. The difficulty is the Offset field. It's OK to submit this now, but maybe file an issue about it. We could have some common function that takes a flag, for example, that would cover both.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done it now so I don't commit duplicate code to begin with.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants