Skip to content

Commit

Permalink
Migrated all bio webservices.
Browse files Browse the repository at this point in the history
  • Loading branch information
PKatGITHUB committed Aug 21, 2019
1 parent 2217a27 commit 7d4bea9
Show file tree
Hide file tree
Showing 24 changed files with 653 additions and 510 deletions.
Expand Up @@ -28,15 +28,15 @@
import org.intermine.util.IntPresentSet;
import org.intermine.web.logic.export.ExportException;
import org.intermine.web.logic.export.Exporter;
import org.intermine.web.logic.export.ExporterSpring;

/**
* Exports LocatedSequenceFeature objects in UCSC BED format.
*
* @author Fengyuan Hu
*/
public class BEDExporter implements Exporter
public class BEDExporter extends ExporterSpring
{
PrintWriter out;
private boolean makeUcscCompatible = true;
private int writtenResultsCount = 0;
private boolean headerPrinted = false;
Expand All @@ -63,21 +63,19 @@ public class BEDExporter implements Exporter

/**
* Constructor.
* @param out output stream
* @param featureIndexes index of column with exported sequence
* @param sourceName name of Mine to put in GFF source column
* @param organismString a comma separated string of organism short names
* @param makeUcscCompatible true if chromosome ids should be prefixed by 'chr'
* @param trackDescription track description in the header
*/
public BEDExporter(PrintWriter out, List<Integer> featureIndexes, String sourceName,
public BEDExporter(List<Integer> featureIndexes, String sourceName,
String organismString, boolean makeUcscCompatible, String trackDescription) {

this.out = out;
this.featureIndexes = featureIndexes;
this.sourceName = sourceName;
this.makeUcscCompatible = makeUcscCompatible;
this.trackDescription = trackDescription;
this.outputString = "";

if ("".equals(trackDescription) || trackDescription == null) {
this.trackName = "track";
Expand Down Expand Up @@ -111,10 +109,8 @@ public void export(Iterator<? extends List<ResultElement>> resultIt,
finishLastRow();

if (writtenResultsCount == 0) {
out.println("Nothing was found for export");
outputString = outputString.concat("Nothing was found for export").concat("\n");
}

out.flush();
} catch (Exception ex) {
throw new ExportException("Export failed", ex);
}
Expand Down Expand Up @@ -217,11 +213,11 @@ private void makeRecord() {
if (bedRecord != null) {
// have a chromosome ref and chromosomeLocation ref
if (!headerPrinted) {
out.println(getHeader());
outputString = outputString.concat(getHeader()).concat("\n");
headerPrinted = true;
}

out.println(bedRecord.toBED());
outputString = outputString.concat(bedRecord.toBED()).concat("\n");
exportedIds.add(lastLsf.getId());
writtenResultsCount++;
}
Expand All @@ -247,11 +243,11 @@ private void finishLastRow() {
if (bedRecord != null) {
// have a chromsome ref and chromosomeLocation ref
if (!headerPrinted) {
out.println(getHeader());
outputString = outputString.concat(getHeader()).concat("\n");
headerPrinted = true;
}

out.println(bedRecord.toBED());
outputString = outputString.concat(bedRecord.toBED()).concat("\n");
writtenResultsCount++;
}
lastLsfId = null;
Expand Down
Expand Up @@ -39,13 +39,14 @@
import org.intermine.util.PropertiesUtil;
import org.intermine.web.logic.export.ExportException;
import org.intermine.web.logic.export.Exporter;
import org.intermine.web.logic.export.ExporterSpring;

/**
* Exports LocatedSequenceFeature objects in GFF3 format.
* @author Kim Rutherford
* @author Jakub Kulaviak
*/
public class GFF3Exporter implements Exporter
public class GFF3Exporter extends ExporterSpring
{
private static final Logger LOG = Logger.getLogger(GFF3Exporter.class);
/**
Expand All @@ -65,7 +66,6 @@ public class GFF3Exporter implements Exporter
public static final String FLY_LINK =
"https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=7227";

PrintWriter out;
private List<Integer> featureIndexes;
private Map<String, String> soClassNames;
private int writtenResultsCount = 0;
Expand All @@ -82,7 +82,6 @@ public class GFF3Exporter implements Exporter

/**
* Constructor.
* @param out output stream
* @param indexes index of column with exported sequence
* @param soClassNames mapping
* @param attributesNames names of attributes that are printed in record,
Expand All @@ -92,16 +91,16 @@ public class GFF3Exporter implements Exporter
* @param organisms taxon id of the organisms
* @param makeUcscCompatible true if chromosome ids should be prefixed by 'chr'
*/
public GFF3Exporter(PrintWriter out, List<Integer> indexes, Map<String, String> soClassNames,
public GFF3Exporter(List<Integer> indexes, Map<String, String> soClassNames,
List<String> attributesNames, String sourceName, Set<String> organisms,
boolean makeUcscCompatible) {
this.out = out;
this.featureIndexes = indexes;
this.soClassNames = soClassNames;
this.attributesNames = attributesNames;
this.sourceName = sourceName;
this.organisms = organisms;
this.makeUcscCompatible = makeUcscCompatible;
this.outputString = "";

for (String s : soClassNames.keySet()) {
this.cNames.add(s.toLowerCase());
Expand All @@ -110,7 +109,6 @@ public GFF3Exporter(PrintWriter out, List<Integer> indexes, Map<String, String>

/**
* Constructor.
* @param out output stream
* @param indexes index of column with exported sequence
* @param soClassNames mapping
* @param attributesNames names of attributes that are printed in record,
Expand All @@ -121,10 +119,9 @@ public GFF3Exporter(PrintWriter out, List<Integer> indexes, Map<String, String>
* @param makeUcscCompatible true if chromosome ids should be prefixed by 'chr'
* @param paths paths
*/
public GFF3Exporter(PrintWriter out, List<Integer> indexes, Map<String, String> soClassNames,
public GFF3Exporter(List<Integer> indexes, Map<String, String> soClassNames,
List<String> attributesNames, String sourceName, Set<String> organisms,
boolean makeUcscCompatible, List<Path> paths) {
this.out = out;
this.featureIndexes = indexes;
this.soClassNames = soClassNames;
this.attributesNames = attributesNames;
Expand Down Expand Up @@ -199,11 +196,9 @@ public void export(Iterator<? extends List<ResultElement>> resultIt,
}

if (writtenResultsCount == 0) {
out.println("Nothing to export. Sequence features might miss some information, "
outputString = outputString.concat("Nothing to export. Sequence features might miss some information, "
+ "e.g. chromosome location, etc.");
}

out.flush();
} catch (Exception ex) {
throw new ExportException("Export failed", ex);
}
Expand Down Expand Up @@ -442,11 +437,11 @@ private void makeRecord() {
if (gff3Record != null) {
// have a chromosome ref and chromosomeLocation ref
if (!headerPrinted) {
out.println(getHeader());
outputString = outputString.concat(getHeader()).concat("\n");
headerPrinted = true;
}

out.println(gff3Record.toGFF3());
outputString = outputString.concat(gff3Record.toGFF3()).concat("\n");
exportedIds.add(lastLsf.getId());
writtenResultsCount++;
}
Expand Down
Expand Up @@ -50,6 +50,7 @@
import org.intermine.util.IntPresentSet;
import org.intermine.web.logic.export.ExportException;
import org.intermine.web.logic.export.Exporter;
import org.intermine.web.logic.export.ExporterSpring;

/**
* Export data in FASTA format. Select cell in each row that can be exported as
Expand All @@ -58,11 +59,10 @@
* @author Kim Rutherford
* @author Jakub Kulaviak
**/
public class SequenceExporter implements Exporter
public class SequenceExporter extends ExporterSpring
{

private ObjectStore os;
private OutputStream out;
private int featureIndex;
private int writtenResultsCount = 0;
private final Map<String, List<FieldDescriptor>> classKeys;
Expand All @@ -79,40 +79,35 @@ public class SequenceExporter implements Exporter
*
* @param os
* object store used for fetching sequence for exported object
* @param outputStream
* output stream
* @param featureIndex
* index of cell in row that contains object to be exported
* @param classKeys for the model
* @param extension extension
*/
public SequenceExporter(ObjectStore os, OutputStream outputStream,
public SequenceExporter(ObjectStore os,
int featureIndex, Map<String, List<FieldDescriptor>> classKeys, int extension) {
this.os = os;
this.out = outputStream;
this.featureIndex = featureIndex;
this.classKeys = classKeys;
this.extension = extension;
this.outputString = "";
}

/**
* Constructor.
*
* @param os
* object store used for fetching sequence for exported object
* @param outputStream
* output stream
* @param featureIndex
* index of cell in row that contains object to be exported
* @param classKeys for the model
* @param extension extension
* @param paths paths to include
*/
public SequenceExporter(ObjectStore os, OutputStream outputStream,
public SequenceExporter(ObjectStore os,
int featureIndex, Map<String, List<FieldDescriptor>> classKeys, int extension,
List<Path> paths) {
this.os = os;
this.out = outputStream;
this.featureIndex = featureIndex;
this.classKeys = classKeys;
this.extension = extension;
Expand Down Expand Up @@ -204,16 +199,17 @@ public void export(Iterator<? extends List<ResultElement>> resultIt,
}
}

FastaWriterHelper.writeSequence(out, bioSequence);
//FastaWriterHelper.writeSequence(out, bioSequence);
outputString = outputString.concat(bioSequence.getSequenceAsString()).concat("\n");

writtenResultsCount++;
exportedIDs.add(objectId);
}

if (writtenResultsCount == 0) {
out.write("Nothing was found for export".getBytes(Charset.forName("UTF-8")));
outputString = outputString.concat("Nothing was found for export");
}

out.flush();
} catch (Exception e) {
throw new ExportException("Export failed.", e);
}
Expand Down
Expand Up @@ -34,6 +34,7 @@
import org.intermine.pathquery.PathQuery;
import org.intermine.metadata.StringUtil;
import org.intermine.web.logic.export.Exporter;
import org.intermine.web.logic.export.ExporterSpring;
import org.intermine.web.logic.export.ResponseUtil;
import org.intermine.webservice.server.Format;
import org.intermine.webservice.server.WebServiceRequestParser;
Expand All @@ -51,12 +52,19 @@
*/
public abstract class AbstractRegionExportService extends GenomicRegionSearchService
{
public String getOutputString() {
return outputString;
}

protected String outputString;

/**
* Constructor.
* @param im The InterMine API settings object.
*/
public AbstractRegionExportService(InterMineAPI im, Format format) {
super(im, format);
this.outputString = "";
}

@Override
Expand Down Expand Up @@ -123,15 +131,15 @@ protected void checkPathQuery(PathQuery pq) throws Exception {
* @param pq pathquery
* @return the exporter
*/
protected abstract Exporter getExporter(PathQuery pq);
protected abstract ExporterSpring getExporter(PathQuery pq);

/**
* Method that carries out the logic for this exporter.
* @param pq The pathquery.
* @param profile A profile to lookup saved bags in.
*/
protected void export(PathQuery pq, Profile profile) {
Exporter exporter = getExporter(pq);
ExporterSpring exporter = getExporter(pq);
ExportResultsIterator iter = null;
try {
PathQueryExecutor executor = this.im.getPathQueryExecutor(profile);
Expand All @@ -147,62 +155,9 @@ protected void export(PathQuery pq, Profile profile) {
iter.releaseGoFaster();
}
}
outputString = exporter.getOutputString();
}

/**
* @return The suffix for the file name.
*/
protected abstract String getSuffix();

/*@Override
protected String getDefaultFileName() {
return "results" + StringUtil.uniqueString() + getSuffix();
}*/

private PrintWriter pw;
private OutputStream os;

/**
* @return printwriter
*/
protected PrintWriter getPrintWriter() {
return pw;
}

/**
* @return outputstream
*/
protected OutputStream getOutputStream() {
return os;
}

/**
* @return content type
*/
protected abstract String getContentType();

/**
* @return formatter
*/
protected Formatter getFormatter() {
return new PlainFormatter();
}

/*@Override
protected Output getDefaultOutput(PrintWriter out, OutputStream outputstream,
String separator) {
this.pw = out;
this.os = outputstream;
output = new StreamedOutput(out, getFormatter(), separator);
if (isUncompressed()) {
ResponseUtil.setCustomTypeHeader(response, getDefaultFileName(), getContentType());
}
return output;
}*/

@Override
public Format getDefaultFormat() {
return Format.UNKNOWN;
}

}

0 comments on commit 7d4bea9

Please sign in to comment.