{"action":"created","issue":{"url":"https://api.github.com/repos/GMOD/cram-js/issues/18","repository_url":"https://api.github.com/repos/GMOD/cram-js","labels_url":"https://api.github.com/repos/GMOD/cram-js/issues/18/labels{/name}","comments_url":"https://api.github.com/repos/GMOD/cram-js/issues/18/comments","events_url":"https://api.github.com/repos/GMOD/cram-js/issues/18/events","html_url":"https://github.com/GMOD/cram-js/issues/18","id":394841200,"node_id":"MDU6SXNzdWUzOTQ4NDEyMDA=","number":18,"title":"Using example code with local sequence file","user":{"login":"shihabdider","id":12467607,"node_id":"MDQ6VXNlcjEyNDY3NjA3","avatar_url":"https://avatars1.githubusercontent.com/u/12467607?v=4","gravatar_id":"","url":"https://api.github.com/users/shihabdider","html_url":"https://github.com/shihabdider","followers_url":"https://api.github.com/users/shihabdider/followers","following_url":"https://api.github.com/users/shihabdider/following{/other_user}","gists_url":"https://api.github.com/users/shihabdider/gists{/gist_id}","starred_url":"https://api.github.com/users/shihabdider/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shihabdider/subscriptions","organizations_url":"https://api.github.com/users/shihabdider/orgs","repos_url":"https://api.github.com/users/shihabdider/repos","events_url":"https://api.github.com/users/shihabdider/events{/privacy}","received_events_url":"https://api.github.com/users/shihabdider/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-12-30T02:40:52Z","updated_at":"2018-12-30T19:05:28Z","closed_at":null,"author_association":"NONE","body":"I'm trying to do some benchmarking of CRAM-JS and am having some trouble with the example code. \r\n\r\nI have three cram files and their corresponding crai indices as well as the reference sequences in separate fasta files. I'd like to use the local reference sequences to read the cram files, but I'm not sure how to change the seqFetch argument to do this. Currently the code just seems to generate a fake sequence of A's and the documentation is not entirely clear on how to use the local sequence file. \r\n\r\nAlso there might be some bugs with fetch records portion of the code (e.g the await is not inside an async)\r\n\r\n```\r\nconst { IndexedCramFile, CramFile, CraiIndex } = require('@gmod/cram')\r\n\r\n// open local files\r\nconst indexedFile = new IndexedCramFile({\r\n  cramPath: require.resolve(`./data/ce#5.tmp.cram`),\r\n  index: new CraiIndex({\r\n    path: require.resolve(`./data/ce#5.tmp.cram.crai`),\r\n  }),\r\n  seqFetch: async (seqId, start, end) => {\r\n    // seqFetch should return a promise for a string.\r\n    // this one just returns a fake sequence of all A's of the proper length\r\n    let fakeSeq = ''\r\n    for (let i = start; i <= end; i += 1) {\r\n      fakeSeq += 'A'\r\n    }\r\n    return fakeSeq\r\n  },\r\n  checkSequenceMD5: false,\r\n})\r\n\r\n// example of fetching records from an indexed CRAM file.\r\n// NOTE: only numeric IDs for the reference sequence are accepted\r\nconst records = await indexedFile.getRecordsForRange(0, 10000, 20000)\r\nrecords.forEach(record => {\r\n  console.log(`got a record named ${record.readName}`)\r\n  record.readFeatures.forEach(({ code, pos, refPos, ref, sub }) => {\r\n    if (code === 'X')\r\n      console.log(\r\n        `${\r\n          record.readName\r\n        } shows a base substitution of ${ref}->${sub} at ${refPos}`,\r\n      )\r\n  })\r\n})\r\n\r\n\r\n// can also pass `cramUrl`, and `url` params to open remote URLs\r\n```"},"comment":{"url":"https://api.github.com/repos/GMOD/cram-js/issues/comments/450580369","html_url":"https://github.com/GMOD/cram-js/issues/18#issuecomment-450580369","issue_url":"https://api.github.com/repos/GMOD/cram-js/issues/18","id":450580369,"node_id":"MDEyOklzc3VlQ29tbWVudDQ1MDU4MDM2OQ==","user":{"login":"cmdcolin","id":6511937,"node_id":"MDQ6VXNlcjY1MTE5Mzc=","avatar_url":"https://avatars0.githubusercontent.com/u/6511937?v=4","gravatar_id":"","url":"https://api.github.com/users/cmdcolin","html_url":"https://github.com/cmdcolin","followers_url":"https://api.github.com/users/cmdcolin/followers","following_url":"https://api.github.com/users/cmdcolin/following{/other_user}","gists_url":"https://api.github.com/users/cmdcolin/gists{/gist_id}","starred_url":"https://api.github.com/users/cmdcolin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmdcolin/subscriptions","organizations_url":"https://api.github.com/users/cmdcolin/orgs","repos_url":"https://api.github.com/users/cmdcolin/repos","events_url":"https://api.github.com/users/cmdcolin/events{/privacy}","received_events_url":"https://api.github.com/users/cmdcolin/received_events","type":"User","site_admin":false},"created_at":"2018-12-30T19:05:28Z","updated_at":"2018-12-30T19:05:28Z","author_association":"CONTRIBUTOR","body":"You might consider implementing seqFetch with https://github.com/GMOD/indexedfasta-js or https://github.com/gmod/twobit-js. There is not any example code but the basic idea should be fairly straightforward. I guess ideally those modules would not be the bottleneck in CRAM decoding but it could be something to be aware of to make sure the sequence retrieval is not the bottleneck (could add cache layer or sequence chunking)\r\n\r\nAlso for the async/await, it's true it needs wrapping in an async function technically.  Ideally the JS community comes to some conclusion about \"top level await\" https://github.com/tc39/proposal-top-level-await "}}
{"actor":{"display_login":"cmdcolin"}}