Skip to content

Commit

Permalink
[alleles] Rename Alleler properties
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed Jul 3, 2019
1 parent 0d4af65 commit 7e264e0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
23 changes: 11 additions & 12 deletions alleles.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (

// Alleler is responsible for building the allele table
type Alleler struct {
PafFile string // ex. "genome.paf"
REFile string // ex. "genome.counts_GATC.txt"
Paf PAF // The PAF data
ReFile RECountsFile // The RE data
PafFile string // ex. "genome.paf"
ReFile string // ex. "genome.counts_GATC.txt"
Paf PAFFile // The PAF data
ReCounts RECountsFile // The RE data
}

// Tag represents the additional info in the 12+ columns in the PAF
Expand Down Expand Up @@ -70,13 +70,13 @@ type PAFRecord struct {
}

// PAF parses the PAF file into a set of records
type PAF struct {
type PAFFile struct {
PafFile string // File path of the paf
Records []PAFRecord // List of PAF records
}

// ParseRecords collects all records in memory
func (r *PAF) ParseRecords() {
func (r *PAFFile) ParseRecords() {
r.Records = []PAFRecord{}
fh := mustOpen(r.PafFile)

Expand Down Expand Up @@ -137,19 +137,18 @@ func (r *PAF) ParseRecords() {

// extractAllelicPairs collects Extract allelic pairs
func (r *Alleler) extractAllelicPairs() {

// Sort the contigs by sizes, starting from shortest
sort.Slice(r.ReFile.Records, func(i, j int) bool {
return r.ReFile.Records[i].Length < r.ReFile.Records[j].Length
sort.Slice(r.ReCounts.Records, func(i, j int) bool {
return r.ReCounts.Records[i].Length < r.ReCounts.Records[j].Length
})
}

// Run kicks off the Alleler
func (r *Alleler) Run() {
r.Paf = PAF{PafFile: r.PafFile}
r.Paf = PAFFile{PafFile: r.PafFile}
r.Paf.ParseRecords()
r.ReFile = RECountsFile{Filename: r.REFile}
r.ReFile.ParseRecords()
r.ReCounts = RECountsFile{Filename: r.ReFile}
r.ReCounts.ParseRecords()
r.extractAllelicPairs()
log.Notice("Success")
}
8 changes: 4 additions & 4 deletions alleles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func setupAlleler() allhic.Alleler {
pafFile := filepath.Join("tests", "test.paf")
reFile := filepath.Join("tests", "test.counts_RE.txt")
alleler := allhic.Alleler{PafFile: pafFile, REFile: reFile}
alleler := allhic.Alleler{PafFile: pafFile, ReFile: reFile}
alleler.Run()
return alleler
}
Expand All @@ -36,10 +36,10 @@ func TestParsePafFile(t *testing.T) {
}
expectedCmValue := 5277
if cmValue != expectedCmValue {
t.Fatalf("The first record is expected to have cm = %d, got %d", expectedCmValue, cmValue)
t.Fatalf("The first record is expected to have cm %d, got %d", expectedCmValue, cmValue)
}
expectedLength := 135917
if gotLength := alleler.ReFile.Records[0].Length; gotLength != expectedLength {
t.Fatalf("The first record is expected to have length=%d, got %d", expectedLength, gotLength)
if gotLength := alleler.ReCounts.Records[0].Length; gotLength != expectedLength {
t.Fatalf("The first record is expected to have length %d, got %d", expectedLength, gotLength)
}
}
2 changes: 1 addition & 1 deletion cmd/allhic.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ ALLHiC generates "alleles.table", which can then be used for later steps.

pafFile := c.Args().Get(0)
reFile := c.Args().Get(1)
p := allhic.Alleler{PafFile: pafFile, REFile: reFile}
p := allhic.Alleler{PafFile: pafFile, ReFile: reFile}
p.Run()
return nil
},
Expand Down

0 comments on commit 7e264e0

Please sign in to comment.