use of cern.colt.list.ObjectArrayList in project Gemma by PavlidisLab.
the class LinkAnalysisServiceImpl method writeLinks.
/**
* Write links as text.
*/
private void writeLinks(final LinkAnalysis la, FilterConfig filterConfig, Writer wr) throws IOException {
Map<CompositeSequence, Set<Gene>> probeToGeneMap = la.getProbeToGeneMap();
ObjectArrayList links = la.getKeep();
double subsetSize = la.getConfig().getSubsetSize();
List<String> buf = new ArrayList<>();
if (la.getConfig().isSubset() && links.size() > subsetSize) {
la.getConfig().setSubsetUsed(true);
}
wr.write(la.getConfig().toString());
wr.write(filterConfig.toString());
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(4);
Integer probeDegreeThreshold = la.getConfig().getProbeDegreeThreshold();
int i = 0;
int keptLinksCount = 0;
Random generator = new Random();
double rand;
double fraction = subsetSize / links.size();
int skippedDueToDegree = 0;
for (int n = links.size(); i < n; i++) {
Object val = links.getQuick(i);
if (val == null)
continue;
Link m = (Link) val;
Double w = m.getWeight();
int x = m.getx();
int y = m.gety();
if (probeDegreeThreshold > 0 && (la.getProbeDegree(x) > probeDegreeThreshold || la.getProbeDegree(y) > probeDegreeThreshold)) {
skippedDueToDegree++;
continue;
}
CompositeSequence p1 = la.getProbe(x);
CompositeSequence p2 = la.getProbe(y);
Set<Gene> g1 = probeToGeneMap.get(p1);
Set<Gene> g2 = probeToGeneMap.get(p2);
List<String> genes1 = new ArrayList<>();
for (Gene cluster : g1) {
String t = cluster.getOfficialSymbol();
genes1.add(t);
}
List<String> genes2 = new ArrayList<>();
for (Gene cluster : g2) {
String t = cluster.getOfficialSymbol();
genes2.add(t);
}
if (genes2.size() == 0 || genes1.size() == 0) {
continue;
}
String gene1String = StringUtils.join(genes1.iterator(), "|");
String gene2String = StringUtils.join(genes2.iterator(), "|");
if (gene1String.equals(gene2String)) {
continue;
}
if (++keptLinksCount % 50000 == 0) {
LinkAnalysisServiceImpl.log.info(keptLinksCount + " links retained");
}
if (la.getConfig().isSubsetUsed()) {
rand = generator.nextDouble();
if (rand > fraction)
continue;
}
buf.add(p1.getId() + "\t" + p2.getId() + "\t" + gene1String + "\t" + gene2String + "\t" + nf.format(w) + // save links
"\n");
// wr.write( p1.getId() + "\t" + p2.getId() + "\t" + gene1String + "\t" + gene2String + "\t" + nf.format( w
// ) + "\n" );
}
wr.write("# totalLinks:" + keptLinksCount + "\n");
wr.write("# printedLinks:" + buf.size() + "\n");
wr.write("# skippedDueToHighNodeDegree:" + skippedDueToDegree + "\n");
for (String line : buf) {
// write links to file
wr.write(line);
}
if (la.getConfig().isSubsetUsed()) {
// subset option activated
LinkAnalysisServiceImpl.log.info("Done, " + keptLinksCount + "/" + links.size() + " links kept, " + buf.size() + " links printed");
// wr.write("# Amount of links before subsetting/after subsetting: " + links.size() + "/" + numPrinted +
// "\n" );
} else {
LinkAnalysisServiceImpl.log.info("Done, " + keptLinksCount + "/" + links.size() + " links printed (some may have been filtered)");
}
wr.flush();
}
use of cern.colt.list.ObjectArrayList in project Gemma by PavlidisLab.
the class LinkAnalysisPersisterImpl method saveLinksToDb.
@Override
public void saveLinksToDb(LinkAnalysis la) {
if (!la.getConfig().isUseDb()) {
throw new IllegalArgumentException("Analysis is not configured to use the db to persist");
}
this.deleteAnalyses(la.getExpressionExperiment());
// the analysis object will get updated.
CoexpressionAnalysis analysisObj = la.getAnalysisObj();
analysisObj.setCoexpCorrelationDistribution(la.getCorrelationDistribution());
analysisObj = (CoexpressionAnalysis) persisterHelper.persist(analysisObj);
/*
* At this point we have the populated analysis object, but no links.
*/
la.setAnalysisObj(analysisObj);
StopWatch watch = new StopWatch();
watch.start();
ObjectArrayList links = la.getKeep();
int numSaved = this.saveLinks(la, links);
LinkAnalysisPersisterImpl.log.info("Seconds to process " + numSaved + " links (plus flipped versions):" + watch.getTime() / 1000.0);
watch.stop();
}
use of cern.colt.list.ObjectArrayList in project tdq-studio-se by Talend.
the class AbstractLongObjectMap method values.
/**
* Returns a list filled with all values contained in the receiver.
* The returned list has a size that equals <tt>this.size()</tt>.
* Iteration order is guaranteed to be <i>identical</i> to the order used by method {@link #forEachKey(LongProcedure)}.
* <p>
* This method can be used to iterate over the values of the receiver.
*
* @return the values.
*/
public ObjectArrayList values() {
ObjectArrayList list = new ObjectArrayList(size());
values(list);
return list;
}
use of cern.colt.list.ObjectArrayList in project tdq-studio-se by Talend.
the class OpenLongObjectHashMap method clear.
/**
* Removes all (key,value) associations from the receiver.
* Implicitly calls <tt>trimToSize()</tt>.
*/
public void clear() {
new ByteArrayList(this.state).fillFromToWith(0, this.state.length - 1, FREE);
// delta
new ObjectArrayList(values).fillFromToWith(0, state.length - 1, null);
this.distinct = 0;
// delta
this.freeEntries = table.length;
trimToSize();
}
use of cern.colt.list.ObjectArrayList in project tdq-studio-se by Talend.
the class OpenIntObjectHashMap method clear.
/**
* Removes all (key,value) associations from the receiver.
* Implicitly calls <tt>trimToSize()</tt>.
*/
public void clear() {
new ByteArrayList(this.state).fillFromToWith(0, this.state.length - 1, FREE);
// delta
new ObjectArrayList(values).fillFromToWith(0, state.length - 1, null);
this.distinct = 0;
// delta
this.freeEntries = table.length;
trimToSize();
}
Aggregations