Search in sources :

Example 1 with SequenceDAO

use of org.jbei.ice.storage.hibernate.dao.SequenceDAO in project ice by JBEI.

the class BulkUploadController method setFileData.

protected PartData setFileData(String userId, Entry entry, PartData partData) {
    SequenceDAO sequenceDAO = DAOFactory.getSequenceDAO();
    if (sequenceDAO.hasSequence(entry.getId())) {
        partData.setHasSequence(true);
        String name = sequenceDAO.getSequenceFilename(entry);
        partData.setSequenceFileName(name);
    }
    // check attachment
    if (attachmentController.hasAttachment(entry)) {
        partData.setHasAttachment(true);
        partData.setAttachments(attachmentController.getByEntry(userId, entry.getId()));
    }
    return partData;
}
Also used : SequenceDAO(org.jbei.ice.storage.hibernate.dao.SequenceDAO)

Example 2 with SequenceDAO

use of org.jbei.ice.storage.hibernate.dao.SequenceDAO in project ice by JBEI.

the class AnnotationsTest method testCurate.

@Test
public void testCurate() throws Exception {
    Account account = AccountCreator.createTestAccount("AnnotationsTest.testCurate", true);
    Plasmid plasmid = TestEntryCreator.createTestPlasmid(account);
    SequenceDAO sequenceDAO = new SequenceDAO();
    Assert.assertFalse(sequenceDAO.hasSequence(plasmid.getId()));
    DNASequence dnaSequence = GeneralParser.getInstance().parse(sequenceString);
    Sequence sequence = SequenceController.dnaSequenceToSequence(dnaSequence);
    sequence.setEntry(plasmid);
    sequence = sequenceDAO.saveSequence(sequence);
    Assert.assertNotNull(sequence);
    SequenceFeatureDAO sequenceFeatureDAO = new SequenceFeatureDAO();
    List<SequenceFeature> sequenceFeatures = sequenceFeatureDAO.getEntrySequenceFeatures(plasmid);
    Assert.assertEquals(1, sequenceFeatures.size());
    Feature feature = sequenceFeatures.get(0).getFeature();
    DNAFeature dnaFeature = feature.toDataTransferObject();
    Curation curation = new Curation();
    curation.setExclude(true);
    dnaFeature.setCuration(curation);
    List<DNAFeature> features = new ArrayList<>();
    features.add(dnaFeature);
    Annotations annotations = new Annotations(account.getEmail());
    annotations.curate(features);
    sequenceFeatures = sequenceFeatureDAO.getEntrySequenceFeatures(plasmid);
    feature = sequenceFeatures.get(0).getFeature();
    Assert.assertTrue(feature.getCuration().isExclude());
}
Also used : Curation(org.jbei.ice.lib.dto.Curation) ArrayList(java.util.ArrayList) DNASequence(org.jbei.ice.lib.dto.DNASequence) DNAFeature(org.jbei.ice.lib.dto.DNAFeature) SequenceFeatureDAO(org.jbei.ice.storage.hibernate.dao.SequenceFeatureDAO) DNASequence(org.jbei.ice.lib.dto.DNASequence) SequenceDAO(org.jbei.ice.storage.hibernate.dao.SequenceDAO) DNAFeature(org.jbei.ice.lib.dto.DNAFeature) Test(org.junit.Test)

Example 3 with SequenceDAO

use of org.jbei.ice.storage.hibernate.dao.SequenceDAO in project ice by JBEI.

the class ModelToInfoFactory method createTableViewData.

public static PartData createTableViewData(String userId, Entry entry, boolean includeOwnerInfo) {
    if (entry == null)
        return null;
    EntryType type = EntryType.nameToType(entry.getRecordType());
    PartData view = new PartData(type);
    view.setId(entry.getId());
    view.setRecordId(entry.getRecordId());
    view.setPartId(entry.getPartNumber());
    view.setName(entry.getName());
    view.setShortDescription(entry.getShortDescription());
    view.setCreationTime(entry.getCreationTime().getTime());
    view.setStatus(entry.getStatus());
    view.setAlias(entry.getAlias());
    //        view.setOwnerEmail(entry.getOwnerEmail());
    Visibility visibility = Visibility.valueToEnum(entry.getVisibility());
    // information about the owner and creator
    if (includeOwnerInfo) {
        view.setOwner(entry.getOwner());
        view.setOwnerId(getAccountId(entry.getOwnerEmail()));
        // creator
        view.setCreator(entry.getCreator());
        view.setCreatorEmail(entry.getCreatorEmail());
        view.setCreatorId(getAccountId(entry.getCreatorEmail()));
    }
    // has sample
    view.setHasSample(DAOFactory.getSampleDAO().hasSample(entry));
    // has sequence
    if (visibility == Visibility.REMOTE) {
        view.setHasSequence(entry.getLongDescriptionType().equalsIgnoreCase("sequence"));
    } else {
        SequenceDAO sequenceDAO = DAOFactory.getSequenceDAO();
        view.setHasSequence(sequenceDAO.hasSequence(entry.getId()));
        view.setHasOriginalSequence(sequenceDAO.hasOriginalSequence(entry.getId()));
    }
    // has parents
    for (Entry linkedEntry : entry.getLinkedEntries()) {
        // todo : authorization
        //            if (!authorization.canRead(userId, parent))
        //                continue;
        PartData linkedPartData = new PartData(EntryType.nameToType(linkedEntry.getRecordType()));
        linkedPartData.setId(linkedEntry.getId());
        view.getLinkedParts().add(linkedPartData);
    }
    List<Entry> parents = DAOFactory.getEntryDAO().getParents(entry.getId());
    if (parents != null) {
        for (Entry parentEntry : parents) {
            PartData partData = new PartData(EntryType.nameToType(parentEntry.getRecordType()));
            partData.setId(parentEntry.getId());
            view.getParents().add(partData);
        }
    }
    // entry count
    view.setViewCount(DAOFactory.getAuditDAO().getHistoryCount(entry));
    return view;
}
Also used : SequenceDAO(org.jbei.ice.storage.hibernate.dao.SequenceDAO)

Example 4 with SequenceDAO

use of org.jbei.ice.storage.hibernate.dao.SequenceDAO in project ice by JBEI.

the class Collection method setFileData.

protected PartData setFileData(String userId, Entry entry, PartData partData) {
    SequenceDAO sequenceDAO = DAOFactory.getSequenceDAO();
    if (sequenceDAO.hasSequence(entry.getId())) {
        partData.setHasSequence(true);
        String name = sequenceDAO.getSequenceFilename(entry);
        partData.setSequenceFileName(name);
    }
    AttachmentController attachmentController = new AttachmentController();
    // check attachment
    if (attachmentController.hasAttachment(entry)) {
        partData.setHasAttachment(true);
        partData.setAttachments(attachmentController.getByEntry(userId, entry.getId()));
    }
    return partData;
}
Also used : AttachmentController(org.jbei.ice.lib.entry.attachment.AttachmentController) SequenceDAO(org.jbei.ice.storage.hibernate.dao.SequenceDAO)

Example 5 with SequenceDAO

use of org.jbei.ice.storage.hibernate.dao.SequenceDAO in project ice by JBEI.

the class RemoteEntriesAsCSV method writeLocalEntries.

protected void writeLocalEntries(List<Entry> entries, List<EntryField> fields, CSVWriter writer, ZipOutputStream zos) {
    if (entries == null)
        return;
    SequenceDAO sequenceDAO = DAOFactory.getSequenceDAO();
    Configuration configuration = DAOFactory.getConfigurationDAO().get(ConfigurationKey.URI_PREFIX);
    String thisUrl = configuration == null ? "" : configuration.getValue();
    for (Entry entry : entries) {
        String[] line = new String[fields.size() + 4];
        line[0] = thisUrl;
        line[1] = entry.getCreationTime().toString();
        line[2] = entry.getPartNumber();
        int i = 2;
        for (EntryField field : fields) {
            line[i + 1] = EntryUtil.entryFieldToValue(entry, field);
            i += 1;
        }
        // write sequence to zip file
        long entryId = entry.getId();
        if (sequenceDAO.hasSequence(entryId)) {
            String name = entry.getPartNumber() + ".gb";
            try {
                Sequence sequence = sequenceDAO.getByEntry(entry);
                line[i + 1] = name;
                GenbankFormatter genbankFormatter = new GenbankFormatter(name);
                ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
                genbankFormatter.format(sequence, byteStream);
                ByteArrayWrapper wrapper = new ByteArrayWrapper(byteStream.toByteArray(), name);
                putZipEntry(wrapper, zos);
            } catch (Exception e) {
                line[i + 1] = "";
            }
        } else {
            line[i + 1] = "";
        }
        writer.writeNext(line);
    }
}
Also used : FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) EntryField(org.jbei.ice.lib.dto.entry.EntryField) GenbankFormatter(org.jbei.ice.lib.entry.sequence.composers.formatters.GenbankFormatter) ZipEntry(java.util.zip.ZipEntry) ByteArrayWrapper(org.jbei.ice.lib.entry.sequence.ByteArrayWrapper) SequenceDAO(org.jbei.ice.storage.hibernate.dao.SequenceDAO)

Aggregations

SequenceDAO (org.jbei.ice.storage.hibernate.dao.SequenceDAO)6 ArrayList (java.util.ArrayList)1 ZipEntry (java.util.zip.ZipEntry)1 IllegalSymbolException (org.biojava.bio.symbol.IllegalSymbolException)1 SymbolList (org.biojava.bio.symbol.SymbolList)1 Curation (org.jbei.ice.lib.dto.Curation)1 DNAFeature (org.jbei.ice.lib.dto.DNAFeature)1 DNASequence (org.jbei.ice.lib.dto.DNASequence)1 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)1 EntryField (org.jbei.ice.lib.dto.entry.EntryField)1 AttachmentController (org.jbei.ice.lib.entry.attachment.AttachmentController)1 ByteArrayWrapper (org.jbei.ice.lib.entry.sequence.ByteArrayWrapper)1 GenbankFormatter (org.jbei.ice.lib.entry.sequence.composers.formatters.GenbankFormatter)1 SequenceFeatureDAO (org.jbei.ice.storage.hibernate.dao.SequenceFeatureDAO)1 Sequence (org.jbei.ice.storage.model.Sequence)1 Test (org.junit.Test)1