Search in sources :

Example 1 with IridaSequenceFile

use of ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile in project irida by phac-nml.

the class AnalysisCollectionServiceGalaxy method uploadSequenceFilesPaired.

/**
 * Uploads a list of paired sequence files belonging to the given samples to
 * Galaxy.
 *
 * @param sampleSequenceFilesPaired
 *            A map between {@link Sample} and {@link SequenceFilePair}.
 * @param workflowHistory
 *            The history to upload the sequence files into.
 * @param workflowLibrary
 *            A temporary library to upload files into.
 * @return A CollectionResponse for the dataset collection constructed from
 *         the given files.
 * @throws ExecutionManagerException
 *             If there was an error uploading the files.
 */
public CollectionResponse uploadSequenceFilesPaired(Map<Sample, ? extends IridaSequenceFilePair> sampleSequenceFilesPaired, History workflowHistory, Library workflowLibrary) throws ExecutionManagerException {
    CollectionDescription description = new CollectionDescription();
    description.setCollectionType(DatasetCollectionType.LIST_PAIRED.toString());
    description.setName(COLLECTION_NAME_PAIRED);
    Map<Sample, Path> samplesMapPairForward = new HashMap<>();
    Map<Sample, Path> samplesMapPairReverse = new HashMap<>();
    Set<Path> pathsToUpload = new HashSet<>();
    for (Sample sample : sampleSequenceFilesPaired.keySet()) {
        IridaSequenceFilePair sequenceFilePair = sampleSequenceFilesPaired.get(sample);
        IridaSequenceFile fileForward = sequenceFilePair.getForwardSequenceFile();
        IridaSequenceFile fileReverse = sequenceFilePair.getReverseSequenceFile();
        samplesMapPairForward.put(sample, fileForward.getFile());
        samplesMapPairReverse.put(sample, fileReverse.getFile());
        pathsToUpload.add(fileForward.getFile());
        pathsToUpload.add(fileReverse.getFile());
    }
    // upload files to library and then to a history
    Map<Path, String> pathHistoryDatasetId = galaxyHistoriesService.filesToLibraryToHistory(pathsToUpload, InputFileType.FASTQ_SANGER, workflowHistory, workflowLibrary, DataStorage.LOCAL);
    for (Sample sample : sampleSequenceFilesPaired.keySet()) {
        Path fileForward = samplesMapPairForward.get(sample);
        Path fileReverse = samplesMapPairReverse.get(sample);
        if (!pathHistoryDatasetId.containsKey(fileForward)) {
            throw new UploadException("Error, no corresponding history item found for " + fileForward);
        } else if (!pathHistoryDatasetId.containsKey(fileReverse)) {
            throw new UploadException("Error, no corresponding history item found for " + fileReverse);
        } else {
            String datasetHistoryIdForward = pathHistoryDatasetId.get(fileForward);
            String datasetHistoryIdReverse = pathHistoryDatasetId.get(fileReverse);
            CollectionElement pairedElement = new CollectionElement();
            pairedElement.setName(sample.getSampleName());
            pairedElement.setCollectionType(DatasetCollectionType.PAIRED.toString());
            HistoryDatasetElement datasetElementForward = new HistoryDatasetElement();
            datasetElementForward.setId(datasetHistoryIdForward);
            datasetElementForward.setName(FORWARD_NAME);
            pairedElement.addCollectionElement(datasetElementForward);
            HistoryDatasetElement datasetElementReverse = new HistoryDatasetElement();
            datasetElementReverse.setId(datasetHistoryIdReverse);
            datasetElementReverse.setName(REVERSE_NAME);
            pairedElement.addCollectionElement(datasetElementReverse);
            description.addDatasetElement(pairedElement);
        }
    }
    return galaxyHistoriesService.constructCollection(description, workflowHistory);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) IridaSequenceFilePair(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) UploadException(ca.corefacility.bioinformatics.irida.exceptions.UploadException) CollectionDescription(com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionDescription) HistoryDatasetElement(com.github.jmchilton.blend4j.galaxy.beans.collection.request.HistoryDatasetElement) IridaSequenceFile(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile) CollectionElement(com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionElement) HashSet(java.util.HashSet)

Example 2 with IridaSequenceFile

use of ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile in project irida by phac-nml.

the class SequenceFilePair method getForwardSequenceFile.

/**
 * Gets the forward {@link SequenceFile} from the pair.
 *
 * @return The forward {@link SequenceFile} from the pair.
 */
public SequenceFile getForwardSequenceFile() {
    IridaSequenceFile[] pair = getFiles().toArray(new IridaSequenceFile[getFiles().size()]);
    String[] filenames = { pair[0].getFile().getFileName().toString(), pair[1].getFile().getFileName().toString() };
    int index = StringUtils.indexOfDifference(filenames[0], filenames[1]);
    if (Stream.of(forwardMatches).anyMatch(x -> String.valueOf(filenames[0].charAt(index)).equals(x))) {
        return (SequenceFile) pair[0];
    } else if (Stream.of(forwardMatches).anyMatch(x -> String.valueOf(filenames[1].charAt(index)).equals(x))) {
        return (SequenceFile) pair[1];
    } else {
        throw new NoSuchElementException();
    }
}
Also used : Size(javax.validation.constraints.Size) Date(java.util.Date) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Table(javax.persistence.Table) Lists(com.google.common.collect.Lists) Audited(org.hibernate.envers.Audited) FetchMode(org.hibernate.annotations.FetchMode) EntityListeners(javax.persistence.EntityListeners) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) AuditingEntityListener(org.springframework.data.jpa.domain.support.AuditingEntityListener) NoSuchElementException(java.util.NoSuchElementException) CollectionTable(javax.persistence.CollectionTable) IridaSequenceFilePair(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair) Entity(javax.persistence.Entity) Fetch(org.hibernate.annotations.Fetch) ImmutableSet(com.google.common.collect.ImmutableSet) Iterator(java.util.Iterator) CascadeType(javax.persistence.CascadeType) UniqueConstraint(javax.persistence.UniqueConstraint) JoinColumn(javax.persistence.JoinColumn) IridaSequenceFile(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile) OneToMany(javax.persistence.OneToMany) Set(java.util.Set) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) FetchType(javax.persistence.FetchType) IridaSequenceFile(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile) UniqueConstraint(javax.persistence.UniqueConstraint) NoSuchElementException(java.util.NoSuchElementException) IridaSequenceFile(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile)

Example 3 with IridaSequenceFile

use of ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile in project irida by phac-nml.

the class SequenceFilePair method getReverseSequenceFile.

/**
 * Gets the reverse {@link SequenceFile} from the pair.
 *
 * @return The reverse {@link SequenceFile} from the pair.
 */
public SequenceFile getReverseSequenceFile() {
    IridaSequenceFile[] pair = getFiles().toArray(new IridaSequenceFile[getFiles().size()]);
    String[] filenames = { pair[0].getFile().getFileName().toString(), pair[1].getFile().getFileName().toString() };
    int index = StringUtils.indexOfDifference(filenames[0], filenames[1]);
    if (Stream.of(reverseMatches).anyMatch(x -> String.valueOf(filenames[0].charAt(index)).equals(x))) {
        return (SequenceFile) pair[0];
    } else if (Stream.of(reverseMatches).anyMatch(x -> String.valueOf(filenames[1].charAt(index)).equals(x))) {
        return (SequenceFile) pair[1];
    } else {
        throw new NoSuchElementException();
    }
}
Also used : Size(javax.validation.constraints.Size) Date(java.util.Date) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Table(javax.persistence.Table) Lists(com.google.common.collect.Lists) Audited(org.hibernate.envers.Audited) FetchMode(org.hibernate.annotations.FetchMode) EntityListeners(javax.persistence.EntityListeners) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) AuditingEntityListener(org.springframework.data.jpa.domain.support.AuditingEntityListener) NoSuchElementException(java.util.NoSuchElementException) CollectionTable(javax.persistence.CollectionTable) IridaSequenceFilePair(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair) Entity(javax.persistence.Entity) Fetch(org.hibernate.annotations.Fetch) ImmutableSet(com.google.common.collect.ImmutableSet) Iterator(java.util.Iterator) CascadeType(javax.persistence.CascadeType) UniqueConstraint(javax.persistence.UniqueConstraint) JoinColumn(javax.persistence.JoinColumn) IridaSequenceFile(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile) OneToMany(javax.persistence.OneToMany) Set(java.util.Set) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) FetchType(javax.persistence.FetchType) IridaSequenceFile(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile) UniqueConstraint(javax.persistence.UniqueConstraint) NoSuchElementException(java.util.NoSuchElementException) IridaSequenceFile(ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile)

Aggregations

IridaSequenceFile (ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFile)3 IridaSequenceFilePair (ca.corefacility.bioinformatics.irida.model.irida.IridaSequenceFilePair)3 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Lists (com.google.common.collect.Lists)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Iterator (java.util.Iterator)2 List (java.util.List)2 NoSuchElementException (java.util.NoSuchElementException)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Stream (java.util.stream.Stream)2 CascadeType (javax.persistence.CascadeType)2 CollectionTable (javax.persistence.CollectionTable)2 Entity (javax.persistence.Entity)2 EntityListeners (javax.persistence.EntityListeners)2 FetchType (javax.persistence.FetchType)2 JoinColumn (javax.persistence.JoinColumn)2 OneToMany (javax.persistence.OneToMany)2