Cara yang betul untuk melaksanakan IGV.js dalam React
P粉748218846
P粉748218846 2023-09-01 11:50:19
0
1
510
<p>Saya cuba menggunakan IGV.js dalam React dan mendapati bahawa kod berikut mencipta dua div bekas dan bukannya satu: </p> <pre class="brush:php;toolbar:false;">var igvDiv = document.getElementById("igv-div"); pilihan var = { genom: "hg38", lokus: "chr8:127,736,588-127,739,371", lagu: [ { "nama": "HG00103", "url": "https://s3.amazonaws.com/1000genomes/data/HG00103/alignment/HG00103.alt_bwamem_GRCh38DH.20150718.GBR.low_coverage.cram", "indexURL": "https://s3.amazonaws.com/1000genomes/data/HG00103/alignment/HG00103.alt_bwamem_GRCh38DH.20150718.GBR.low_coverage.cram.crai", "format": "cram" } ] }; igv.createBrowser(igvDiv, pilihan) .then(fungsi (pelayar) { console.log("Pelayar IGV yang dicipta"); })</pre> <p>Kod React Saya lebih baik menggunakan useRef: </p> <pre class="brush:php;toolbar:false;">import React, { useRef, useEffect, Component } daripada 'react'; import igv daripada 'igv'; var igvStyle = { fonKeluarga: 'open sans,helveticaneue,helvetica neue,Helvetica,Arial,sans-serif', paddingTop: '60px', jidar: '5px' } kelas IGViewerSection memanjangkan Komponen { componentDidMount() { var igvContainer = document.getElementById('igv-div'); var igvOptions = { genom: "hg38", lokus: "chr8:127,736,588-127,739,371", lagu: [ { "nama": "HG00103", "url": "https://s3.amazonaws.com/1000genomes/data/HG00103/alignment/HG00103.alt_bwamem_GRCh38DH.20150718.GBR.low_coverage.cram", "indexURL": "https://s3.amazonaws.com/1000genomes/data/HG00103/alignment/HG00103.alt_bwamem_GRCh38DH.20150718.GBR.low_coverage.cram.crai", "format": "cram" } ] }; kembalikan igv.createBrowser(igvContainer, igvOptions); } render() { kembali ( <div id="igv-div" style={igvStyle}></div> ); } } eksport lalai IGViewerSection;</pre> <p>Saya mahu melaksanakan IGV.js dalam React menggunakan pendekatan yang betul. Bolehkah anda membimbing saya cara melaksanakan IGV.js dengan betul dalam React dan cara membetulkannya</p>
P粉748218846
P粉748218846

membalas semua(1)
P粉410239819

Berikut ialah versi yang betul, anda boleh menggunakan atribut ref untuk melampirkan objek ref anda pada komponen dan ia akan tersedia apabila komponen dipasang.

import React, { createRef, Component } from 'react';
import igv from 'igv';

const igvStyle = {
  fontFamily: 'open sans,helveticaneue,helvetica neue,Helvetica,Arial,sans-serif',
  paddingTop: '60px',
  margin: '5px'
}

class IGViewerSection extends Component {
  constructor(props) {
    super(props)
    this.container = createRef(null)
  }

  componentDidMount() {
    const igvOptions = {
      genome: "hg38",
      locus: "chr8:127,736,588-127,739,371",
      tracks: [
        {
          "name": "HG00103",
          "url": "https://s3.amazonaws.com/1000genomes/data/HG00103/alignment/HG00103.alt_bwamem_GRCh38DH.20150718.GBR.low_coverage.cram",
          "indexURL": "https://s3.amazonaws.com/1000genomes/data/HG00103/alignment/HG00103.alt_bwamem_GRCh38DH.20150718.GBR.low_coverage.cram.crai",
          "format": "cram"
        }
      ]
    };
    return igv.createBrowser(this.container.current, igvOptions);
  }

  render() {
    return (
      <div id="igv-div" ref={this.container} style={igvStyle}></div>
    );
  }
}
  

export default IGViewerSection;
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan