Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle alternate line endings #3250

Merged
merged 1 commit into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test('test using the sequence feature panel', () => {
const readFasta = (filename: string) => {
return fs
.readFileSync(require.resolve(filename), 'utf8')
.split('\n')
.split(/\n|\r\n|\r/)
.slice(1)
.join('')
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/data_adapters/CytobandAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CytobandAdapter extends BaseAdapter {
}
const data = await openLocation(loc).readFile('utf8')
return data
.split('\n')
.split(/\n|\r\n|\r/)
.filter(f => !!f.trim())
.map(line => {
const [refName, start, end, name, type] = line.split('\t')
Expand Down
2 changes: 1 addition & 1 deletion plugins/alignments/src/CramAdapter/CramTestAdapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function parseSmallFasta(text: string) {
.split('>')
.filter(t => /\S/.test(t))
.map(entryText => {
const [defLine, ...seqLines] = entryText.split('\n')
const [defLine, ...seqLines] = entryText.split(/\n|\r\n|\r/)
const [id, ...descriptionLines] = defLine.split(' ')
const description = descriptionLines.join(' ')
const sequence = seqLines.join('').replace(/\s/g, '')
Expand Down
4 changes: 2 additions & 2 deletions plugins/bed/src/BedAdapter/BedAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class BedAdapter extends BaseFeatureDataAdapter {
throw new Error('Data exceeds maximum string length (512MB)')
}
const data = new TextDecoder('utf8', { fatal: true }).decode(buffer)
const lines = data.split('\n').filter(f => !!f)
const lines = data.split(/\n|\r\n|\r/).filter(f => !!f)
const headerLines = []
let i = 0
for (; i < lines.length && lines[i].startsWith('#'); i++) {
Expand Down Expand Up @@ -106,7 +106,7 @@ export default class BedAdapter extends BaseFeatureDataAdapter {
if (columnNames.length) {
return columnNames
}
const defs = header.split('\n').filter(f => !!f)
const defs = header.split(/\n|\r\n|\r/).filter(f => !!f)
const defline = defs[defs.length - 1]
return defline?.includes('\t')
? defline
Expand Down
2 changes: 1 addition & 1 deletion plugins/bed/src/BedTabixAdapter/BedTabixAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class BedTabixAdapter extends BaseFeatureDataAdapter {
return this.columnNames
}
const header = await this.bed.getHeader()
const defs = header.split('\n').filter(f => !!f)
const defs = header.split(/\n|\r\n|\r/).filter(f => !!f)
const defline = defs[defs.length - 1]
return defline?.includes('\t')
? defline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,6 @@ export default class ChainAdapter extends PAFAdapter {
throw new Error('Data exceeds maximum string length (512MB)')
}
const text = new TextDecoder('utf8', { fatal: true }).decode(buf)
return paf_chain2paf(text.split('\n').filter(line => !!line))
return paf_chain2paf(text.split(/\n|\r\n|\r/).filter(line => !!line))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@ export default class DeltaAdapter extends PAFAdapter {
}
const text = new TextDecoder('utf8', { fatal: true }).decode(buf)

return paf_delta2paf(text.split('\n').filter(line => !!line))
return paf_delta2paf(text.split(/\n|\r\n|\r/).filter(line => !!line))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class MCScanAnchorsAdapter extends BaseFeatureDataAdapter {
const bed1Map = parseBed(bed1text)
const bed2Map = parseBed(bed2text)
const feats = mcscantext
.split('\n')
.split(/\n|\r\n|\r/)
.filter(f => !!f && f !== '###')
.map((line, index) => {
const [name1, name2, score] = line.split('\t')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class MCScanAnchorsAdapter extends BaseFeatureDataAdapter {
const bed1Map = parseBed(bed1text)
const bed2Map = parseBed(bed2text)
const feats = mcscantext
.split('\n')
.split(/\n|\r\n|\r/)
.filter(f => !!f && f !== '###')
.map((line, index) => {
const [n11, n12, n21, n22, score, strand] = line.split('\t')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class MashMapAdapter extends PAFAdapter {

// mashmap produces PAF-like data that is space separated instead of tab
return text
.split('\n')
.split(/\n|\r\n|\r/)
.filter(line => !!line)
.map(line => {
const fields = line.split(' ')
Expand Down
2 changes: 1 addition & 1 deletion plugins/comparative-adapters/src/PAFAdapter/PAFAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default class PAFAdapter extends BaseFeatureDataAdapter {
const text = new TextDecoder('utf8', { fatal: true }).decode(buf)

return text
.split('\n')
.split(/\n|\r\n|\r/)
.filter(line => !!line)
.map(line => {
const [
Expand Down
2 changes: 1 addition & 1 deletion plugins/comparative-adapters/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function isGzip(buf: Buffer) {
export function parseBed(text: string) {
return new Map(
text
.split('\n')
.split(/\n|\r\n|\r/)
.filter(f => !!f || f.startsWith('#'))
.map(line => {
const [refName, start, end, name, score, strand] = line.split('\t')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class RefNameAliasAdapter
const refColumn = readConfObject(this.config, 'refNameColumn')
return results
.trim()
.split('\n')
.split(/\n|\r\n|\r/)
.filter(f => !!f && !f.startsWith('#'))
.map(row => {
const aliases = row.split('\t')
Expand Down
2 changes: 1 addition & 1 deletion plugins/gff3/src/Gff3Adapter/Gff3Adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class extends BaseFeatureDataAdapter {
throw new Error('Data exceeds maximum string length (512MB)')
}
const data = new TextDecoder('utf8', { fatal: true }).decode(buffer)
const lines = data.split('\n')
const lines = data.split(/\n|\r\n|\r/)
const headerLines = []
for (let i = 0; i < lines.length && lines[i].startsWith('#'); i++) {
headerLines.push(lines[i])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function ImportBookmarks({
}
const data = await openLocation(location).readFile('utf8')
const regions = data
.split('\n')
.split(/\n|\r\n|\r/)
.filter(f => !!f.trim())
.filter(
f =>
Expand Down
4 changes: 3 additions & 1 deletion plugins/gtf/src/GtfAdapter/GtfAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export default class extends BaseFeatureDataAdapter {
}
const data = new TextDecoder('utf8', { fatal: true }).decode(buf)

const lines = data.split('\n').filter(f => !!f && !f.startsWith('#'))
const lines = data
.split(/\n|\r\n|\r/)
.filter(f => !!f && !f.startsWith('#'))
const feats = {} as { [key: string]: string[] }
for (let i = 0; i < lines.length; i++) {
const line = lines[i]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function parse(text: string, url: string): Config {
}
}

text.split('\n').forEach((textLine, i): void => {
text.split(/\n|\r\n|\r/).forEach((textLine, i): void => {
lineNumber = i + 1
const line = textLine.replace(/^\s*#.+/, '')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class extends BaseAdapter implements RegionsAdapter {
const data = await file.readFile('utf8')
return Object.fromEntries(
data
.split('\n')
.split(/\n|\r\n|\r/)
.map(f => f.trim())
.filter(f => !!f)
.map((line: string) => {
Expand Down
2 changes: 1 addition & 1 deletion plugins/sequence/src/TwoBitAdapter/TwoBitAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class TwoBitAdapter extends BaseSequenceAdapter {
const data = await file.readFile('utf8')
return Object.fromEntries(
data
?.split('\n')
?.split(/\n|\r\n|\r/)
.filter(line => !!line.trim())
.map(line => {
const [name, length] = line.split('\t')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function parseVcfBuffer(
const rows: Row[] = []
const vcfParser = new VCF({ header })
header = '' // garbage collect
body.split('\n').forEach((line: string, lineNumber) => {
body.split(/\n|\r\n|\r/).forEach((line: string, lineNumber) => {
if (/\S/.test(line)) {
rows.push(vcfRecordToRow(vcfParser, line, lineNumber))
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/variants/src/VcfAdapter/VcfAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import VcfFeature from '../VcfTabixAdapter/VcfFeature'
const readVcf = (f: string) => {
const header: string[] = []
const rest: string[] = []
f.split('\n')
f.split(/\n|\r\n|\r/)
.map(f => f.trim())
.filter(f => !!f)
.forEach(line => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default function MultiWiggleWidget({ model }: { model: AddTrackModel }) {
try {
bigWigs = JSON.parse(val)
} catch (e) {
bigWigs = val.split('\n')
bigWigs = val.split(/\n|\r\n|\r/)
}
const obj =
typeof bigWigs[0] === 'string'
Expand Down
2 changes: 1 addition & 1 deletion scripts/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function main(changed, version) {
['--silent', 'lerna-changelog', '--next-version', version],
{ encoding: 'utf8' },
).stdout
const changelogLines = lernaChangelog.split('\n')
const changelogLines = lernaChangelog.split(/\n|\r\n|\r/)
const changedPackages = JSON.parse(changed)
const updatesTable = ['| Package | Download |', '| --- | --- |']
changedPackages.forEach(changedPackage => {
Expand Down