diff --git a/uk/ac/sanger/artemis/Feature.java b/uk/ac/sanger/artemis/Feature.java index 58f7d42c657ac98f6bee3454ae37d5dd5d1f65c1..781dad435f7fbfff7aa36b8b0e639b48204dcc38 100644 --- a/uk/ac/sanger/artemis/Feature.java +++ b/uk/ac/sanger/artemis/Feature.java @@ -20,7 +20,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/Feature.java,v 1.29 2007-10-02 14:17:39 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/Feature.java,v 1.30 2007-10-08 09:44:29 tjc Exp $ */ package uk.ac.sanger.artemis; @@ -60,7 +60,7 @@ import java.util.Date; * embl.Feature and embl.Entry objects. * * @author Kim Rutherford - * @version $Id: Feature.java,v 1.29 2007-10-02 14:17:39 tjc Exp $ + * @version $Id: Feature.java,v 1.30 2007-10-08 09:44:29 tjc Exp $ **/ public class Feature @@ -2628,7 +2628,7 @@ CHANGED_END: else return entry.getBases().getReverseStrand(); } - + /** * Return the reference of a new copy of this Feature. This method will * update the underlying embl.Entry and the new Feature will be installed @@ -2636,12 +2636,26 @@ CHANGED_END: * @return The reference of the new feature. **/ public Feature duplicate() + throws ReadOnlyException + { + return duplicate(false); + } + + /** + * Return the reference of a new copy of this Feature. This method will + * update the underlying embl.Entry and the new Feature will be installed + * in the same Entry object as this one. + * @param isDuplicatedInChado if true then create new ID and update in chado + * @return + * @throws ReadOnlyException + */ + public Feature duplicate(final boolean isDuplicatedInChado) throws ReadOnlyException { uk.ac.sanger.artemis.io.Feature new_embl_feature; if(getEmblFeature() instanceof GFFStreamFeature) - new_embl_feature = new GFFStreamFeature(getEmblFeature()); + new_embl_feature = new GFFStreamFeature(getEmblFeature(), isDuplicatedInChado); else new_embl_feature = new EmblStreamFeature(getEmblFeature()); @@ -2649,7 +2663,7 @@ CHANGED_END: try { - getEntry().add(return_feature, true, false); + getEntry().add(return_feature, !isDuplicatedInChado, false); } catch(EntryInformationException e) { diff --git a/uk/ac/sanger/artemis/io/GFFStreamFeature.java b/uk/ac/sanger/artemis/io/GFFStreamFeature.java index aba7c3495395dcbfe27f3457e14ce8d9e45e9641..b1a28cc4d6bc741a7ae354e4b1c9c15111c8980b 100644 --- a/uk/ac/sanger/artemis/io/GFFStreamFeature.java +++ b/uk/ac/sanger/artemis/io/GFFStreamFeature.java @@ -20,7 +20,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/GFFStreamFeature.java,v 1.56 2007-07-30 09:57:16 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/GFFStreamFeature.java,v 1.57 2007-10-08 09:43:12 tjc Exp $ */ package uk.ac.sanger.artemis.io; @@ -49,7 +49,7 @@ import uk.ac.sanger.artemis.util.StringVector; * A StreamFeature that thinks it is a GFF feature. * * @author Kim Rutherford - * @version $Id: GFFStreamFeature.java,v 1.56 2007-07-30 09:57:16 tjc Exp $ + * @version $Id: GFFStreamFeature.java,v 1.57 2007-10-08 09:43:12 tjc Exp $ **/ public class GFFStreamFeature extends SimpleDocumentFeature @@ -149,13 +149,18 @@ public class GFFStreamFeature extends SimpleDocumentFeature } } + public GFFStreamFeature(final Feature feature) + { + this(feature, false); + } + /** * Create a new GFFStreamFeature with the same key, location and * qualifiers as the given feature. The feature should be added to an * Entry (with Entry.add()). * @param feature The feature to copy. **/ - public GFFStreamFeature(final Feature feature) + public GFFStreamFeature(final Feature feature, final boolean isDuplicatedInChado) { this(feature.getKey(), feature.getLocation(), feature.getQualifiers()); @@ -171,6 +176,52 @@ public class GFFStreamFeature extends SimpleDocumentFeature this.setGffSeqName(((GFFStreamFeature)feature).getGffSeqName()); this.setGffSource(((GFFStreamFeature)feature).getGffSource()); + + + if(isDuplicatedInChado) + { + try + { + final String uniquename; + if(id_range_store != null) + { + final Hashtable new_id_range_store = new Hashtable(id_range_store.size()); + final Enumeration enumIdRangeStore = id_range_store.keys(); + while(enumIdRangeStore.hasMoreElements()) + { + final String keyId = (String)enumIdRangeStore.nextElement(); + final Range range = (Range)id_range_store.get(keyId); + new_id_range_store.put(keyId+":DUP", range); + } + id_range_store.clear(); + this.id_range_store = (Hashtable) new_id_range_store.clone(); + + uniquename = getSegmentID(getLocation().getRanges()); + } + else + uniquename = (String) getQualifierByName("ID").getValues().get(0)+":DUP"; + setQualifier(new Qualifier("ID", uniquename)); + + if(getQualifierByName("Parent") != null) + { + final String parent = + (String) getQualifierByName("Parent").getValues().get(0); + setQualifier(new Qualifier("Parent", parent+":DUP")); + } + + if(getQualifierByName("Derives_from") != null) + { + final String derives_from = + (String) getQualifierByName("Derives_from").getValues().get(0); + setQualifier(new Qualifier("Derives_from", derives_from+":DUP")); + } + removeQualifierByName("feature_id"); + removeQualifierByName("timelastmodified"); + removeQualifierByName("feature_relationship_rank"); + } + catch(ReadOnlyException e){} + catch(EntryInformationException e){} + } } }