import { ConfigurationSchema } from '@jbrowse/core/configuration' ; import AdapterType from '@jbrowse/core/pluggableElementTypes/AdapterType' ; import DisplayType from '@jbrowse/core/pluggableElementTypes/DisplayType' ; import { createBaseTrackConfig , createBaseTrackModel , } from '@jbrowse/core/pluggableElementTypes/models' ; import TrackType from '@jbrowse/core/pluggableElementTypes/TrackType' ; import Plugin from '@jbrowse/core/Plugin' ; import PluginManager from '@jbrowse/core/PluginManager' ; import { BaseLinearDisplayComponent } from '@jbrowse/plugin-linear-genome-view' ; import { FileLocation } from '@jbrowse/core/util/types' ; import Color from 'color' ; import HicRenderer , { configSchema as hicRendererConfigSchema , ReactComponent as HicRendererReactComponent , } from './HicRenderer' ; import { configSchemaFactory as linearHicdisplayConfigSchemaFactory , modelFactory as linearHicdisplayModelFactory , } from './LinearHicDisplay' ; import hicAdapterConfigSchema from './HicAdapter/configSchema' ; import { AdapterGuesser , getFileName , TrackTypeGuesser , } from '@jbrowse/core/util/tracks' ; export default class HicPlugin extends Plugin { name = 'HicPlugin' ; install ( pluginManager ) { pluginManager . addAdapterType ( ( ) => new AdapterType ( { name : 'HicAdapter' , configSchema : hicAdapterConfigSchema , getAdapterClass : ( ) => import ( './HicAdapter/HicAdapter' ) . then ( r => r . default ) , } ) ) ; pluginManager . addToExtensionPoint ( 'Core-guessAdapterForLocation' , ( adapterGuesser ) => { return ( file , index ? , adapterHint ? ) => { const regexGuess = /\.hic/i ; const adapterName = 'HicAdapter' ; const fileName = getFileName ( file ) ; if ( regexGuess . test ( fileName ) || adapterHint === adapterName ) { return { type : adapterName , hicLocation : file , } ; } return adapterGuesser ( file , index , adapterHint ) ; } ; } ) ; pluginManager . addToExtensionPoint ( 'Core-guessTrackTypeForLocation' , ( trackTypeGuesser ) => { return ( adapterName ) => { if ( adapterName === 'HicAdapter' ) { return 'HicTrack' ; } return trackTypeGuesser ( adapterName ) ; } ; } ) ; pluginManager . addRendererType ( ( ) => new HicRenderer ( { name : 'HicRenderer' , ReactComponent : HicRendererReactComponent , configSchema : hicRendererConfigSchema , pluginManager , } ) ) ; pluginManager . addTrackType ( ( ) => { const configSchema = ConfigurationSchema ( 'HicTrack' , { } , { baseConfiguration : createBaseTrackConfig ( pluginManager ) , explicitIdentifier : 'trackId' , } ) ; return new TrackType ( { name : 'HicTrack' , configSchema , stateModel : createBaseTrackModel ( pluginManager , 'HicTrack' , configSchema ) , } ) ; } ) ; pluginManager . addDisplayType ( ( ) => { const configSchema = linearHicdisplayConfigSchemaFactory ( pluginManager ) ; return new DisplayType ( { name : 'LinearHicDisplay' , configSchema , stateModel : linearHicdisplayModelFactory ( configSchema ) , trackType : 'HicTrack' , viewType : 'LinearGenomeView' , ReactComponent : BaseLinearDisplayComponent , } ) ; } ) ; } configure ( pluginManager ) { pluginManager . jexl . addFunction ( 'alpha' , ( color , value ) => color . alpha ( value ) ) ; pluginManager . jexl . addFunction ( 'hsl' , ( color ) => color . hsl ( ) ) ; pluginManager . jexl . addFunction ( 'colorString' , ( color ) => color . string ( ) ) ; } }