Skip to content
Snippets Groups Projects
Select Git revision
  • 901fac97a095c45cab591d04c277da9aa3f89dc5
  • master default protected
  • rednatco-v2
  • base-pairs-ladder
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

parser.ts

  • parser.ts 1.66 KiB
    /**
     * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author Alexander Rose <alexander.rose@weirdbyte.de>
     */
    
    import { ReaderResult as Result } from '../result'
    import { Task } from '../../../mol-task'
    import { parseCsv } from '../csv/parser';
    import { Column, Table } from '../../../mol-data/db';
    import { toTable } from '../cif/schema';
    
    import Schema = Column.Schema
    import { CsvTable } from '../csv/data-model';
    
    
    export const Schema3DG = {
        /** Chromosome name */
        chromosome: Schema.str,
        /** Base position */
        position: Schema.int,
        /** X coordinate */
        x: Schema.float,
        /** Y coordinate */
        y: Schema.float,
        /** Z coordinate */
        z: Schema.float,
    }
    export type Schema3DG = typeof Schema3DG
    
    export interface File3DG {
        table: Table<Schema3DG>
    }
    
    const FieldNames = [ 'chromosome', 'position', 'x', 'y', 'z' ]
    
    function categoryFromTable(name: string, table: CsvTable) {
        return {
            name,
            rowCount: table.rowCount,
            fieldNames: FieldNames,
            getField: (name: string) => {
                return table.getColumn(FieldNames.indexOf(name).toString())
            }
        }
    }
    
    export function parse3DG(data: string) {
        return Task.create<Result<File3DG>>('Parse 3DG', async ctx => {
            const opts = { quote: '', comment: '#', delimiter: '\t', noColumnNames: true }
            const csvFile = await parseCsv(data, opts).runInContext(ctx)
            if (csvFile.isError) return Result.error(csvFile.message, csvFile.line)
            const category = categoryFromTable('3dg', csvFile.result.table)
            const table = toTable(Schema3DG, category)
            return Result.success({ table })
        });
    }