From: Jim Procter Date: Mon, 16 Jan 2017 12:28:27 +0000 (+0000) Subject: JAL-2349 JAL-2382 Contact prediction/CASP-RR importer X-Git-Tag: Release_2_11_4_0~562^2~9^2~16 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=554e7dbf49226f573e291891bac6b87a2b8880d9;p=jalview.git JAL-2349 JAL-2382 Contact prediction/CASP-RR importer --- diff --git a/src/jalview/io/PContactPredictionFile.java b/src/jalview/io/PContactPredictionFile.java new file mode 100644 index 0000000..92500c0 --- /dev/null +++ b/src/jalview/io/PContactPredictionFile.java @@ -0,0 +1,136 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview 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 3 + * of the License, or (at your option) any later version. + * + * Jalview 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 Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.io; + +import jalview.datamodel.ContactMatrix; +import jalview.datamodel.SequenceI; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * A file parser for contact prediction files. + * + * An example file is the following + * + *
+ * 
+ * 
+ * + * + * @author jim procter + * + */ +public class PContactPredictionFile extends AlignFile +{ + public PContactPredictionFile(String inFile, DataSourceType fileSourceType) + throws IOException + { + super(inFile, fileSourceType); + + } + + public PContactPredictionFile(FileParse source) throws IOException + { + super(source); + } + + Integer fWidth; + + List models = new ArrayList(); + + public List getContactMatrices() + { + return models; + } + + /* + * RaptorX pattern: + * for a contact prediction + * Target sequence + * alignment for target sequence + * contact matrix for sequence + * models generated that fit matrix + */ + + /* + * TODO: create annotation rows from contact matrices. + * (non-Javadoc) + * @see jalview.io.AlignFile#parse() + */ + @Override + public void parse() throws IOException + { + String line; + /* + * stash any header lines if we've been given a CASP-RR file + */ + Map header = new HashMap(); + ContactMatrix cm = null; + + while ((line = nextLine()) != null) + { + int left, right; + double strength = Float.NaN; + String parts[] = line.split("\\s+"); + + // check for header tokens in parts[0] + + // others - stash details + // MODEL - start a new matrix + // skip comments ? + + if (parts.length == 3) // and all are integers + { + + if (cm == null) + { + cm = new ContactMatrix(true); + models.add(cm); + } + + try + { + left = Integer.parseInt(parts[0]); + right = Integer.parseInt(parts[1]); + strength = Double.parseDouble(parts[2]); + } catch (Exception x) + { + error = true; + errormessage = "Couldn't process line: " + + x.getLocalizedMessage() + "\n" + line; + return; + } + cm.addContact(left, right, (float) strength); + } + } + } + + @Override + public String print(SequenceI[] sqs, boolean jvsuffix) + { + // TODO Auto-generated method stub + return "Not valid."; + } +}