use of org.apache.commons.collections4.BidiMap in project sling by apache.
the class ResourceResolverFactoryActivator method activate.
// ---------- SCR Integration ---------------------------------------------
/**
* Activates this component (called by SCR before)
*/
@Activate
protected void activate(final BundleContext bundleContext, final ResourceResolverFactoryConfig config) {
this.bundleContext = bundleContext;
this.config = config;
final BidiMap virtuals = new TreeBidiMap();
for (int i = 0; config.resource_resolver_virtual() != null && i < config.resource_resolver_virtual().length; i++) {
final String[] parts = Mapping.split(config.resource_resolver_virtual()[i]);
virtuals.put(parts[0], parts[2]);
}
virtualURLMap = virtuals;
final List<Mapping> maps = new ArrayList<>();
for (int i = 0; config.resource_resolver_mapping() != null && i < config.resource_resolver_mapping().length; i++) {
maps.add(new Mapping(config.resource_resolver_mapping()[i]));
}
final Mapping[] tmp = maps.toArray(new Mapping[maps.size()]);
// check whether direct mappings are allowed
if (config.resource_resolver_allowDirect()) {
final Mapping[] tmp2 = new Mapping[tmp.length + 1];
tmp2[0] = Mapping.DIRECT;
System.arraycopy(tmp, 0, tmp2, 1, tmp.length);
mappings = tmp2;
} else {
mappings = tmp;
}
// from configuration if available
searchPath = config.resource_resolver_searchpath();
if (searchPath != null && searchPath.length > 0) {
for (int i = 0; i < searchPath.length; i++) {
// ensure leading slash
if (!searchPath[i].startsWith("/")) {
searchPath[i] = "/" + searchPath[i];
}
// ensure trailing slash
if (!searchPath[i].endsWith("/")) {
searchPath[i] += "/";
}
}
}
if (searchPath == null) {
searchPath = new String[] { "/" };
}
// the root of the resolver mappings
mapRoot = config.resource_resolver_map_location();
mapRootPrefix = mapRoot + '/';
final String[] paths = config.resource_resolver_map_observation();
this.observationPaths = new Path[paths.length];
for (int i = 0; i < paths.length; i++) {
this.observationPaths[i] = new Path(paths[i]);
}
// vanity path white list
this.vanityPathWhiteList = null;
String[] vanityPathPrefixes = config.resource_resolver_vanitypath_whitelist();
if (vanityPathPrefixes != null) {
final List<String> prefixList = new ArrayList<>();
for (final String value : vanityPathPrefixes) {
if (value.trim().length() > 0) {
if (value.trim().endsWith("/")) {
prefixList.add(value.trim());
} else {
prefixList.add(value.trim() + "/");
}
}
}
if (prefixList.size() > 0) {
this.vanityPathWhiteList = prefixList.toArray(new String[prefixList.size()]);
}
}
// vanity path black list
this.vanityPathBlackList = null;
vanityPathPrefixes = config.resource_resolver_vanitypath_blacklist();
if (vanityPathPrefixes != null) {
final List<String> prefixList = new ArrayList<>();
for (final String value : vanityPathPrefixes) {
if (value.trim().length() > 0) {
if (value.trim().endsWith("/")) {
prefixList.add(value.trim());
} else {
prefixList.add(value.trim() + "/");
}
}
}
if (prefixList.size() > 0) {
this.vanityPathBlackList = prefixList.toArray(new String[prefixList.size()]);
}
}
// check for required property
Set<String> requiredResourceProvidersLegacy = getStringSet(config.resource_resolver_required_providers());
Set<String> requiredResourceProviderNames = getStringSet(config.resource_resolver_required_providernames());
boolean hasLegacyRequiredProvider = false;
if (requiredResourceProvidersLegacy != null) {
hasLegacyRequiredProvider = requiredResourceProvidersLegacy.remove(ResourceResolverFactoryConfig.LEGACY_REQUIRED_PROVIDER_PID);
if (!requiredResourceProvidersLegacy.isEmpty()) {
logger.error("ResourceResolverFactory is using deprecated required providers configuration (resource.resolver.required.providers" + "). Please change to use the property resource.resolver.required.providernames for values: " + requiredResourceProvidersLegacy);
} else {
requiredResourceProvidersLegacy = null;
}
}
if (hasLegacyRequiredProvider) {
final boolean hasRequiredProvider;
if (requiredResourceProviderNames != null) {
hasRequiredProvider = !requiredResourceProviderNames.add(ResourceResolverFactoryConfig.REQUIRED_PROVIDER_NAME);
} else {
hasRequiredProvider = false;
requiredResourceProviderNames = Collections.singleton(ResourceResolverFactoryConfig.REQUIRED_PROVIDER_NAME);
}
if (hasRequiredProvider) {
logger.warn("ResourceResolverFactory is using deprecated required providers configuration (resource.resolver.required.providers" + ") with value '" + ResourceResolverFactoryConfig.LEGACY_REQUIRED_PROVIDER_PID + ". Please remove this configuration property. " + ResourceResolverFactoryConfig.REQUIRED_PROVIDER_NAME + " is already contained in the property resource.resolver.required.providernames.");
} else {
logger.warn("ResourceResolverFactory is using deprecated required providers configuration (resource.resolver.required.providers" + ") with value '" + ResourceResolverFactoryConfig.LEGACY_REQUIRED_PROVIDER_PID + ". Please remove this configuration property and add " + ResourceResolverFactoryConfig.REQUIRED_PROVIDER_NAME + " to the property resource.resolver.required.providernames.");
}
}
// for testing: if we run unit test, both trackers are set from the outside
if (this.resourceProviderTracker == null) {
this.resourceProviderTracker = new ResourceProviderTracker();
this.changeListenerWhiteboard = new ResourceChangeListenerWhiteboard();
this.preconds.activate(this.bundleContext, requiredResourceProvidersLegacy, requiredResourceProviderNames, resourceProviderTracker);
this.changeListenerWhiteboard.activate(this.bundleContext, this.resourceProviderTracker, searchPath);
this.resourceProviderTracker.activate(this.bundleContext, this.eventAdmin, new ChangeListener() {
@Override
public void providerAdded() {
if (factoryRegistration == null) {
checkFactoryPreconditions(null, null);
}
}
@Override
public void providerRemoved(final String name, final String pid, final boolean stateful, final boolean isUsed) {
if (factoryRegistration != null) {
if (isUsed && (stateful || config.resource_resolver_providerhandling_paranoid())) {
unregisterFactory();
}
checkFactoryPreconditions(name, pid);
}
}
});
} else {
this.preconds.activate(this.bundleContext, requiredResourceProvidersLegacy, requiredResourceProviderNames, resourceProviderTracker);
this.checkFactoryPreconditions(null, null);
}
}
use of org.apache.commons.collections4.BidiMap in project polyGembler by c-zhou.
the class Traceable method main.
public static void main(String[] args) {
final BidiMap<String, Integer> bidi = new TreeBidiMap<String, Integer>();
bidi.put("a", 1);
bidi.put("a", 2);
bidi.put("b", 2);
System.out.println(bidi.size());
final DirectedWeightedPseudograph<TraceableVertex<String>, DefaultWeightedEdge> razor = new DirectedWeightedPseudograph<TraceableVertex<String>, DefaultWeightedEdge>(DefaultWeightedEdge.class);
// JGraphModelAdapter<TraceableVertex<String>, DefaultWeightedEdge> jgAdapter =
// new JGraphModelAdapter<TraceableVertex<String>, DefaultWeightedEdge>(razor);
// JGraph jgraph = new JGraph(jgAdapter);
TraceableVertex<String> a = new TraceableVertex<String>("a");
TraceableVertex<String> b = new TraceableVertex<String>("b");
TraceableVertex<String> c = new TraceableVertex<String>("c");
TraceableVertex<String> d = new TraceableVertex<String>("d");
razor.addVertex(a);
razor.addVertex(b);
razor.addVertex(c);
razor.addVertex(d);
razor.setEdgeWeight(razor.addEdge(a, a), 1);
razor.setEdgeWeight(razor.addEdge(a, b), 1);
razor.setEdgeWeight(razor.addEdge(a, c), 1);
razor.setEdgeWeight(razor.addEdge(a, d), 1);
razor.setEdgeWeight(razor.addEdge(b, a), 1);
razor.setEdgeWeight(razor.addEdge(b, b), 1);
razor.setEdgeWeight(razor.addEdge(b, c), 1);
razor.setEdgeWeight(razor.addEdge(b, d), 1);
razor.setEdgeWeight(razor.addEdge(c, a), 1);
razor.setEdgeWeight(razor.addEdge(c, b), 1);
razor.setEdgeWeight(razor.addEdge(c, c), 1);
razor.setEdgeWeight(razor.addEdge(c, d), 1);
razor.setEdgeWeight(razor.addEdge(d, a), 1);
razor.setEdgeWeight(razor.addEdge(d, b), 1);
razor.setEdgeWeight(razor.addEdge(d, c), 1);
razor.setEdgeWeight(razor.addEdge(d, d), 1);
// JFrame frame = new JFrame();
// frame.getContentPane().add(jgraph);
// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// frame.pack();
// frame.setVisible(true);
Set<TraceableVertex<String>> visited = new HashSet<TraceableVertex<String>>();
Deque<TraceableVertex<String>> queue = new ArrayDeque<TraceableVertex<String>>();
queue.push(a);
visited.add(a);
a.setScore(10);
Set<DefaultWeightedEdge> out_edges;
double max_score = Double.NEGATIVE_INFINITY, source_score, target_score, score;
int source_ln;
TraceableVertex<String> max_vertex = null;
boolean isLeaf;
TraceableVertex<String> source_vertex, target_vertex;
double edge_weight;
while (!queue.isEmpty()) {
source_vertex = queue.pop();
source_ln = 10;
source_score = source_vertex.getScore() - source_ln;
isLeaf = true;
out_edges = razor.outgoingEdgesOf(source_vertex);
for (DefaultWeightedEdge out : out_edges) {
target_vertex = razor.getEdgeTarget(out);
target_score = target_vertex.getScore();
edge_weight = razor.getEdgeWeight(out);
score = source_score + edge_weight;
if (visited.contains(target_vertex) && (score <= target_score || isLoopback(razor, source_vertex, target_vertex)))
continue;
isLeaf = false;
target_vertex.setBackTrace(source_vertex);
target_vertex.setScore(score);
queue.push(target_vertex);
visited.add(target_vertex);
}
if (isLeaf && source_vertex.getScore() > max_score) {
max_score = source_vertex.getScore();
max_vertex = source_vertex;
}
}
}
use of org.apache.commons.collections4.BidiMap in project polyGembler by c-zhou.
the class RenjinLOD method run.
@Override
public void run() {
// TODO Auto-generated method stub
final BidiMap<Integer, String> scaffs = new TreeBidiMap<Integer, String>();
final List<Double> boundary_lg = new ArrayList<Double>();
try {
BufferedReader br = Utils.getBufferedReader(txt_in);
String line = br.readLine();
String[] s;
while (line != null) {
if (line.startsWith("$order")) {
int i = 0;
while ((line = br.readLine()) != null && line.length() > 0) {
s = line.split("\\s+")[1].split("-");
for (String scf : s) scaffs.put(i++, scf.replaceAll("^scaffold", ""));
boundary_lg.add((double) i);
}
break;
}
line = br.readLine();
}
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int n = scaffs.size();
double[][] recomfJ = new double[n][n];
double[][] lodscrJ = new double[n][n];
final double constr = Math.log10(.5);
try {
String line;
String[] s;
Integer scf_i1, scf_i2;
double f, l, NR, R;
for (String in : ds_in) {
BufferedReader br = Utils.getBufferedReader(in);
while ((line = br.readLine()) != null) {
s = line.split("\\s+");
scf_i1 = scaffs.getKey(s[6]);
scf_i2 = scaffs.getKey(s[7]);
if (scf_i1 == null || scf_i2 == null)
continue;
f = Double.parseDouble(s[1]);
recomfJ[scf_i1][scf_i2] = f;
recomfJ[scf_i2][scf_i1] = f;
if (f == 0) {
l = 100.0;
} else {
NR = (1 - f);
R = f;
l = Math.min(100.0, n_hap * (Math.log10(NR) * NR + Math.log10(R) * R - constr));
}
lodscrJ[scf_i1][scf_i2] = l;
lodscrJ[scf_i2][scf_i1] = l;
}
br.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DoubleMatrixBuilder reccoo = new DoubleMatrixBuilder(n * (n - 1), 5);
int w = 0;
for (int i = 1; i < n; i++) {
for (int j = 0; j < i; j++) {
reccoo.set(w, 0, j);
reccoo.set(w, 1, i);
reccoo.set(w, 2, j + 1);
reccoo.set(w, 3, i + 1);
reccoo.set(w, 4, lodscrJ[i][j]);
w++;
reccoo.set(w, 0, i);
reccoo.set(w, 1, j);
reccoo.set(w, 2, i + 1);
reccoo.set(w, 3, j + 1);
reccoo.set(w, 4, recomfJ[i][j]);
w++;
}
}
DoubleMatrixBuilder recomf = new DoubleMatrixBuilder(n, n);
DoubleMatrixBuilder lodscr = new DoubleMatrixBuilder(n, n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
recomf.set(i, j, recomfJ[i][j]);
lodscr.set(i, j, lodscrJ[i][j]);
}
}
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("Renjin");
if (engine == null) {
throw new RuntimeException("Renjin not found!!!");
}
StringVector scf = new StringArrayVector(scaffs.values());
recomf.setRowNames(scf);
recomf.setColNames(scf);
lodscr.setRowNames(scf);
lodscr.setColNames(scf);
try {
Context context = Context.newTopLevelContext();
FileOutputStream fos = new FileOutputStream(r_out);
GZIPOutputStream zos = new GZIPOutputStream(fos);
RDataWriter writer = new RDataWriter(context, zos);
ListVector.NamedBuilder dat = new ListVector.NamedBuilder();
dat.add("scaffs", scf);
dat.add("boundary_lg", new DoubleArrayVector(boundary_lg));
dat.add("recomf", recomf.build());
dat.add("lodscr", lodscr.build());
dat.add("reccoo", reccoo.build());
writer.save(dat.build());
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.apache.commons.collections4.BidiMap in project polyGembler by c-zhou.
the class RenjinLOD method run2.
public void run2() {
// TODO Auto-generated method stub
final BidiMap<Integer, String> scaffs = new TreeBidiMap<Integer, String>();
final List<Double> boundary_lg = new ArrayList<Double>();
try {
BufferedReader br = Utils.getBufferedReader(txt_in);
String line = br.readLine();
String[] s;
while (line != null) {
if (line.startsWith("$order")) {
int i = 0;
while ((line = br.readLine()) != null && line.length() > 0) {
s = line.split("\\s+")[1].split("-");
for (String scf : s) scaffs.put(i++, scf.replaceAll("^scaffold", ""));
boundary_lg.add((double) i);
}
break;
}
line = br.readLine();
}
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
double[][] recomf = new double[scaffs.size()][scaffs.size()];
double[][] lodscr = new double[scaffs.size()][scaffs.size()];
final double constr = Math.log10(.5);
try {
String line;
String[] s;
Integer scf_i1, scf_i2;
double f, l, NR, R;
for (String in : ds_in) {
BufferedReader br = Utils.getBufferedReader(in);
while ((line = br.readLine()) != null) {
s = line.split("\\s+");
scf_i1 = scaffs.getKey(s[6]);
scf_i2 = scaffs.getKey(s[7]);
if (scf_i1 == null || scf_i2 == null)
continue;
f = Double.parseDouble(s[1]);
recomf[scf_i1][scf_i2] = f;
recomf[scf_i2][scf_i1] = f;
if (f == 0) {
l = 100.0;
} else {
NR = (1 - f);
R = f;
l = Math.min(100.0, n_hap * (Math.log10(NR) * NR + Math.log10(R) * R - constr));
}
lodscr[scf_i1][scf_i2] = l;
lodscr[scf_i2][scf_i1] = l;
}
br.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
StringVector scf = new StringArrayVector(scaffs.values());
}
use of org.apache.commons.collections4.BidiMap in project polyGembler by c-zhou.
the class DataRetrievor method main.
public static void main(String[] args) {
String in_vcf = "C:\\Users\\chenxi.zhou\\Desktop\\new_alg\\____2.vcf";
String ncsu_sample = "C:\\Users\\chenxi.zhou\\Desktop\\new_alg\\ncsu_samples.txt";
String out_txt = "C:\\Users\\chenxi.zhou\\Desktop\\new_alg\\gbs_nsp306_02.txt";
String[] parent_sample = new String[] { "440132", "440166" };
int M = 10;
BidiMap<String, Integer> target_sample = new TreeBidiMap<String, Integer>();
target_sample.put(parent_sample[0], 0);
target_sample.put(parent_sample[1], 1);
int idx = 2;
String line;
try {
BufferedReader br_s = Utils.getBufferedReader(ncsu_sample);
while ((line = br_s.readLine()) != null) {
if (!target_sample.containsKey(line))
target_sample.put(line, idx++);
}
br_s.close();
// C:\\Users\\chenxi.zhou\\Desktop\\new_alg\\gbs_nsp306_01.txt
// int[] retrieve_line = new int[]{
// 134, 160, 184, 186, 189, 191, 192, 201, 214, 215,
// 217, 219, 221, 222, 227, 229, 230, 233, 256, 273
// };
int[] retrieve_line = new int[] { 160, 200, 213, 215, 216, 227, 229, 304, 348, 462 };
int N = target_sample.size();
BufferedReader br_v = Utils.getBufferedReader(in_vcf);
int skip = 0;
final Map<Integer, Integer> sample_index = new HashMap<Integer, Integer>();
String[] s;
while ((line = br_v.readLine()) != null) {
skip++;
if (line.startsWith("#") && !line.startsWith("##")) {
s = line.split("\\s+");
for (int i = 0; i != s.length; i++) if (target_sample.containsKey(s[i]))
sample_index.put(target_sample.get(s[i]), i);
break;
}
}
BufferedWriter bw_txt = Utils.getBufferedWriter(out_txt);
bw_txt.write(N + "\n");
bw_txt.write(M + "\n");
bw_txt.write(parent_sample[0]);
for (int i = 1; i != N; i++) bw_txt.write("\t" + target_sample.getKey(i));
bw_txt.write("\n");
bw_txt.write(parent_sample[0] + "\t" + parent_sample[0] + "\n");
bw_txt.write("M1");
for (int i = 1; i != M; i++) bw_txt.write("\tM" + (i + 1));
bw_txt.write("\n");
for (int i = 0; i != M; i++) {
if (i == 0)
skip = retrieve_line[0] - skip - 1;
else
skip = retrieve_line[i] - retrieve_line[i - 1] - 1;
for (int j = 0; j != skip; j++) br_v.readLine();
line = br_v.readLine();
s = line.split("\\s+");
bw_txt.write("M" + (i + 1) + "\t" + s[1] + "\tA");
int m = s[3].split(";").length;
for (int j = 1; j != m; j++) bw_txt.write("," + (char) ('A' + j));
for (int j = 0; j != N; j++) {
idx = sample_index.get(j);
if (s[idx].equals(".")) {
bw_txt.write("\t0");
for (int k = 1; k != m; k++) bw_txt.write(",0");
} else
bw_txt.write("\t" + s[idx].replaceAll(";", ","));
}
bw_txt.write("\n");
}
br_v.close();
bw_txt.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations