Search in sources :

Example 1 with FeaturedDNASequence

use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.

the class EntryCreator method copyPart.

/**
     * Creates a copy of
     *
     * @param userId   identifier for user making request
     * @param sourceId unique identifier for part acting as source of copy. Can be the part id, uuid or id
     * @return wrapper around the id and record id of the newly created entry
     * @throws IllegalArgumentException if the source part for the copy cannot be located using the identifier
     */
public PartData copyPart(String userId, String sourceId) {
    Entry entry = getEntry(sourceId);
    if (entry == null)
        throw new IllegalArgumentException("Could not retrieve entry \"" + sourceId + "\" for copy");
    // check permission (expecting read permission)
    entryAuthorization.expectRead(userId, entry);
    Sequence sequence = null;
    if (sequenceDAO.hasSequence(entry.getId())) {
        sequence = sequenceDAO.getByEntry(entry);
    }
    // copy to data model and back ??
    PartData partData = ModelToInfoFactory.getInfo(entry);
    entry = InfoToModelFactory.infoToEntry(partData);
    // create entry
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    entry.setName(entry.getName() + " (copy)");
    entry.setRecordId(Utils.generateUUID());
    entry.setVersionId(entry.getRecordId());
    entry.setOwnerEmail(account.getEmail());
    entry.setOwner(account.getFullName());
    entry = createEntry(account, entry, new ArrayList<>());
    // check sequence
    if (sequence != null) {
        SequenceController sequenceController = new SequenceController();
        FeaturedDNASequence dnaSequence = sequenceController.sequenceToDNASequence(sequence);
        sequence = SequenceController.dnaSequenceToSequence(dnaSequence);
        sequence.setEntry(entry);
        sequenceDAO.saveSequence(sequence);
        BlastPlus.scheduleBlastIndexRebuildTask(true);
    }
    PartData copy = new PartData(EntryType.nameToType(entry.getRecordType()));
    copy.setId(entry.getId());
    copy.setRecordId(entry.getRecordId());
    return copy;
}
Also used : PartData(org.jbei.ice.lib.dto.entry.PartData) ArrayList(java.util.ArrayList) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) SequenceController(org.jbei.ice.lib.entry.sequence.SequenceController) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence)

Example 2 with FeaturedDNASequence

use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.

the class RemoteEntriesAsCSV method writeDataEntries.

protected void writeDataEntries(RemotePartner partner, List<PartData> entries, List<EntryField> fields, CSVWriter writer, ZipOutputStream zos) {
    if (entries == null)
        return;
    for (PartData partData : entries) {
        String[] line = new String[fields.size() + 4];
        line[0] = partner.getUrl();
        line[1] = new Date(partData.getCreationTime()).toString();
        line[2] = partData.getPartId();
        int i = 2;
        for (EntryField field : fields) {
            line[i + 1] = PartDataUtil.entryFieldToValue(partData, field);
            i += 1;
        }
        // write sequence to zip file
        if (partData.isHasSequence()) {
            try {
                // get remote sequence
                FeaturedDNASequence featuredDNASequence = remoteEntries.getPublicEntrySequence(partner.getId(), Long.toString(partData.getId()));
                if (featuredDNASequence != null) {
                    String name = partData.getPartId() + ".gb";
                    // write sequence to zip
                    line[i + 1] = name;
                    Sequence sequence = SequenceController.dnaSequenceToSequence(featuredDNASequence);
                    GenbankFormatter genbankFormatter = new GenbankFormatter(name);
                    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
                    genbankFormatter.format(sequence, byteStream);
                    ByteArrayWrapper wrapper = new ByteArrayWrapper(byteStream.toByteArray(), name);
                    putZipEntry(wrapper, zos);
                } else {
                    line[i + 1] = "";
                }
            } catch (Exception e) {
                line[i + 1] = "";
            }
        } else {
            line[i + 1] = "";
        }
        writer.writeNext(line);
    }
}
Also used : GenbankFormatter(org.jbei.ice.lib.entry.sequence.composers.formatters.GenbankFormatter) ByteArrayWrapper(org.jbei.ice.lib.entry.sequence.ByteArrayWrapper) PartData(org.jbei.ice.lib.dto.entry.PartData) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) Date(java.util.Date) EntryField(org.jbei.ice.lib.dto.entry.EntryField)

Example 3 with FeaturedDNASequence

use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.

the class FastaParser method parse.

@Override
public FeaturedDNASequence parse(String textSequence) throws InvalidFormatParserException {
    try {
        textSequence = cleanSequence(textSequence);
        try (BufferedReader br = new BufferedReader(new StringReader(textSequence))) {
            FeaturedDNASequence sequence;
            RichSequenceIterator richSequences = IOTools.readFastaDNA(br, null);
            if (richSequences.hasNext()) {
                RichSequence richSequence = richSequences.nextRichSequence();
                sequence = new FeaturedDNASequence(richSequence.seqString(), new LinkedList<>());
            } else {
                throw new InvalidFormatParserException("No sequence found in sequence file!");
            }
            return sequence;
        }
    } catch (BioException | IOException e) {
        throw new InvalidFormatParserException("Couldn't parse FASTA sequence!", e);
    }
}
Also used : BioException(org.biojava.bio.BioException) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) RichSequenceIterator(org.biojavax.bio.seq.RichSequenceIterator) InvalidFormatParserException(org.jbei.ice.lib.parsers.InvalidFormatParserException) IOException(java.io.IOException) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) LinkedList(java.util.LinkedList) RichSequence(org.biojavax.bio.seq.RichSequence)

Example 4 with FeaturedDNASequence

use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.

the class PlainParser method parse.

@Override
public FeaturedDNASequence parse(Iterator<String> iterator, String... entryType) throws InvalidFormatParserException {
    SymbolList sl;
    try {
        String textSequence = getSequence(iterator);
        textSequence = cleanSequence(textSequence);
        sl = new SimpleSymbolList(DNATools.getDNA().getTokenization("token"), textSequence.replaceAll("\\s+", "").replaceAll("[\\.|~]", "-").replaceAll("[0-9]", ""));
    } catch (BioException e) {
        throw new InvalidFormatParserException("Couldn't parse Plain sequence!", e);
    }
    return new FeaturedDNASequence(sl.seqString(), new ArrayList<>());
}
Also used : BioException(org.biojava.bio.BioException) SimpleSymbolList(org.biojava.bio.symbol.SimpleSymbolList) SymbolList(org.biojava.bio.symbol.SymbolList) SimpleSymbolList(org.biojava.bio.symbol.SimpleSymbolList) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence)

Example 5 with FeaturedDNASequence

use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.

the class FeaturesSectionTest method process.

@Test
public void process() {
    FeaturedDNASequence sequence = new FeaturedDNASequence();
    FeaturesSection tag = new FeaturesSection(sequence);
    String[] lines = feature.split("\n");
    for (String line : lines) tag.process(line);
    Assert.assertNotNull(sequence);
    Assert.assertEquals(sequence.getFeatures().size(), 1);
    DNAFeature feature = sequence.getFeatures().get(0);
    Assert.assertEquals("CDS", feature.getType());
    Assert.assertEquals(2, feature.getLocations().size());
    Assert.assertEquals(7, feature.getNotes().size());
}
Also used : DNAFeature(org.jbei.ice.lib.dto.DNAFeature) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) Test(org.junit.Test)

Aggregations

FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)47 Test (org.junit.Test)23 HibernateRepositoryTest (org.jbei.ice.storage.hibernate.HibernateRepositoryTest)17 Account (org.jbei.ice.storage.model.Account)17 Sequence (org.jbei.ice.storage.model.Sequence)14 DNAFeature (org.jbei.ice.lib.dto.DNAFeature)8 Plasmid (org.jbei.ice.storage.model.Plasmid)8 IOException (java.io.IOException)5 SequenceInfo (org.jbei.ice.lib.dto.entry.SequenceInfo)5 Strain (org.jbei.ice.storage.model.Strain)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InvalidFormatParserException (org.jbei.ice.lib.parsers.InvalidFormatParserException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ArrayList (java.util.ArrayList)3 BioException (org.biojava.bio.BioException)3 PartData (org.jbei.ice.lib.dto.entry.PartData)3 BufferedReader (java.io.BufferedReader)2 StringReader (java.io.StringReader)2 Date (java.util.Date)2 LinkedList (java.util.LinkedList)2