Skip to content
Snippets Groups Projects
Commit e56375d1 authored by tjc's avatar tjc
Browse files

ensure the tool does not transfer and duplicate existing qualifiers

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@10162 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent 3930aaa1
No related branches found
No related tags found
No related merge requests found
...@@ -52,10 +52,12 @@ import uk.ac.sanger.artemis.components.genebuilder.GeneEdit; ...@@ -52,10 +52,12 @@ import uk.ac.sanger.artemis.components.genebuilder.GeneEdit;
import uk.ac.sanger.artemis.components.genebuilder.GeneUtils; import uk.ac.sanger.artemis.components.genebuilder.GeneUtils;
import uk.ac.sanger.artemis.io.DatabaseDocumentEntry; import uk.ac.sanger.artemis.io.DatabaseDocumentEntry;
import uk.ac.sanger.artemis.io.GFFStreamFeature; import uk.ac.sanger.artemis.io.GFFStreamFeature;
import uk.ac.sanger.artemis.io.InvalidRelationException;
import uk.ac.sanger.artemis.io.PartialSequence; import uk.ac.sanger.artemis.io.PartialSequence;
import uk.ac.sanger.artemis.io.Qualifier; import uk.ac.sanger.artemis.io.Qualifier;
import uk.ac.sanger.artemis.io.QualifierVector; import uk.ac.sanger.artemis.io.QualifierVector;
import uk.ac.sanger.artemis.util.DatabaseDocument; import uk.ac.sanger.artemis.util.DatabaseDocument;
import uk.ac.sanger.artemis.util.StringVector;
class TransferAnnotationTool extends JFrame class TransferAnnotationTool extends JFrame
{ {
...@@ -69,12 +71,17 @@ class TransferAnnotationTool extends JFrame ...@@ -69,12 +71,17 @@ class TransferAnnotationTool extends JFrame
"Parent", "Parent",
"isObsolete", "isObsolete",
"timelastmodified", "timelastmodified",
"cytoplasm_location",
"non_cytoplasm_location",
"orthologous_to", "orthologous_to",
"paralogous_to", "paralogous_to",
"PlasmoAP_score",
"polypeptide_domain",
"fasta_file", "fasta_file",
"blastp_file", "blastp_file",
"blastn_file", "blastn_file",
"systematic_id", "systematic_id",
"transmembrane",
"previous_systematic_id" "previous_systematic_id"
}; };
...@@ -311,36 +318,81 @@ class TransferAnnotationTool extends JFrame ...@@ -311,36 +318,81 @@ class TransferAnnotationTool extends JFrame
* @return * @return
*/ */
private String[] transfer(final FeatureVector features, private String[] transfer(final FeatureVector features,
final QualifierVector qualifiersToTransfer, final QualifierVector qualifiersToTransfer,
final String key, final String key,
final boolean sameKey, final boolean sameKey,
final boolean isDatabaseEntry, final boolean isDatabaseEntry,
String[] geneNames) String[] geneNames)
{ {
final TransferFeaturePredicate predicate = new TransferFeaturePredicate( final TransferFeaturePredicate predicate = new TransferFeaturePredicate(
key, sameKey, isDatabaseEntry, geneNames); key, sameKey, isDatabaseEntry, geneNames);
for (int i = 0; i < features.size(); i++) for (int i = 0; i < features.size(); i++)
{ {
Feature thisFeature = features.elementAt(i); Feature thisFeature = features.elementAt(i);
if (predicate.testPredicate(thisFeature)) if (predicate.testPredicate(thisFeature))
{ {
for (int j = 0; j < qualifiersToTransfer.size(); j++) for (int j = 0; j < qualifiersToTransfer.size(); j++)
{ {
Qualifier qualifier = (Qualifier) qualifiersToTransfer.elementAt(j); Qualifier newQualifier = (Qualifier) qualifiersToTransfer.elementAt(j);
try
{ try
thisFeature.addQualifierValues(qualifier); {
} catch (Exception e1) final StringVector oldValues;
{ if(thisFeature.getQualifierByName(newQualifier.getName()) == null)
e1.printStackTrace(); oldValues = null;
} else
} oldValues =
geneNames = removeArrayElement(geneNames, predicate.getGeneName()); thisFeature.getQualifierByName(newQualifier.getName()).getValues();
}
} final Qualifier newQualifierTmp =
return geneNames; getQualifierWithoutDuplicateValues(newQualifier, oldValues);
} if(newQualifierTmp == null)
continue;
thisFeature.addQualifierValues(newQualifierTmp);
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
geneNames = removeArrayElement(geneNames, predicate.getGeneName());
}
}
return geneNames;
}
/**
* Return a qualifier copy of the qualifier provided that does not contain
* any of the values in the StringVector.
* @param newQualifier
* @param oldValues
* @return
* @throws InvalidRelationException
*/
private Qualifier getQualifierWithoutDuplicateValues(
final Qualifier qualifier,
final StringVector values) throws InvalidRelationException
{
final Qualifier newQualifier;
if (values == null || values.size() < 1)
newQualifier = qualifier;
else
{
StringVector newValues = qualifier.getValues();
StringVector valuesToAdd = new StringVector();
for (int k = 0; k < newValues.size(); k++)
{
if(!values.contains(newValues.get(k)))
valuesToAdd.add(newValues.get(k));
}
if(valuesToAdd.size() == 0)
return null;
newQualifier = new Qualifier(qualifier.getName(), valuesToAdd);
}
return newQualifier;
}
/** /**
* Remove a string from an array of strings. If the string appears multiple * Remove a string from an array of strings. If the string appears multiple
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment