-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some adapters for uniprot alphafold data
- Loading branch information
Showing
8 changed files
with
257 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/AlphaFoldConfidenceAdapter/AlphaFoldConfidenceAdapter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { | ||
BaseFeatureDataAdapter, | ||
BaseOptions, | ||
} from '@jbrowse/core/data_adapters/BaseAdapter' | ||
import { openLocation } from '@jbrowse/core/util/io' | ||
import { ObservableCreate } from '@jbrowse/core/util/rxjs' | ||
import { | ||
Region, | ||
Feature, | ||
doesIntersect2, | ||
SimpleFeature, | ||
} from '@jbrowse/core/util' | ||
|
||
export default class AlphaFoldConfidenceAdapter extends BaseFeatureDataAdapter { | ||
public static capabilities = ['getFeatures', 'getRefNames'] | ||
|
||
public feats: | ||
| Promise<{ uniqueId: string; start: number; end: number; score: number }[]> | ||
| undefined | ||
|
||
private async loadDataP() { | ||
const scores = JSON.parse( | ||
await openLocation(this.getConf('location')).readFile('utf8'), | ||
) as { residueNumber: number[]; confidenceScore: number[] } | ||
|
||
return scores.residueNumber.map((value, idx) => ({ | ||
uniqueId: `feat-${idx}`, | ||
start: value, | ||
end: value + 1, | ||
score: scores.confidenceScore[idx]!, | ||
})) | ||
} | ||
|
||
private async loadData(_opts: BaseOptions = {}) { | ||
if (!this.feats) { | ||
this.feats = this.loadDataP().catch((e: unknown) => { | ||
this.feats = undefined | ||
throw e | ||
}) | ||
} | ||
|
||
return this.feats | ||
} | ||
|
||
public async getRefNames(_opts: BaseOptions = {}) { | ||
return [] | ||
} | ||
|
||
public getFeatures(query: Region, opts: BaseOptions = {}) { | ||
return ObservableCreate<Feature>(async observer => { | ||
const { start, end, refName } = query | ||
const data = await this.loadData() | ||
for (const f of data) { | ||
if (doesIntersect2(f.start, f.end, start, end)) { | ||
observer.next(new SimpleFeature({ ...f, refName })) | ||
} | ||
} | ||
observer.complete() | ||
}, opts.signal) | ||
} | ||
|
||
public freeResources(): void {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ConfigurationSchema } from '@jbrowse/core/configuration' | ||
|
||
/** | ||
* #config AlphaFoldConfidenceAdapter | ||
*/ | ||
function x() {} // eslint-disable-line @typescript-eslint/no-unused-vars | ||
|
||
const AlphaFoldConfidenceAdapter = ConfigurationSchema( | ||
'AlphaFoldConfidenceAdapter', | ||
{ | ||
/** | ||
* #slot | ||
*/ | ||
location: { | ||
type: 'fileLocation', | ||
defaultValue: { uri: '/path/to/my.bed.gz', locationType: 'UriLocation' }, | ||
}, | ||
}, | ||
{ explicitlyTyped: true }, | ||
) | ||
export default AlphaFoldConfidenceAdapter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import PluginManager from '@jbrowse/core/PluginManager' | ||
import AdapterType from '@jbrowse/core/pluggableElementTypes/AdapterType' | ||
|
||
import configSchema from './configSchema' | ||
|
||
export default function AlphaFoldConfidenceAdapterF( | ||
pluginManager: PluginManager, | ||
) { | ||
pluginManager.addAdapterType( | ||
() => | ||
new AdapterType({ | ||
name: 'AlphaFoldConfidenceAdapter', | ||
displayName: 'AlphaFoldConfidence adapter', | ||
configSchema, | ||
getAdapterClass: () => | ||
import('./AlphaFoldConfidenceAdapter').then(r => r.default), | ||
}), | ||
) | ||
} |
109 changes: 109 additions & 0 deletions
109
src/AlphaMissensePathogenicityAdapter/AlphaMissensePathogenicityAdapter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { | ||
BaseFeatureDataAdapter, | ||
BaseOptions, | ||
} from '@jbrowse/core/data_adapters/BaseAdapter' | ||
import { openLocation } from '@jbrowse/core/util/io' | ||
import { ObservableCreate } from '@jbrowse/core/util/rxjs' | ||
import { | ||
Region, | ||
Feature, | ||
doesIntersect2, | ||
SimpleFeature, | ||
max, | ||
min, | ||
} from '@jbrowse/core/util' | ||
|
||
export default class AlphaMissensePathogenicityAdapter extends BaseFeatureDataAdapter { | ||
public static capabilities = ['getFeatures', 'getRefNames'] | ||
|
||
public feats: | ||
| Promise< | ||
{ | ||
uniqueId: string | ||
start: number | ||
end: number | ||
score: number | ||
ref: string | ||
variant: string | ||
am_class: string | ||
}[] | ||
> | ||
| undefined | ||
|
||
private async loadDataP() { | ||
const scores = await openLocation(this.getConf('location')).readFile('utf8') | ||
return scores | ||
.split('\n') | ||
.slice(1) | ||
.map(f => f.trim()) | ||
.filter(f => !!f) | ||
.map((row, idx) => { | ||
const [protein_variant, score, am_class] = row.split(',') | ||
const ref = protein_variant![0] | ||
const variant = protein_variant!.at(-1) | ||
const coord = protein_variant!.slice(1, -1) | ||
return { | ||
uniqueId: `feat-${idx}`, | ||
ref: ref!, | ||
variant: variant!, | ||
start: +coord, | ||
end: +coord + 1, | ||
score: +score!, | ||
am_class: am_class!, | ||
} | ||
}) | ||
} | ||
|
||
private async loadData(_opts: BaseOptions = {}) { | ||
if (!this.feats) { | ||
this.feats = this.loadDataP().catch((e: unknown) => { | ||
this.feats = undefined | ||
throw e | ||
}) | ||
} | ||
|
||
return this.feats | ||
} | ||
|
||
public async getGlobalStats(_opts?: BaseOptions) { | ||
const data = await this.loadData() | ||
const scoreMin = min(data.map(s => s.score)) | ||
const scoreMax = max(data.map(s => s.score)) | ||
return { scoreMin, scoreMax } | ||
} | ||
|
||
// always render bigwig instead of calculating a feature density for it | ||
async getMultiRegionFeatureDensityStats(_regions: Region[]) { | ||
return { featureDensity: 0 } | ||
} | ||
public async getRefNames(_opts: BaseOptions = {}) { | ||
return [] | ||
} | ||
|
||
public getFeatures(query: Region, opts: BaseOptions = {}) { | ||
return ObservableCreate<Feature>(async observer => { | ||
const { start, end, refName } = query | ||
const data = await this.loadData() | ||
for (const f of data) { | ||
if (doesIntersect2(f.start, f.end, start, end)) { | ||
observer.next(new SimpleFeature({ ...f, refName, source: f.variant })) | ||
} | ||
} | ||
observer.complete() | ||
}, opts.signal) | ||
} | ||
|
||
public async getSources() { | ||
const sources = new Set<string>() | ||
const data = await this.loadData() | ||
for (const f of data) { | ||
sources.add(f.variant) | ||
} | ||
return [...sources].map(s => ({ | ||
name: s, | ||
__name: s, | ||
})) | ||
} | ||
|
||
public freeResources(): void {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ConfigurationSchema } from '@jbrowse/core/configuration' | ||
|
||
/** | ||
* #config AlphaMissensePathogenicityAdapter | ||
*/ | ||
function x() {} // eslint-disable-line @typescript-eslint/no-unused-vars | ||
|
||
const AlphaMissensePathogenicityAdapter = ConfigurationSchema( | ||
'AlphaMissensePathogenicityAdapter', | ||
{ | ||
/** | ||
* #slot | ||
*/ | ||
location: { | ||
type: 'fileLocation', | ||
defaultValue: { uri: '/path/to/my.bed.gz', locationType: 'UriLocation' }, | ||
}, | ||
}, | ||
{ explicitlyTyped: true }, | ||
) | ||
export default AlphaMissensePathogenicityAdapter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import PluginManager from '@jbrowse/core/PluginManager' | ||
import AdapterType from '@jbrowse/core/pluggableElementTypes/AdapterType' | ||
|
||
import configSchema from './configSchema' | ||
|
||
export default function AlphaMissensePathogenicityAdapterF( | ||
pluginManager: PluginManager, | ||
) { | ||
pluginManager.addAdapterType( | ||
() => | ||
new AdapterType({ | ||
name: 'AlphaMissensePathogenicityAdapter', | ||
displayName: 'AlphaMissensePathogenicity adapter', | ||
configSchema, | ||
getAdapterClass: () => | ||
import('./AlphaMissensePathogenicityAdapter').then(r => r.default), | ||
}), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters