Skip to content
Snippets Groups Projects
Commit 2222c866 authored by tcarver's avatar tcarver
Browse files

feature offset in GFF with multiple sequences

parent ff118c0f
No related branches found
No related tags found
No related merge requests found
/*
* This file is part of Artemis
*
* Copyright (C) 2013 Genome Research Limited
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
package uk.ac.sanger.artemis.io;
import static org.junit.Assert.assertTrue;
import junit.framework.Assert;
import org.junit.Test;
import uk.ac.sanger.artemis.EntryGroup;
import uk.ac.sanger.artemis.Feature;
import uk.ac.sanger.artemis.FeatureVector;
import uk.ac.sanger.artemis.Options;
import uk.ac.sanger.artemis.SimpleEntryGroup;
import uk.ac.sanger.artemis.io.Entry;
import uk.ac.sanger.artemis.io.Qualifier;
import uk.ac.sanger.artemis.io.InvalidRelationException;
import uk.ac.sanger.artemis.sequence.NoSequenceException;
import uk.ac.sanger.artemis.util.OutOfRangeException;
import uk.ac.sanger.artemis.util.StringVector;
public class GFFTest
{
@Test
/**
* For a GFF with multiple sequences check the offset position
* of a gene is correctly set.
*/
public void testGFFMultipleFastaOffset()
{
try
{
final Entry entry = Utils.getEntry("/data/Pf3D7_01_02_v3.gff.gz");
final EntryGroup egrp = new SimpleEntryGroup();
egrp.add(new uk.ac.sanger.artemis.Entry(entry));
final FeatureVector features = egrp.getAllFeatures();
// change the translation table did cause a problem
// with the offset that has now been fixed in GFFDocumentEntry
Utils.changeTranslationTable("11");
for (int i=0; i<features.size(); i++)
{
Feature f = features.elementAt(i);
try
{
final Qualifier q = f.getQualifierByName("ID");
if (q != null)
{
final String id = q.getValues().get(0);
if (id.equals("PF3D7_0200100"))
{
assertTrue("Offset check first base: " + id +
" " +f.getFirstBase() + " != 666083",
f.getFirstBase() == 666083);
assertTrue("Offset check location: " + id+
" " +f.getEmblFeature().getLocation().getFirstBase() + " != 666083",
f.getEmblFeature().getLocation().getFirstBase() == 666083);
}
}
}
catch(InvalidRelationException e)
{
Assert.fail(e.getMessage());
}
}
}
catch (OutOfRangeException e)
{
Assert.fail(e.getMessage());
}
catch (NoSequenceException e)
{
Assert.fail(e.getMessage());
}
}
}
\ No newline at end of file
/*
* This file is part of Artemis
*
* Copyright (C) 2013 Genome Research Limited
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
package uk.ac.sanger.artemis.io;
import java.io.IOException;
import java.net.URL;
import junit.framework.Assert;
import uk.ac.sanger.artemis.Options;
import uk.ac.sanger.artemis.io.DocumentEntryFactory;
import uk.ac.sanger.artemis.io.Entry;
import uk.ac.sanger.artemis.io.EntryInformationException;
import uk.ac.sanger.artemis.sequence.AminoAcidSequence;
import uk.ac.sanger.artemis.sequence.Bases;
import uk.ac.sanger.artemis.util.Document;
import uk.ac.sanger.artemis.util.DocumentFactory;
import uk.ac.sanger.artemis.util.StringVector;
public class Utils
{
protected static Entry getEntry(final String fileName)
{
try
{
URL entryFile = ValidateFeatureTest.class.getResource(fileName);
final Document doc = DocumentFactory.makeDocument(entryFile.getFile());
return DocumentEntryFactory.makeDocumentEntry(
Options.getArtemisEntryInformation(),doc,null);
}
catch(EntryInformationException e)
{
Assert.fail(e.getMessage());
}
catch(IOException e)
{
Assert.fail(e.getMessage());
}
return null;
}
/**
* Method to change the translation table being used
* @param n - genetic code table number
*/
protected static void changeTranslationTable(String n)
{
StringVector options_file_table =
Options.getOptions().getOptionValues("translation_table_"+n);
StringVector table = Options.getOptions().getOptionValues("translation_table_1");
for(String cod_plus_aa: options_file_table)
{
final int codon_index = Bases.getIndexOfBase(cod_plus_aa.charAt(0)) * 16 +
Bases.getIndexOfBase(cod_plus_aa.charAt(1)) * 4 +
Bases.getIndexOfBase(cod_plus_aa.charAt(2));
table.setElementAt(cod_plus_aa.substring(3), codon_index);
}
StringBuffer sbuff = new StringBuffer();
for(int i = 0; i < 64; ++i)
sbuff.append(table.elementAt(i)+" ");
Options.getOptions().setGeneticCode(sbuff.toString());
options_file_table =
Options.getOptions().getOptionValues("start_codons_"+n);
sbuff = new StringBuffer();
for(String start: options_file_table)
sbuff.append(start+" ");
Options.getOptions().setProperty("start_codons",sbuff.toString());
AminoAcidSequence.setGeneCode();
}
}
\ No newline at end of file
/*
* This file is part of Artemis
*
* Copyright (C) 2013 Genome Research Limited
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
package uk.ac.sanger.artemis.io;
import static org.junit.Assert.assertEquals;
......@@ -36,7 +56,7 @@ public class ValidateFeatureTest
{
try
{
final Entry entry = getEntry("/data/test.gff.gz");
final Entry entry = Utils.getEntry("/data/test.gff.gz");
final EntryGroup egrp = new SimpleEntryGroup();
egrp.add(new uk.ac.sanger.artemis.Entry(entry));
ValidateFeature validate = new ValidateFeature(egrp);
......@@ -82,7 +102,7 @@ public class ValidateFeatureTest
@Test
public void testGFFBoundary()
{
final Entry entry = getEntry("/data/test_boundary.gff.gz");
final Entry entry = Utils.getEntry("/data/test_boundary.gff.gz");
final FeatureVector features = entry.getAllFeatures();
for(uk.ac.sanger.artemis.io.Feature f: features)
......@@ -105,7 +125,7 @@ public class ValidateFeatureTest
@Test
public void testGFFStrand()
{
final Entry entry = getEntry("/data/test_boundary.gff.gz");
final Entry entry = Utils.getEntry("/data/test_boundary.gff.gz");
final FeatureVector features = entry.getAllFeatures();
for(uk.ac.sanger.artemis.io.Feature f: features)
......@@ -128,7 +148,7 @@ public class ValidateFeatureTest
@Test
public void testGFFPhase()
{
final Entry entry = getEntry("/data/test_boundary.gff.gz");
final Entry entry = Utils.getEntry("/data/test_boundary.gff.gz");
final FeatureVector features = entry.getAllFeatures();
for(uk.ac.sanger.artemis.io.Feature f: features)
......@@ -151,7 +171,7 @@ public class ValidateFeatureTest
@Test
public void testGFFCompleteGeneModel()
{
final Entry entry = getEntry("/data/test_boundary.gff.gz");
final Entry entry = Utils.getEntry("/data/test_boundary.gff.gz");
final FeatureVector features = entry.getAllFeatures();
for(uk.ac.sanger.artemis.io.Feature f: features)
......@@ -180,7 +200,7 @@ public class ValidateFeatureTest
@Test
public void testGFFId()
{
final Entry entry = getEntry("/data/test_boundary.gff.gz");
final Entry entry = Utils.getEntry("/data/test_boundary.gff.gz");
final FeatureVector features = entry.getAllFeatures();
for(uk.ac.sanger.artemis.io.Feature f: features)
......@@ -205,7 +225,7 @@ public class ValidateFeatureTest
@Test
public void testGFFPartials()
{
final Entry entry = getEntry("/data/test_boundary.gff.gz");
final Entry entry = Utils.getEntry("/data/test_boundary.gff.gz");
final FeatureVector features = entry.getAllFeatures();
for(uk.ac.sanger.artemis.io.Feature f: features)
......@@ -232,7 +252,7 @@ public class ValidateFeatureTest
@Test
public void testGFFAttributes()
{
final Entry entry = getEntry("/data/test_boundary.gff.gz");
final Entry entry = Utils.getEntry("/data/test_boundary.gff.gz");
final FeatureVector features = entry.getAllFeatures();
for(uk.ac.sanger.artemis.io.Feature f: features)
......@@ -259,7 +279,7 @@ public class ValidateFeatureTest
{
try
{
final Entry entry = getEntry("/data/test_boundary.gff.gz");
final Entry entry = Utils.getEntry("/data/test_boundary.gff.gz");
final FeatureVector features = entry.getAllFeatures();
final EntryGroup egrp = new SimpleEntryGroup();
egrp.add(new uk.ac.sanger.artemis.Entry(entry));
......@@ -294,7 +314,7 @@ public class ValidateFeatureTest
{
try
{
final Entry entry = getEntry("/data/test_boundary.gff.gz");
final Entry entry = Utils.getEntry("/data/test_boundary.gff.gz");
final FeatureVector features = entry.getAllFeatures();
final EntryGroup egrp = new SimpleEntryGroup();
egrp.add(new uk.ac.sanger.artemis.Entry(entry));
......@@ -317,24 +337,4 @@ public class ValidateFeatureTest
}
}
private Entry getEntry(final String gff)
{
try
{
URL gffFile = ValidateFeatureTest.class.getResource(gff);
final Document doc = DocumentFactory.makeDocument(gffFile.getFile());
return DocumentEntryFactory.makeDocumentEntry(
Options.getArtemisEntryInformation(),doc,null);
}
catch(EntryInformationException e)
{
Assert.fail(e.getMessage());
}
catch(IOException e)
{
Assert.fail(e.getMessage());
}
return null;
}
}
\ No newline at end of file
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