Skip to content

Commit

Permalink
Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Aug 21, 2024
1 parent 5dfa77f commit acb1661
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
36 changes: 17 additions & 19 deletions test/cram2sam.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable no-console */
import { IndexedFasta } from '@gmod/indexedfasta'
import { CraiIndex, IndexedCramFile } from '../src'
import CramRecord from '../src/cramFile/record'

if (process.argv.length != 7) {
if (process.argv.length !== 7) {
process.stderr.write(
'Usage: node jkb_test.js REF.fa input.cram tid start end\n',
)
Expand All @@ -19,14 +20,14 @@ const end = Number.parseInt(endStr)
// Fasta
const t = new IndexedFasta({
path: process.argv[2],
faiPath: process.argv[2] + '.fai',
faiPath: `${process.argv[2]}.fai`,
})

// open local files
const indexedFile = new IndexedCramFile({
cramPath: process.argv[3],
index: new CraiIndex({
path: process.argv[3] + '.crai',
path: `${process.argv[3]}.crai`,
}),
seqFetch: async (seqId, start, end) => {
// note:
Expand Down Expand Up @@ -60,7 +61,7 @@ function decodeSeqCigar(record: CramRecord) {
seq += ref.slice(last_pos - refStart, refPos - refStart)
last_pos = refPos

if (oplen && op != 'M') {
if (oplen && op !== 'M') {
cigar += oplen + op
oplen = 0
}
Expand All @@ -86,53 +87,53 @@ function decodeSeqCigar(record: CramRecord) {
seq += sub
last_pos++
oplen++
} else if (code == 'D' || code == 'N') {
} else if (code === 'D' || code === 'N') {
// Deletion or Ref Skip
last_pos += data
if (oplen) {
cigar += oplen + op
}
cigar += data + code
oplen = 0
} else if (code == 'I' || code == 'S') {
} else if (code === 'I' || code === 'S') {
// Insertion or soft-clip
seq += data
if (oplen) {
cigar += oplen + op
}
cigar += data.length + code
oplen = 0
} else if (code == 'i') {
} else if (code === 'i') {
// Single base insertion
seq += data
if (oplen) {
cigar += oplen + op
}
cigar += 1 + 'I'
cigar += `${1}I`
oplen = 0
} else if (code == 'P') {
} else if (code === 'P') {
// Padding
if (oplen) {
cigar += oplen + op
}
cigar += data + 'P'
} else if (code == 'H') {
cigar += `${data}P`
} else if (code === 'H') {
// Hard clip
if (oplen) {
cigar += oplen + op
}
cigar += data + 'H'
cigar += `${data}H`
oplen = 0
} // else q or Q
})
} else {
sublen = record.readLength - seq.length
}
if (seq.length != record.readLength) {
if (seq.length !== record.readLength) {
sublen = record.readLength - seq.length
seq += ref.slice(last_pos - refStart, last_pos - refStart + sublen)

if (oplen && op != 'M') {
if (oplen && op !== 'M') {
cigar += oplen + op
oplen = 0
}
Expand Down Expand Up @@ -168,7 +169,7 @@ function tags2str(record: CramRecord, RG: string[]) {
}

if (record.readGroupId >= 0) {
str += '\tRG:Z:' + RG[record.readGroupId]
str += `\tRG:Z:${RG[record.readGroupId]}`
}
return str
}
Expand All @@ -179,16 +180,13 @@ async function run() {
const seqList = await t.getSequenceNames()
let tid: string | number = chr // ie numeric or string form
seqList.forEach((name, id) => {
if (name == chr) {
if (name === chr) {
tid = id
return
}
})

const hdr = await indexedFile.cram.getSamHeader()
if (!hdr) {
throw new Error('getSamHeader returned undefined')
}
const RG: string[] = []
let nRG = 0
for (const line of hdr) {
Expand Down
4 changes: 2 additions & 2 deletions test/example-code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ describe('code examples', () => {

// or with local files
const indexedFile2 = new IndexedCramFile({
cramPath: require.resolve(`./data/ce#5.tmp.cram`),
cramPath: require.resolve("./data/ce#5.tmp.cram"),
index: new CraiIndex({
path: require.resolve(`./data/ce#5.tmp.cram.crai`),
path: require.resolve("./data/ce#5.tmp.cram.crai"),
}),
seqFetch: async (seqId, start, end) => {
let fakeSeq = ''
Expand Down
2 changes: 1 addition & 1 deletion test/lib/syncLocalFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class LocalFile {
this.filename = source
}

async read(buffer, offset = 0, length, position) {
async read(buffer, offset, length, position) {
let readPosition = position
if (readPosition === null) {
readPosition = this.position
Expand Down
4 changes: 2 additions & 2 deletions test/lossy-names.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { CraiIndex, IndexedCramFile } from '../src'
describe('1kg mate test', () => {
it('runs without error', async () => {
const indexedCramFile = new IndexedCramFile({
cramPath: require.resolve(`./data/na12889_lossy.cram`),
cramPath: require.resolve("./data/na12889_lossy.cram"),
index: new CraiIndex({
path: require.resolve(`./data/na12889_lossy.cram.crai`),
path: require.resolve("./data/na12889_lossy.cram.crai"),
}),
seqFetch: async (seqId, start, end) => {
let fakeSeq = ''
Expand Down

0 comments on commit acb1661

Please sign in to comment.