Skip to content

Commit

Permalink
Version 1.0.20
Browse files Browse the repository at this point in the history
"Inteligent" matching of column names can be disabled
experimaental m/z and calculated mass can now also read in via the gui
  • Loading branch information
lfischer committed Oct 2, 2017
1 parent f0b8617 commit fe7402a
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.rappsilberlab</groupId>
<artifactId>xiFDR</artifactId>
<version>1.0.19</version>
<version>1.0.20</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
Expand Down
37 changes: 30 additions & 7 deletions src/main/java/org/rappsilber/fdr/gui/components/CSVSelection.form
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="cbCSVDElimiter" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cbCSVDElimiter" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="ckCSVHasHeader" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="jLabel27" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cbCSVQuote" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="ckCSVHasHeader" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="ckSmartMatch" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
Expand All @@ -77,15 +80,15 @@
</Group>
</Group>
<Group type="102" attributes="0">
<Component id="fbCsvIn" pref="512" max="32767" attributes="0"/>
<Component id="fbCsvIn" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="btnReadCsv" pref="78" max="32767" attributes="0"/>
<Component id="btnAddCSV" max="32767" attributes="0"/>
</Group>
<EmptySpace min="0" pref="8" max="32767" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
Expand Down Expand Up @@ -128,6 +131,7 @@
<Group type="103" groupAlignment="3" attributes="0">
<Component id="rbCSVLowBetter" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="ckCSVHasHeader" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="ckSmartMatch" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
Expand Down Expand Up @@ -191,7 +195,7 @@
<Component class="javax.swing.JTable" name="tblCSVColumns">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="3" rowCount="23">
<Table columnCount="3" rowCount="25">
<Column editable="false" title="Column" type="java.lang.String">
<Data value="run"/>
<Data value="scan"/>
Expand All @@ -216,6 +220,8 @@
<Data value="peptide position 1"/>
<Data value="peptide position 2"/>
<Data value="Crosslinker"/>
<Data value="experimental mz"/>
<Data value="calculated mass"/>
</Column>
<Column editable="false" title="Optional" type="java.lang.Boolean">
<Data value="true"/>
Expand All @@ -241,6 +247,8 @@
<Data value="null"/>
<Data value="null"/>
<Data value="true"/>
<Data value="true"/>
<Data value="true"/>
</Column>
<Column editable="true" title="Name in CSV" type="java.lang.String">
<Data value=""/>
Expand All @@ -266,6 +274,8 @@
<Data value="null"/>
<Data value="null"/>
<Data value="null"/>
<Data value="null"/>
<Data value="null"/>
</Column>
</Table>
</Property>
Expand All @@ -278,7 +288,11 @@
<Properties>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="hasHeader"/>
<Property name="toolTipText" type="java.lang.String" value="first row of input is considered header"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ckCSVHasHeaderActionPerformed"/>
</Events>
</Component>
<Component class="org.rappsilber.gui.components.FileBrowser" name="fbCsvIn">
<Properties>
Expand Down Expand Up @@ -327,5 +341,14 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnAddCSVActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="ckSmartMatch">
<Properties>
<Property name="text" type="java.lang.String" value="intelligent column matching"/>
<Property name="toolTipText" type="java.lang.String" value="Needs Manual control:tries to select the best header by string distance"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ckSmartMatchActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>
85 changes: 75 additions & 10 deletions src/main/java/org/rappsilber/fdr/gui/components/CSVSelection.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.EventObject;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultCellEditor;
Expand Down Expand Up @@ -57,6 +58,31 @@ public class CSVSelection extends javax.swing.JPanel {

private JoinedThreadedTextOuput m_status = null;

public static String[][] COLUMN_ALIASES = new String[][]{
{"matchid", "spectrummatchid", "match id", "spectrum match id", "psmid"},
{"isdecoy", "is decoy", "reverse", "decoy"},
{"isdecoy1", "is decoy 1", "is decoy1","reverse1", "decoy1", "protein 1 decoy"},
{"isdecoy2", "is decoy 2", "is decoy2", "reverse2", "decoy2", "protein 2 decoy"},
{"score", "match score", "match score", "pep score"},
{"peptide1 score", "pep1 score", "score peptide1", "score pep1", "pep 1 score"},
{"peptide2 score", "pep2 score", "score peptide2", "score pep2", "pep 2 score"},
{"run", "run name", "raw file", "filename/id"},
{"scan", "scan number", "ms/ms scan number", "spectrum number"},
{"pep1 position", "peptide position1", "start1", "peptide position 1", "PepPos1"},
{"pep2 position", "peptide position2", "start2", "peptide position 2", "PepPos2"},
{"pep1 link pos", "link1", "peptide1 link pos", "peptide link1", "peptide link 1", "from site","LinkPos1"},
{"pep2 link pos", "link2", "peptide2 link pos", "peptide link2", "peptide link 2" , "to site","LinkPos2"},
{"lengthpeptide1", "peptide1 length", "peptide1 length", "peptide length 1", "length1"},
{"lengthpeptide2", "peptide2 length", "peptide2 length", "peptide length 2", "length2"},
{"peptide1", "peptide 1", "peptide", "modified sequence"},
{"peptide2" , "peptide 2"},
{"precursermz", "precursor mz", "experimental mz", "exp mz"},
{"precursor charge", "precoursorcharge", "charge"},
{"calculated mass", "calc mass", "theoretical mass"},
{"description1", "fasta1"},
{"description2", "fasta2"},
{"protein1", "display protein1", "accession1"},
{"protein2", "display protein2", "accession2"},};

private class NeededOptionalComboBoxCellEditor extends DefaultCellEditor {

Expand Down Expand Up @@ -141,6 +167,11 @@ public void actionPerformed(ActionEvent e) {

TableColumn columnNamesColumn = tblCSVColumns.getColumnModel().getColumn(2);
columnNamesColumn.setCellEditor(new NeededOptionalComboBoxCellEditor(cbCSVHeaders, cbCSVHeaderOptional));
resetColumnMappings();

}

protected void resetColumnMappings() {
TableModel tm = tblCSVColumns.getModel();
for (int r = 0; r < tblCSVColumns.getRowCount(); r++) {
if (Boolean.TRUE.equals(tm.getValueAt(r, 1))) {
Expand All @@ -149,7 +180,6 @@ public void actionPerformed(ActionEvent e) {
tblCSVColumns.getModel().setValueAt(missingColumn, r, 2);
}
}

}

public void setUpCsvHeaders() {
Expand All @@ -158,7 +188,7 @@ public void setUpCsvHeaders() {
CsvParser csv;
try {
csv = CsvParser.guessCsv(f, 50);
ColumnAlternatives.setupAlternatives(csv);
ColumnAlternatives.setupAlternatives(csv,COLUMN_ALIASES);
String delimiter = csv.getDelimiter();
if (delimiter.contentEquals(",")) {
delimiter = "Comma";
Expand All @@ -177,7 +207,11 @@ public void setUpCsvHeaders() {

if (ckCSVHasHeader.isSelected()) {
csv.setCurrentLineAsHeader();
ColumnAlternatives.levenshteinMatchHeadersALternatives(csv);
HashMap<String,String[]> excludeMappings = new HashMap<>(2);
if (ckSmartMatch.isSelected()) {
excludeMappings.put("psmid",new String[]{"spectra to matched","matchrank","spectrum quality score"});
ColumnAlternatives.levenshteinMatchHeadersAlternatives(csv, excludeMappings,0.7);
}
for (int c = 0; c < csv.getMaxColumns(); c++) {
csvColumns[c + 1] = csv.getHeader(c);
csvColumnsOptional[c + 1] = csv.getHeader(c);
Expand Down Expand Up @@ -333,6 +367,7 @@ private void initComponents() {
btnReadCsv = new javax.swing.JButton();
jLabel27 = new javax.swing.JLabel();
btnAddCSV = new javax.swing.JButton();
ckSmartMatch = new javax.swing.JCheckBox();

cbCSVHeaders.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

Expand Down Expand Up @@ -384,7 +419,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
{"description2", new Boolean(true), null},
{"peptide position 1", null, null},
{"peptide position 2", null, null},
{"Crosslinker", new Boolean(true), null}
{"Crosslinker", new Boolean(true), null},
{"experimental mz", new Boolean(true), null},
{"calculated mass", new Boolean(true), null}
},
new String [] {
"Column", "Optional", "Name in CSV"
Expand All @@ -410,6 +447,12 @@ public boolean isCellEditable(int rowIndex, int columnIndex) {

ckCSVHasHeader.setSelected(true);
ckCSVHasHeader.setText("hasHeader");
ckCSVHasHeader.setToolTipText("first row of input is considered header");
ckCSVHasHeader.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ckCSVHasHeaderActionPerformed(evt);
}
});

fbCsvIn.setDescription("Text Files");
fbCsvIn.setExtensions(new String[] {"csv", "txt", "tsv"});
Expand All @@ -436,6 +479,14 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});

ckSmartMatch.setText("intelligent column matching");
ckSmartMatch.setToolTipText("Needs Manual control:tries to select the best header by string distance");
ckSmartMatch.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ckSmartMatchActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
Expand All @@ -453,25 +504,27 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cbCSVDElimiter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ckCSVHasHeader))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(cbCSVDElimiter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel27)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbCSVQuote, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(ckCSVHasHeader))
.addComponent(ckSmartMatch))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(rbCSVLowBetter)
.addComponent(rbCSVHighBetter)))
.addGroup(layout.createSequentialGroup()
.addComponent(fbCsvIn, javax.swing.GroupLayout.DEFAULT_SIZE, 512, Short.MAX_VALUE)
.addComponent(fbCsvIn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(btnReadCsv, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
.addComponent(btnAddCSV, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(0, 8, Short.MAX_VALUE))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane2)))
Expand Down Expand Up @@ -503,7 +556,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addGap(3, 3, 3)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(rbCSVLowBetter)
.addComponent(ckCSVHasHeader))))
.addComponent(ckCSVHasHeader)
.addComponent(ckSmartMatch))))
.addGap(18, 18, 18)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE)
.addContainerGap())
Expand Down Expand Up @@ -600,6 +654,16 @@ private void btnAddCSVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR
doAddPerformed();
}//GEN-LAST:event_btnAddCSVActionPerformed

private void ckSmartMatchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ckSmartMatchActionPerformed
resetColumnMappings();

setUpCsvHeaders();
}//GEN-LAST:event_ckSmartMatchActionPerformed

private void ckCSVHasHeaderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ckCSVHasHeaderActionPerformed
ckSmartMatch.setEnabled(ckCSVHasHeader.isSelected());
}//GEN-LAST:event_ckCSVHasHeaderActionPerformed

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup bgScoreDirectionCSV;
private javax.swing.JButton btnAddCSV;
Expand All @@ -609,6 +673,7 @@ private void btnAddCSVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR
private javax.swing.JComboBox cbCSVHeaders;
private javax.swing.JComboBox cbCSVQuote;
private javax.swing.JCheckBox ckCSVHasHeader;
private javax.swing.JCheckBox ckSmartMatch;
private org.rappsilber.gui.components.FileBrowser fbCsvIn;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel26;
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/org/rappsilber/utils/SequenceCalculation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2017 lfischer.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.rappsilber.utils;

import java.util.ArrayList;

/**
*
* @author lfischer
*/
public abstract class SequenceCalculation {
public static interface MassCalculator {
double mass(String sequence);
}

static MassCalculator m_masscalc;

public static void setCalculator(MassCalculator cal) {
m_masscalc = cal;
}

public static MassCalculator getMassCalculator() {
return m_masscalc;
}
}

0 comments on commit fe7402a

Please sign in to comment.