biojava Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException:

早过忘川 提交于 2019-12-25 02:55:09

问题


I have problem with multiple sequence alignement. I have two sequences as follow and I m trying to align them using biojava methods and I get error like this. I have no idea what is wrong. I know that sequences are not the same length but it should not matter.

GSKTGTKITFYEDKNFQGRRYDCDCDCADFHTYLSRCNSIKVEGGTWAVYERPNFAGYMYILPQGEYPEYQRWMGLNDRLSSCRAVHLPSGGQYKIQIFEKGDFSGQMYETTEDCPSIMEQFHMREIHSCKVLEGVWIFYELPNYRGRQYLLDKKEYRKPIDWGAASPAVQSFRRIVE SMSAGPWKMVVWDEDGFQGRRHEFTAECPSVLELGFETVRSLKVLSGAWVGFEHAGFQGQQYILERGEYPSWDAWGGNTAYPAERLTSFRPAACANHRDSRLTIFEQENFLGKKGELSDDYPSLQAMGWEGNEVGSFHVHSGAWVCSQFPGYRGFQYVLECDHHSGDYKHFREWGSHAPTFQVQSIRRIQQ

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 at org.forester.evoinference.distance.NeighborJoining.getValueFromD(NeighborJoining.java:150) at org.forester.evoinference.distance.NeighborJoining.execute(NeighborJoining.java:123) at org.biojava3.alignment.GuideTree.(GuideTree.java:88) at org.biojava3.alignment.Alignments.getMultipleSequenceAlignment(Alignments.java:183) at Fasta.main(Fasta.java:41)

public class Fasta {

    public static void main(String[] args) throws Exception{


        ArrayList<String> fileName = new ArrayList<String> ();
        fileName.add("2M3T.fasta.txt");
        fileName.add("3LWK.fasta.txt");
        ArrayList<ProteinSequence> al = new ArrayList<ProteinSequence>();
        //ArrayList<ProteinSequence> all =  new ArrayList<ProteinSequence>();
        for (String fn : fileName)
        {
        al = getProteinSequenceFromFasta(fn);
        //all.add(al.get(0));
        for  (ProteinSequence s : al)
        {
            System.out.println(s);
        }
        }
        Profile<ProteinSequence, AminoAcidCompound> profile = Alignments.getMultipleSequenceAlignment(al);
        System.out.printf("Clustalw:%n%s%n", profile);
        ConcurrencyTools.shutdown();
        }
        //for (int i=0;i<sequence.size();i++)
        //  System.out.println(sequence);


    public static ArrayList<ProteinSequence> getProteinSequenceFromFasta(String file) throws Exception{

        LinkedHashMap<String, ProteinSequence> a = FastaReaderHelper.readFastaProteinSequence(new File(file));
        //sztuczne
        ArrayList<ProteinSequence> sequence =  new ArrayList<ProteinSequence>(a.values());


        return sequence;
    }
}

回答1:


My guess is the problem is at this line:

for (String fn : fileName)
{
    al = getProteinSequenceFromFasta(fn);
...
 }

You are overwriting the contents of a1 for each file. (I assume you want to add all the fasta records into a1. If your fasta files only has 1 record each then it can't do a multiple alignment to a single record.

You probably want

for (String fn : fileName)
{
    al.addAll(getProteinSequenceFromFasta(fn) );
...
 }

Granted, the library you are using should probably have checked first to make sure there are more than 1 sequences....



来源:https://stackoverflow.com/questions/24428773/biojava-exception-in-thread-main-java-lang-arrayindexoutofboundsexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!