Skip to content

Commit

Permalink
Merge pull request #4 from MikePone/master
Browse files Browse the repository at this point in the history
  • Loading branch information
dannovikov authored Mar 20, 2024
2 parents 8b3173f + 387b872 commit f4f826a
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 5 deletions.
Binary file modified SeqRuler.jar
Binary file not shown.
15 changes: 15 additions & 0 deletions modules/gui-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
<artifactId>gui-app</artifactId>
<version>0.1</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.hive/hive-common -->
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-common</artifactId>
<version>3.1.3</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.hive/hive-exec -->
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>3.1.3</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
Expand Down
20 changes: 15 additions & 5 deletions modules/gui-app/src/main/java/TN93/TN93.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
//Parallelization
import java.util.concurrent.*;




import static java.lang.Math.log;

public class TN93 extends Observable {
Expand Down Expand Up @@ -53,8 +50,15 @@ public Pair(A first, B second) {
private boolean use_stdout = false;
private boolean input_as_pairs = false;
private boolean enumerate_sequences = false;

enum RESOLVE_METHOD {
RESOLVE,
AVERAGE,
GAPMM,
SKIP
}

public void setEdgeThreshold(float edgeThreshold) {
public void setEdgeThreshold(float edgeThreshold) {
this.edgeThreshold = edgeThreshold;
}

Expand Down Expand Up @@ -591,7 +595,13 @@ private void update_percent_complete(long total_pairs_to_compute, long current_p
notifyObservers(percCompleted);
}

private double tn93(Seq s1, Seq s2) {
/**
* Package visibility to allow the UDF direct access to this method.
* @param s1
* @param s2
* @return
*/
double tn93(Seq s1, Seq s2) {
double[][] nucl_pair_counts = countPairwiseNucl(s1, s2);
double[] nucl_counts = getNuclCounts(nucl_pair_counts);

Expand Down
90 changes: 90 additions & 0 deletions modules/gui-app/src/main/java/TN93/TN93UDF.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package TN93;

import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter.StringConverter;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantHiveDecimalObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantStringObjectInspector;
import org.apache.hadoop.io.DoubleWritable;

public class TN93UDF extends GenericUDF {

private TN93 tn93 = null;
private transient StringConverter stringConverter;

/**
* Arguments are Seq1, Seq1, resolveMode (average, resolve,gapmm,skip), abiguityFraction,
*/
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length != 4) {
throw new UDFArgumentLengthException(
"TN93() requires 4 arguments (Seq1, Seq1, resolveMode (average, resolve, gapmm, skip), abiguityFraction), got "
+ arguments.length);
}
tn93 = new TN93();

for (int i = 0; i < arguments.length; i++) {

if (arguments[i].getCategory() != Category.PRIMITIVE) {
throw new UDFArgumentException("TN93 only takes primitive types, got " +arguments[i].getCategory() + ":" + arguments[i].getTypeName());
}
}
// make sure ambig fraction param is double
PrimitiveObjectInspector ambigArgOI = (PrimitiveObjectInspector) arguments[3];
PrimitiveCategory inputType = ambigArgOI.getPrimitiveCategory();

if (inputType != PrimitiveCategory.DECIMAL) {
throw new UDFArgumentException("TN93 ambig fraction should be a decimal, got " + arguments[3].getTypeName());
}
//initialize TN93 with correct parameters.
WritableConstantHiveDecimalObjectInspector ambigFractionArg = (WritableConstantHiveDecimalObjectInspector) arguments[3];
tn93.setMaxAmbiguityFraction(ambigFractionArg.getWritableConstantValue().doubleValue());
//TN93UDF arg object type : org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantStringObjectInspector
WritableConstantStringObjectInspector resolveArg = (WritableConstantStringObjectInspector) arguments[2];
tn93.setAmbiguityHandling(resolveArg.getWritableConstantValue().toString());

//string converter for sequence string args.
PrimitiveObjectInspector sequenceArgsOI = (PrimitiveObjectInspector) arguments[0];
stringConverter = new PrimitiveObjectInspectorConverter.StringConverter(sequenceArgsOI);

// output object is a double.
ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
return outputOI;
}

@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {

String val1 = null;
String val2 = null;
if (arguments[0] != null && arguments[1] != null) {
val1 = (String) stringConverter.convert(arguments[0].get());
val2 = (String) stringConverter.convert(arguments[1].get());
}
if (val1 == null || val2 == null) {
return null;
}

Seq seq1 = new Seq("1", val1);
Seq seq2 = new Seq("2", val2);

double result = tn93.tn93(seq1,seq2);

return new DoubleWritable(result);
}

@Override
public String getDisplayString(String[] children) {
return "TN93 UDF implementation wrapper for SeqRuler.";
}

}

0 comments on commit f4f826a

Please sign in to comment.