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;
}
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);
}
}
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);
}
}
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<>());
}
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());
}
Aggregations