use of samTextViewer.GenomicCoords in project ASCIIGenome by dariober.
the class TrackWigglesTest method canPrintChromosomeNames.
@Test
public void canPrintChromosomeNames() throws InvalidGenomicCoordsException, IOException, ClassNotFoundException, InvalidRecordException, SQLException {
GenomicCoords gc = new GenomicCoords("chr7:5540000-5570000", 80, null, null);
TrackWiggles tw = new TrackWiggles("test_data/hg18_var_sample.wig.v2.1.30.tdf", gc, 4);
assertTrue(tw.getChromosomeNames().size() > 10);
tw = new TrackWiggles("test_data/test.bedGraph", gc, 4);
assertTrue(tw.getChromosomeNames().size() > 0);
tw = new TrackWiggles("http://hgdownload.cse.ucsc.edu/goldenPath/hg19/encodeDCC/wgEncodeHaibTfbs/wgEncodeHaibTfbsA549Cebpbsc150V0422111RawRep1.bigWig", gc, 4);
assertTrue(tw.getChromosomeNames().size() > 10);
}
use of samTextViewer.GenomicCoords in project ASCIIGenome by dariober.
the class TrackSet method bookmark.
/**
* Handle bookmarks by processing cmd line args.
* @throws InvalidGenomicCoordsException
* @throws SQLException
* @throws InvalidRecordException
* @throws IOException
* @throws ClassNotFoundException
* @throws InvalidCommandLineException
*/
public String bookmark(GenomicCoords gc, List<String> cmdInput) throws ClassNotFoundException, IOException, InvalidRecordException, SQLException, InvalidGenomicCoordsException, InvalidCommandLineException {
String messages = "";
List<String> args = new ArrayList<String>(cmdInput);
// Remove command name
args.remove(0);
// Get all arguments. What is left is the positional argument
boolean delete = Utils.argListContainsFlag(args, "-d");
String name = Utils.getArgForParam(args, "-n", null);
boolean print = Utils.argListContainsFlag(args, "-print");
String file = Utils.getArgForParam(args, ">", null);
GenomicCoords bookmarkRegion = null;
if (args.size() > 0) {
List<String> strRegion = Utils.parseStringCoordsToList(args.get(0));
if (strRegion.get(1) == null) {
strRegion.set(1, "1");
}
if (strRegion.get(2) == null) {
strRegion.set(2, new Integer(Integer.MAX_VALUE).toString());
}
bookmarkRegion = new GenomicCoords(strRegion.get(0) + ":" + strRegion.get(1) + "-" + strRegion.get(2), gc.getUserWindowSize(), gc.getSamSeqDict(), gc.getFastaFile());
} else {
bookmarkRegion = new GenomicCoords(gc.toStringRegion(), gc.getUserWindowSize(), gc.getSamSeqDict(), gc.getFastaFile());
}
if (print) {
for (Track tr : this.getTrackList()) {
if (tr instanceof TrackBookmark) {
List<String> marks = Utils.tabulateList(((TrackBookmark) tr).asList(), -1);
messages = Joiner.on("\n").join(marks);
return messages + "\n";
}
}
return messages;
}
if (file != null) {
for (Track tr : this.getTrackList()) {
if (tr instanceof TrackBookmark) {
((TrackBookmark) tr).save(file, false);
return messages;
}
}
return messages;
}
if (delete) {
for (Track tr : this.getTrackList()) {
if (tr instanceof TrackBookmark) {
((TrackBookmark) tr).removeBookmark(bookmarkRegion);
return messages;
}
}
return messages;
}
if (name == null) {
name = ".";
}
this.addBookmark(bookmarkRegion, name);
return messages;
}
use of samTextViewer.GenomicCoords in project ASCIIGenome by dariober.
the class TrackSet method trimTrack.
private GenomicCoords trimTrack(TrackIntervalFeature tr) throws InvalidGenomicCoordsException, IOException {
GenomicCoords current = tr.getGc();
TrackIntervalFeature itr = (TrackIntervalFeature) tr;
List<IntervalFeature> features = itr.getIntervalFeatureList();
if (features.size() == 0) {
return current;
}
// Get the leftmost and rightmost coordinates of the feature set
// These might extend beyond the current window.
int left = Integer.MAX_VALUE;
int right = 0;
for (IntervalFeature f : features) {
if (f.getFrom() < left) {
left = f.getFrom();
}
if (f.getTo() > right) {
right = f.getTo();
}
}
// See if left and right need to be adjusted by window coordinates
if (left < current.getFrom()) {
left = current.getFrom();
}
if (right > current.getTo()) {
right = current.getTo();
}
return new GenomicCoords(current.getChrom() + ":" + left + "-" + right, current.getUserWindowSize(), current.getSamSeqDict(), current.getFastaFile());
}
use of samTextViewer.GenomicCoords in project ASCIIGenome by dariober.
the class TrackIntervalFeature method genomicCoordsAllChromMatchInGenome.
/**
* Execute findAllChromRegexInGenome() and return the extreme coordinates of the matched features
*/
protected GenomicCoords genomicCoordsAllChromMatchInGenome(Pattern pattern, GenomicCoords currentGc) throws IOException, InvalidGenomicCoordsException {
List<IntervalFeature> matchedFeatures = this.findAllChromMatchInGenome(pattern, currentGc);
if (matchedFeatures.size() == 0) {
return currentGc;
}
// Now get the coords of the first and last feature matched.
String chrom = matchedFeatures.get(0).getChrom();
int startFrom = matchedFeatures.get(0).getFrom();
int endTo = matchedFeatures.get(matchedFeatures.size() - 1).getTo();
GenomicCoords allMatchesGc = new GenomicCoords(Utils.coordinatesToString(chrom, startFrom, endTo), currentGc.getUserWindowSize(), currentGc.getSamSeqDict(), currentGc.getFastaFile());
return allMatchesGc;
}
use of samTextViewer.GenomicCoords in project ASCIIGenome by dariober.
the class TrackIntervalFeature method coordsOfNextFeature.
/**
*Return the coordinates of the next feature so that the start coincide with the start of the feature and
* the end is the start + windowSize.
*/
public GenomicCoords coordsOfNextFeature(GenomicCoords currentGc, boolean getPrevious) throws InvalidGenomicCoordsException, IOException {
IntervalFeature nextFeature;
if (getPrevious) {
nextFeature = this.getPreviousFeature(currentGc.getChrom(), currentGc.getFrom());
} else {
nextFeature = this.getNextFeature(currentGc.getChrom(), currentGc.getTo());
}
if (nextFeature == null) {
return currentGc;
}
GenomicCoords nextGc = new GenomicCoords(Utils.coordinatesToString(nextFeature.getChrom(), nextFeature.getFrom(), nextFeature.getFrom() + currentGc.getGenomicWindowSize() - 1), currentGc.getUserWindowSize(), currentGc.getSamSeqDict(), currentGc.getFastaFile());
return nextGc;
}
Aggregations