BAM import issues
Hi there,
I'm trying to get a BAM file to successfully import from a location on disk. I've indexed the BAM file. The combination of the BAM file and its reference sequences are fine if I import into the UI via drag-and-drop. However, when I try to import via my plug-in, I'm prompted to select a reference sequence. If I select the folder containing the reference sequences that I've imported via my plug-in, the BAM file is parsed correctly.
Below is a snippet of how I'm trying to import the BAM file. Can you advise or provide a minimal example of how to import a BAM file and its reference sequence(s) via public APIs?
Thanks,
Dave
```
-
Hi there,
Our SAM/BAM importer needs to have both the BAM file and reference passed to its DocumentFileImporter.importDocumentsFromMultipleFilesReturningUnimported() method.
Unfortunately this doesn't get used by any of our convenience utility classes, so you'll need to use it directly. Here is an example of how you can do it.
// Get importer
DocumentFileImporter importer = PluginUtilities.getDocumentFileImporters().stream()
.filter(imp ->
Arrays.stream(imp.getPermissibleExtensions()).anyMatch(extension -> extension.equalsIgnoreCase(".bam"))
).findFirst()
.orElseThrow(() -> new DocumentOperationException("No BAM importer available"));
// Create a ImportCallback that stores the results in an ArrayList
List<AnnotatedPluginDocument> imported = new ArrayList<>();
DocumentFileImporter.ImportCallback callback = new DocumentFileImporter.ImportCallback() {
@Override
public AnnotatedPluginDocument addDocument(PluginDocument document) {
AnnotatedPluginDocument apd = DocumentUtilities.createAnnotatedPluginDocument(document);
imported.add(apd);
return apd;
}
@Override
public AnnotatedPluginDocument addDocument(AnnotatedPluginDocument annotatedDocument) {
imported.add(annotatedDocument);
return annotatedDocument;
}
};
// Call the importers method directly and then add the results to the destination folder
List<File> unused = importer.importDocumentsFromMultipleFilesReturningUnimported(importerP.getOptions(files, ProgressListener.EMPTY), files, callback, ProgressListener.EMPTY);
for (AnnotatedPluginDocument toAdd : imported) {
destination.addDocumentCopy(toAdd, ProgressListener.EMPTY);
}0 -
Thanks - this got me unstuck and its working now!
0
Please sign in to leave a comment.
Comments
2 comments