GMOD / cram-js

Read CRAM v3 and v2 in node or in the browser
MIT License
18 stars 9 forks source link

Typescript build with esm module in package.json #98

Closed cmdcolin closed 2 years ago

cmdcolin commented 2 years ago

Similar to changes in other modules (bam, gff, indexedfasta, generic-filehandle, etc)

codecov[bot] commented 2 years ago

Codecov Report

Merging #98 (20af078) into master (ad9df19) will decrease coverage by 2.72%. The diff coverage is 89.51%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #98      +/-   ##
==========================================
- Coverage   89.59%   86.86%   -2.73%     
==========================================
  Files          34       40       +6     
  Lines        1499     1995     +496     
  Branches        0      406     +406     
==========================================
+ Hits         1343     1733     +390     
- Misses        156      237      +81     
- Partials        0       25      +25     
Impacted Files Coverage Δ
test/lib/fasta/indexedFasta.js 1.96% <14.28%> (ø)
src/io/bufferCache.js 5.55% <28.57%> (-0.90%) :arrow_down:
src/io/remoteFile.js 7.50% <50.00%> (-1.88%) :arrow_down:
src/rans/frequencies.js 92.20% <73.91%> (-7.80%) :arrow_down:
test/lib/fasta/index.js 84.61% <75.00%> (ø)
src/cramFile/container/index.js 92.45% <80.00%> (-3.01%) :arrow_down:
src/cramFile/file.js 91.02% <83.33%> (-1.17%) :arrow_down:
src/io/index.js 82.35% <83.33%> (-0.99%) :arrow_down:
src/cramFile/util.js 84.61% <84.61%> (-3.19%) :arrow_down:
src/cramFile/slice/index.js 87.01% <86.66%> (+0.54%) :arrow_up:
... and 60 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update ad9df19...20af078. Read the comment docs.

cmdcolin commented 2 years ago

CC @rbuels in case you are interested

changes the repo to use tsc to compile, just runs over the js, and creates esm module that is about 50% the bundle size

cmdcolin commented 2 years ago

Tested with the new cram-bundle.js generated by webpack and it works in the browser

<html>
  <head>
    <script src="https://unpkg.com/@gmod/cram/dist/cram-bundle.js"></script>
    <script>
      const { IndexedCramFile, CramFile, CraiIndex } = window.gmodCRAM

      // open local files
      const indexedFile = new IndexedCramFile({
        cramUrl: 'volvox-sorted.cram',
        index: new CraiIndex({
          url: 'volvox-sorted.cram.crai',
        }),
        seqFetch: async (seqId, start, end) => {
          return ''
        },
        checkSequenceMD5: false,
      })

      // example of fetching records from an indexed CRAM file.
      // NOTE: only numeric IDs for the reference sequence are accepted.
      // For indexedfasta the numeric ID is the order in which the sequence names appear in the header

      // Wrap in an async and then run
      run = async () => {
        const records = await indexedFile.getRecordsForRange(0, 10000, 20000)
        records.forEach(record => {
          console.log(`got a record named ${record.readName}`)
          if (record.readFeatures != undefined) {
            record.readFeatures.forEach(({ code, pos, refPos, ref, sub }) => {
              if (code === 'X') {
                console.log(
                  `${record.readName} shows a base substitution of ${ref}->${sub} at ${refPos}`,
                )
              }
            })
          }
        })
      }

      run()
    </script>
  </head>
  <body>
    <h1>Hello world</h1>
  </body>
</html>
cmdcolin commented 2 years ago

could try merge for now