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

use groupBy to merge FeatureProps

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@4705 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent f3f8c823
No related branches found
No related tags found
No related merge requests found
......@@ -712,7 +712,11 @@ public class ChadoTransactionManager
// happens when duplicating features
FeatureProp featureprop = new FeatureProp();
featureprop.setValue((String)qualifier_values.elementAt(value_index));
chado_feature.addQualifier(type_id, featureprop);
CvTerm cvTerm = new CvTerm();
cvTerm.setCvTermId(type_id);
featureprop.setCvTerm(cvTerm);
chado_feature.addFeatureProp(featureprop);
// chado_feature.addQualifier(type_id, featureprop);
// }
}
}
......
......@@ -69,8 +69,6 @@ public class Feature
private Organism organism;
/** optional primary public stable identifier */
private FeatureDbXRef featureDbXRef;
/** merged featureprops */
private Hashtable qualifiers;
/** list of FeatureProp */
private Collection featureProps;
/** list of FeatureRelationship children */
......@@ -403,11 +401,11 @@ public class Feature
{
this.featureProps = featureProps;
for(int i=0; i<featureProps.size(); i++)
/* for(int i=0; i<featureProps.size(); i++)
{
FeatureProp featureprop = (FeatureProp)(((List)featureProps).get(i));
addQualifier(featureprop.getCvTerm().getCvTermId(), featureprop);
}
}*/
}
/**
......@@ -494,44 +492,19 @@ public class Feature
this.featureSynonymsForFeatureId = featureSynonymsForFeatureId;
}
/**
* Used in merging the qualifiers to store them as a <code>Hashtable</code> of
* the cvTerm type_id (of the property name) and the property values as a
* <code>Vector</code>.
* @param the cvTerm type_id of the property name
* @param the property value
* Used in merging the qualifiers to store them as a <code>List</code> of
* <code>FeatureProp</code>.
* @param the FeatureProp
*/
public void addQualifier(long prop_type_id, FeatureProp featprop)
public void addFeatureProp(final FeatureProp featureprop)
{
if(qualifiers == null)
qualifiers = new Hashtable();
if(featureProps == null)
featureProps = new Vector();
final Long type_id = new Long(prop_type_id);
if(qualifiers.containsKey(type_id))
{
Vector v = (Vector)qualifiers.get(type_id);
v.add(featprop);
qualifiers.put(type_id, v);
}
else
{
Vector v = new Vector();
v.add(featprop);
qualifiers.put(type_id, v);
}
featureProps.add(featureprop);
}
/**
* Get the qualifiers which are stored as a <code>Hashtable</code> of cvTerm
* type_id (of the property name) and the property values as a <code>Vector</code>.
* @return the qualifiers as a <code>Hashtable</code>
*/
public Hashtable getQualifiers()
{
return qualifiers;
}
/**
* Utility for finding a feature location from a List that corresponds
......
......@@ -92,7 +92,8 @@ public class IBatisDAO implements ChadoDAO
List feature_list = sqlMap.queryForList("getFeature", feature);
// merge same features in the list
return mergeList(feature_list);
//return mergeList(feature_list);
return feature_list;
}
/**
......@@ -495,51 +496,6 @@ public class IBatisDAO implements ChadoDAO
sqlMap.commitTransaction();
}
/**
* Takes a list and creates a new one merging all feature objects
* within it with the same feature and stores the qualifiers/attributes
* as a hash
* @param list of feature objects
* @return list of flattened/merged feature objects
*/
protected static List mergeList(final List list)
{
// merge same features in the list
int feature_size = list.size();
final List flatten_list = new Vector();
Feature featNext = null;
for(int i = 0; i < feature_size; i++)
{
Feature feat = (Feature)list.get(i);
String name = feat.getUniqueName();
feat.addQualifier(feat.getFeatureprop().getCvTerm().getCvTermId(),
feat.getFeatureprop());
if(i < feature_size - 1)
featNext = (Feature)list.get(i + 1);
else
featNext = null;
// merge next line if part of the same feature
while(featNext != null && featNext.getUniqueName().equals(name))
{
feat.addQualifier(featNext.getFeatureprop().getCvTerm().getCvTermId(),
featNext.getFeatureprop());
i++;
if(i < feature_size - 1)
featNext = (Feature)list.get(i + 1);
else
break;
}
flatten_list.add(feat);
}
return flatten_list;
}
/**
* Takes a list and creates a <code>Hashtable</code> with the keys
......
......@@ -251,7 +251,7 @@ public class JdbcDAO
throw new RuntimeException(sqle);
}
// merge same features in the list
return IBatisDAO.mergeList(list);
return mergeList(list);
}
......@@ -1183,4 +1183,51 @@ public class JdbcDAO
}
}
/**
* Takes a list and creates a new one merging all feature objects
* within it with the same feature and stores the qualifiers/attributes
* as a hash
* @param list of feature objects
* @return list of flattened/merged feature objects
*/
private static List mergeList(final List list)
{
// merge same features in the list
int feature_size = list.size();
final List flatten_list = new Vector();
Feature featNext = null;
for(int i = 0; i < feature_size; i++)
{
Feature feat = (Feature)list.get(i);
String name = feat.getUniqueName();
feat.addFeatureProp(feat.getFeatureprop());
//feat.addQualifier(feat.getFeatureprop().getCvTerm().getCvTermId(),
// feat.getFeatureprop());
if(i < feature_size - 1)
featNext = (Feature)list.get(i + 1);
else
featNext = null;
// merge next line if part of the same feature
while(featNext != null && featNext.getUniqueName().equals(name))
{
//feat.addQualifier(featNext.getFeatureprop().getCvTerm().getCvTermId(),
// featNext.getFeatureprop());
feat.addFeatureProp(featNext.getFeatureprop());
i++;
if(i < feature_size - 1)
featNext = (Feature)list.get(i + 1);
else
break;
}
flatten_list.add(feat);
}
return flatten_list;
}
}
......@@ -740,29 +740,20 @@ public class DatabaseDocument extends Document
//this_buff.append("feature_id="+feature_id+";");
// attributes
Hashtable qualifiers = feat.getQualifiers();
if(qualifiers != null && qualifiers.size() > 0)
if(feat.getFeatureProps() != null)
{
Enumeration e_qualifiers = qualifiers.keys();
while(e_qualifiers.hasMoreElements())
List featureprops = (List)feat.getFeatureProps();
for(int j=0; j<featureprops.size(); j++)
{
Long qualifier_type_id = (Long)e_qualifiers.nextElement();
String qualifier_name = getCvtermName(qualifier_type_id.longValue(), dao);
FeatureProp featprop = (FeatureProp)featureprops.get(j);
String qualifier_name = getCvtermName(featprop.getCvTerm().getCvTermId(), dao);
if(qualifier_name == null)
continue;
Vector qualifier_value = (Vector)qualifiers.get(qualifier_type_id);
for(int j=0; j<qualifier_value.size(); j++)
{
FeatureProp featprop = (FeatureProp)qualifier_value.get(j);
if(featprop.getValue() != null)
this_buff.append(qualifier_name+ "=" +
GFFStreamFeature.encode(featprop.getValue())+";");
}
}
}
// append dbxrefs
if(dbxref != null && dbxref.size() > 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment