/** * Reads geometry and attributes from a shapefile. * * @param fileName The name of the file without extension. A shapefile consists of three separate * files called fileName.shp (the geometry), fileName.dbf (the attributes) and fileName.dbx * (an index file). */ public void readFile(String fileName) { ShapefileReader reader = new ShapefileReader(parent); InputStream geomStream = parent.createInput(fileName + ".shp"); if (geomStream == null) { System.err.println("Cannot open shapefile geometry file: " + fileName + ".shp"); return; } InputStream attribStream = parent.createInput(fileName + ".dbf"); if (attribStream == null) { System.err.println("Cannot open shapefile attribute file: " + fileName + ".dbf"); return; } reader.read(geomStream, attribStream); minGeoX = reader.getMinX(); minGeoY = reader.getMinY(); maxGeoX = reader.getMaxX(); maxGeoY = reader.getMaxY(); features = reader.getFeatures(); attributes = reader.getAttributes(); numPoints += reader.getNumPoints(); numLines += reader.getNumLines(); numPolys += reader.getNumPolys(); for (Feature feature : features.values()) { if (feature.getType() == FeatureType.LINE) { numLineVertices += feature.getNumVertices(); } else if (feature.getType() == FeatureType.POLYGON) { numPolygonVertices += feature.getNumVertices(); numPolygonParts += ((Polygon) feature).getSubPartPointers().size(); } } }
public static void printNeighbors(ArrayList neighbors) { int i = 0; for(Neighbor neighbor : neighbors) { Instance instance = neighbor.getInstance(); System.out.println("\nNeighbor " + (i + 1) + ", distance: " + neighbor.getDistance()); i++; for(Feature f : instance.getAttributes()) { System.out.print(f.getName() + ": "); if(f instanceof Category) { System.out.println(((Category)f).getCategory().toString()); } else if(f instanceof Distance) { System.out.println(((Distance)f).getDistance().toString()); } else if (f instanceof Expiration) { System.out.println(((Expiration)f).getExpiry().toString()); } else if (f instanceof Handset) { System.out.print(((Handset)f).getOs().toString() + ", "); System.out.println(((Handset)f).getDevice().toString()); } else if (f instanceof Offer) { System.out.println(((Offer)f).getOfferType().toString()); } else if (f instanceof WSAction) { System.out.println(((WSAction)f).getAction().toString()); } } } }
/** * Handle UTR joins * * @param feature * @param key * @param qualifiers * @return */ private Location joinUtrs(Feature feature, Key key, QualifierVector qualifiers) { Location location = feature.getLocation(); if (key.getKeyString().equals("5'UTR") || key.getKeyString().equals("3'UTR")) { ChadoCanonicalGene gene = ((GFFStreamFeature) feature).getChadoGene(); String utrName = GeneUtils.getUniqueName(feature); String transcriptName = gene.getTranscriptFromName(utrName); List<Feature> utrs; if (key.getKeyString().equals("5'UTR")) utrs = gene.get5UtrOfTranscript(transcriptName); else utrs = gene.get3UtrOfTranscript(transcriptName); if (utrs.size() > 1) { int start = Integer.MAX_VALUE; RangeVector ranges = new RangeVector(); for (int i = 0; i < utrs.size(); i++) { Feature utr = utrs.get(i); Range range = utr.getLocation().getTotalRange(); if (start > range.getStart()) start = range.getStart(); ranges.add(range); } if (start != feature.getLocation().getTotalRange().getStart()) return null; location = new Location(ranges, feature.getLocation().isComplement()); } int ntranscripts = gene.getTranscripts().size(); if (ntranscripts == 1) transcriptName = gene.getGeneUniqueName(); qualifiers.setQualifier(new Qualifier("locus_tag", transcriptName)); qualifiers.removeQualifierByName("ID"); } return location; }
public Object getValue(String featureID) { Feature feature = findFeature(featureID); if (feature != null) { return feature.getValue(getElement()); } return null; }
public void startScanFeatures(Observation obsr) { currentFeatures.clear(); currentFeatureIdx = 0; // scan over all context predicates for (int i = 0; i < obsr.cps.length; i++) { Element elem = (Element) dict.dict.get(new Integer(obsr.cps[i])); if (elem == null) { continue; } if (!(elem.isScanned)) { // scan all labels for features Iterator it = elem.lbCntFidxes.keySet().iterator(); while (it.hasNext()) { Integer labelInt = (Integer) it.next(); CountFIdx cntFIdx = (CountFIdx) elem.lbCntFidxes.get(labelInt); if (cntFIdx.fidx >= 0) { Feature f = new Feature(); f.FeatureInit(labelInt.intValue(), obsr.cps[i]); f.idx = cntFIdx.fidx; elem.cpFeatures.add(f); } } elem.isScanned = true; } for (int j = 0; j < elem.cpFeatures.size(); j++) { currentFeatures.add(elem.cpFeatures.get(j)); } } }
@Test public void testGetDistinctLabels() { FeatureOccurrence mockedOccurrence1 = new FeatureOccurrence(); FeatureOccurrence mockedOccurrence2 = new FeatureOccurrence(); FeatureOccurrence mockedOccurrence3 = new FeatureOccurrence(); mockedOccurrence1.setOccurrenceName("occurrence1"); mockedOccurrence2.setOccurrenceName("occurrence2"); mockedOccurrence3.setOccurrenceName("firstOccurrence"); Feature feature = new Feature(); feature.setLabel("firstOccurrence"); feature.addFeatureOccurrence(mockedOccurrence1); feature.addFeatureOccurrence(mockedOccurrence2); feature.addFeatureOccurrence(mockedOccurrence3); featureContainer.getFeatureDictionary().put("firstOccurrence", feature); ArrayList<String> expected = new ArrayList<String>(); expected.add("occurrence1"); expected.add("occurrence2"); Assert.assertEquals(expected, featureContainer.getDistinctLabels("firstOccurrence")); }
/** @return the command line for the given {@code action}. */ List<String> getCommandLine(String action, Variables variables) { List<String> commandLine = new ArrayList<>(); for (Feature feature : enabledFeatures) { feature.expandCommandLine(action, variables, commandLine); } return commandLine; }
/* * Create and return a new feature object with the given parameters. */ public Feature createFeature(Site site, String id, String version, String url) { Feature result = new Feature(site); result.setId(id); result.setVersion(version); result.setUrl(url); return result; }
private void saveFeatures() throws IOException, ClassNotFoundException { File file = new File(getExternalFilesDir(null), _exerciseName + ".txt"); if (!file.exists()) { file.createNewFile(); } ObjectOutputStream oostream = new ObjectOutputStream(new FileOutputStream(file)); for (int i = 1; i <= _reps; i++) { File readingFile = new File(_directory, i + ".txt"); FileInputStream fistream = new FileInputStream(readingFile); ObjectInputStream oistream = new ObjectInputStream(fistream); ArrayList<SensorReading> reading = new ArrayList<>(); while (fistream.available() > 0) { // Check if the file stream is at the end reading.add((SensorReading) oistream.readObject()); } // TODO: Get feature object here // Create ExerciseData object from the readings ExerciseData exerciseData = new ExerciseData(reading); Feature feature = new Feature(); Log.d("reading_size", reading.size() + ""); feature._features = exerciseData.getFeatureVector(); feature._time = exerciseData.getTime(); feature._classLabel = Globals._numExercises + 1; oostream.writeObject(feature); } if (Globals._exerciseLabels == null) { Globals._exerciseLabels = new HashMap<>(); } Globals._exerciseLabels.put(_exerciseName, Globals._numExercises + 1); Globals._numExercises++; Globals.saveExerciseLabels(this); Classifier.trainModel(this); }
/** * Get the feature by its unique id. * * @param id The id of the feature. * @return The feature by its id or null if no feature found by given id. */ public Feature getFeatureById(final int id) { for (final Feature feature : mFeatures) { if (feature.getId() == id) { return feature; } } return null; }
private void outputRegions(BufferedWriter writer, Collection<Feature> regions) throws IOException { List<Feature> mergedRegions = RegionLoader.collapseRegions(regions, 0); for (Feature region : mergedRegions) { writer.write(region.getSeqname() + "\t" + region.getStart() + "\t" + region.getEnd() + "\n"); } }
public boolean addValue(String featureID, Object value) { Feature feature = findFeature(featureID); if (feature != null) { cleanCachedValueForFeature(featureID); return feature.addValue(getElement(), value); } return false; }
public static Feature createLineSegmentFeature( FeatureSchema fs, Coordinate p0, Coordinate p1, String msg) { Feature feature = new BasicFeature(fs); LineString lineSeg = fact.createLineString(new Coordinate[] {p0, p1}); feature.setGeometry(lineSeg); feature.setAttribute(MESG_ATTR_NAME, msg); return feature; }
public static void add(Object tag, Geometry geom, String msg) { if (!Debug.isDebugging()) return; FeatureDataset fd = getDebugFeatureDataset(tag); Feature feature = new BasicFeature(fd.getFeatureSchema()); feature.setGeometry(geom); feature.setAttribute(MESG_ATTR_NAME, msg); fd.add(feature); }
private FeatureConfiguration(ImmutableList<Feature> enabledFeatures) { this.enabledFeatures = enabledFeatures; ImmutableSet.Builder<String> builder = ImmutableSet.builder(); for (Feature feature : enabledFeatures) { builder.add(feature.getName()); } this.enabledFeatureNames = builder.build(); }
public static Feature createDefaultFeature(String name, CvTerm featureType, Range range) { Feature feature = new DefaultFeature(name, null, featureType); if (range != null) { feature.getRanges().add(range); } return feature; }
public Feature getFeature(final String feature) { for (Feature f : features) { if (f.getName().equals(feature)) { return f; } } throw new NoSuchObjectException("No such Feature in project[" + feature + "]:" + feature); }
@VisibleForTesting Collection<String> getFeatureNames() { Collection<String> featureNames = new HashSet<>(); for (Feature feature : features) { featureNames.add(feature.getName()); } return featureNames; }
/** * Get the list of features filtered by RTP type. * * @param rtpType The payment request type. * @return The unmodifiable list of features. */ public List<Feature> getFeaturesByRtpType(final RTPType rtpType) { final List<Feature> filteredList = new ArrayList<>(); for (final Feature feature : mFeatures) { if (feature.getPaymentRequest().getRtpType().equals(rtpType)) { filteredList.add(feature); } } return filteredList; }
public static Feature createDefaultFeature( String name, CvTerm featureType, Collection<Range> ranges) { Feature feature = new DefaultFeature(name, null, featureType); if (ranges != null) { feature.getRanges().addAll(ranges); } return feature; }
private String getTypeOfResponseVariable(String responseVariable, List<Feature> features) { String type = null; for (Feature feature : features) { if (feature.getName().equals(responseVariable)) { type = feature.getType(); } } return type; }
public static void main(String[] args) throws Exception { NativeLibraryLoader l = new NativeLibraryLoader(); l.load("/home/lmose/code/abra/target"); NativeAssembler assem = new NativeAssembler(); assem.setTruncateOutputOnRepeat(true); assem.setMaxContigs(5000); assem.setMaxPathsFromRoot(5000); assem.setKmer(new int[] {43}); assem.setReadLength(100); assem.setMinKmerFrequency(2); assem.setMaxAverageDepth(400); assem.setShouldSearchForSv(true); // String bam1 = args[0]; String bam1 = "/home/lmose/dev/abra/sv/test.bam"; List<String> inputFiles = new ArrayList<String>(); inputFiles.add(bam1); // String output = args[2]; String output = "/home/lmose/dev/abra/sv/output.txt"; // chr18:60,793,358-60,793,758 Feature region = new Feature("chr18", 60793358, 60793758); String prefix = "pre"; boolean checkForDupes = true; ReAligner realigner = new ReAligner(); CompareToReference2 c2r = new CompareToReference2(); // c2r.init(args[3]); c2r.init("/home/lmose/reference/chr18/chr18.fa"); List<Feature> regions = new ArrayList<Feature>(); regions.add(region); String contigs = assem.assembleContigs( inputFiles, output, "asm_temp", regions, prefix, checkForDupes, realigner, c2r); System.err.println(contigs); System.err.println("-------------------------"); List<BreakpointCandidate> svCandidates = assem.getSvCandidateRegions(); for (BreakpointCandidate svCandidate : svCandidates) { System.err.println( "SV: " + region.getDescriptor() + "-->" + svCandidate.getRegion().getDescriptor()); } // assem.assembleContigs(args[0], args[1], "contig"); // for (int i=0; i<10; i++) { // run(args[0], args[1] + "_" + i); // } // run(args[0], args[1]); // assem.assembleContigs("/home/lmose/code/abra/src/main/c/1810_reads.txt", // "/home/lmose/code/abra/src/main/c/1810.fa", "bar"); }
/** Method that calculates bit set (flags) of all features that are enabled by default. */ public static int collectDefaults() { int flags = 0; for (Feature f : values()) { if (f.enabledByDefault()) { flags |= f.getMask(); } } return flags; }
public static int config(int features, Feature feature, boolean state) { if (state) { features |= feature.getMask(); } else { features &= ~feature.getMask(); } return features; }
/** * Draws all features that match the given attribute stored in the given column of the attribute * table. If no features are found or the given column is out of bounds, nothing is drawn * * @param attribute Attribute identifying features to draw. * @param col Column in the attribute table (where ID is column 0) to search. */ public void draw(String attribute, int col) { Set<Integer> ids = attributes.match(attribute, col); for (Integer id : ids) { Feature feature = features.get(id); if (feature != null) { feature.draw(this); } } }
@Test public void testAddOccurrence() { Feature feature = new Feature(); FeatureOccurrence newOccurrence = new FeatureOccurrence(); newOccurrence.setContainingSentence("test"); featureContainer.getFeatureDictionary().put("feature1", feature); int expected = feature.getOccurrence() + 1; featureContainer.addOccurrence("feature1", newOccurrence); int actual = feature.getOccurrence(); Assert.assertEquals(expected, actual); }
/* Draws a feature called "SELECTED" when the user highlights DNA */ void paintSelectedFeature(int start, int end) { // first see if a selected feature already exists // if it does, remove it removeSelectedFeature(); // paint the new one Feature f = new Feature(cgview.getFeatureSlots().get(0), "SELECTED"); f.setColor(Color.green); new FeatureRange(f, start, end); repaint(); }
protected <T> boolean hasFeature(Feature<T> feature) { if (features != null) { Object[] aspectFeature = features[feature.getAspectId()]; if (aspectFeature != null) { Object value = aspectFeature[feature.getFeatureId()]; if (value != UNSETTED_VALUE) { return true; } } } return false; }
public <T> boolean isSettedFeature(Feature<T> feature) { if (getFeatureType() != feature.getType()) { throw new RuntimeException( "Try to check a feature of type:" + feature.getType() + " on a SchemaFeature of type:" + getFeatureType()); } if (hasFeature(feature)) return true; if (parent == null) return false; return parent.isSettedFeature(feature); }
public void writeFeatures(PrintWriter fout) throws IOException { // write the number of features fout.println(Integer.toString(features.size())); for (int i = 0; i < features.size(); i++) { Feature f = (Feature) features.get(i); fout.println(f.toString(data.cpInt2Str, data.lbInt2Str)); } // wirte the line ###... fout.println(Option.modelSeparator); }