package jalview.io;
import jalview.datamodel.CigarParser;
+import jalview.datamodel.Range;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import java.io.File;
import java.io.IOException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.PrimitiveIterator.OfInt;
import java.util.SortedMap;
import htsjdk.samtools.SAMRecord;
import htsjdk.samtools.SAMRecordIterator;
import htsjdk.samtools.SAMSequenceRecord;
+import htsjdk.samtools.SamInputResource;
import htsjdk.samtools.SamReader;
import htsjdk.samtools.SamReaderFactory;
import htsjdk.samtools.ValidationStringency;
public BamFile(FileParse source) throws IOException
{
super(true, source);
+ parseSuffix();
final SamReaderFactory factory = SamReaderFactory.makeDefault()
.enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS,
SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS)
.validationStringency(ValidationStringency.SILENT);
// File-based bam
- fileReader = factory.open(source.inFile);
+ if (source.getDataSourceType() == DataSourceType.FILE)
+ {
+ fileReader = factory.open(source.inFile);
+ }
+ else
+ {
+ // locate index ?
+ String index = source.getDataName() + ".bai";
+ fileReader = factory.open(SamInputResource.of(source.getDataName())
+ .index(new URL(index)));
+ }
}
@Override
chromosome = chr;
start = s;
end = e;
+ suffix = chromosome + ":" + start + "-" + end;
+ }
+
+ public boolean parseSuffix()
+ {
+ if (suffix == null)
+ {
+ return false;
+ }
+ int csep = suffix.indexOf(":");
+ int rsep = suffix.indexOf("-", csep);
+ if (csep < 0 || rsep < 0 || suffix.length() - rsep <= 1)
+ {
+ return false;
+ }
+ String chr, p1, p2;
+ chr = suffix.substring(0, csep);
+ p1 = suffix.substring(csep + 1, rsep);
+ p2 = suffix.substring(rsep + 1);
+ int cstart, cend;
+ try
+ {
+ cstart = Integer.parseInt(p1);
+ cend = Integer.parseInt(p2);
+ } catch (Exception e)
+ {
+ warningMessage = (warningMessage == null ? "" : warningMessage + "\n")
+ + "Couldn't parse range from " + suffix;
+ return false;
+ }
+ chromosome = chr;
+ start = cstart;
+ end = cend;
+ return true;
}
}
fa.prepareFileReader(file, protocol, format);
source = fa.getAlignFile();
}
-
- BamFileOptionsChooser bamoptions = new BamFileOptionsChooser(
- source);
-
- // ask the user which bit of the bam they want to load
- int confirm = JvOptionPane.showConfirmDialog(null,
- bamoptions,
- MessageManager.getString("label.bam_file_options"),
- JvOptionPane.OK_CANCEL_OPTION,
- JvOptionPane.PLAIN_MESSAGE);
-
- if (confirm == JvOptionPane.CANCEL_OPTION
- || confirm == JvOptionPane.CLOSED_OPTION)
- {
- Desktop.instance.stopLoading();
- return;
- }
- else
+ if (!((BamFile) source).parseSuffix())
{
- bamoptions.update(source);
- al = fa.readFile(file, protocol, format);
+ // configure a window
+ BamFileOptionsChooser bamoptions = new BamFileOptionsChooser(
+ source);
+ // ask the user which bit of the bam they want to load
+ int confirm = JvOptionPane.showConfirmDialog(null, bamoptions,
+ MessageManager.getString("label.bam_file_options"),
+ JvOptionPane.OK_CANCEL_OPTION,
+ JvOptionPane.PLAIN_MESSAGE);
+
+ if (confirm == JvOptionPane.CANCEL_OPTION
+ || confirm == JvOptionPane.CLOSED_OPTION)
+ {
+ Desktop.instance.stopLoading();
+ return;
+ }
+ else
+ {
+ bamoptions.update(source);
+ if (file.indexOf("#") == -1)
+ {
+ file = file + "#" + ((BamFile) source).suffix;
+ }
+ }
}
+ al = fa.readFile(file, protocol, format);
}
if (FileFormat.Jalview.equals(format))
checkURLSource(fileStr);
if (suffixSeparator == '#')
{
- extractSuffix(fileStr); // URL lref is stored for later reference.
+ dataName = extractSuffix(fileStr); // URL lref is stored for later
+ // reference.
}
} catch (IOException e)
{
{
// jar files are special - since they contain all sorts of random
// characters.
- if (source.inFile != null)
+ if (source.inFile != null || source.getDataName() != null)
{
- String fileStr = source.inFile.getName();
+ String fileStr = source.inFile == null ? source.getDataName()
+ : source.inFile.getName();
// possibly a Jalview archive.
if (fileStr.lastIndexOf(".jar") > -1
|| fileStr.lastIndexOf(".zip") > -1)