Showing posts with label java development. Show all posts
Showing posts with label java development. Show all posts

Tuesday, 26 August 2014

Making Your Code Citable

Original post from GitHub Guides:

Digital Object Identifiers (DOI) are the backbone of the academic reference and metrics system. If you’re a researcher writing software, this guide will show you how to make the work you share on GitHub citable by archiving one of your GitHub repositories and assigning a DOI with the data archiving tool Zenodo.
ProTip: This tutorial is aimed at researchers who want to cite GitHub repositories in academic literature. Provided you’ve already set up a GitHub repository, this tutorial can be completed without installing any special software. If you haven’t yet created a project on GitHub, start first byuploading your work to a repository.

Sunday, 8 June 2014

Java Optimization Tips (Memory, CPU Time and Code)


There are several common optimization techniques that apply regardless of the language being used. Some of these techniques, such as global register allocation, are sophisticated strategies to allocate machine resources (for example, CPU registers) and don't apply to Java bytecodes. We'll focus on the techniques that basically involve restructuring code and substituting equivalent operations within a method.  

EntrySet vs KeySet
-----------------------------------------

More efficient:

for (Map.Entry entry : map.entrySet()) {
    Object key = entry.getKey();
    Object value = entry.getValue();
}

than:

for (Object key : map.keySet()) {
    Object value = map.get(key);
}


Avoid to create threads without run methods
------------------------------------

Usage Example: 

public class Test
{
 public void method() throws Exception
 {
  new Thread().start();  //VIOLATION
 }
}
Should be written as:

public class Test
{
 public void method(Runnable r) throws Exception
 {
  new Thread(r).start();  //FIXED
 }
}

Initialise the ArrayList if you know in advance the size
--------------------------------------------
 
For example, use this code if you expect your ArrayList to store around 1000 objects:

List str = new ArrayList(1000)


Use ternary operators
----------------------------------------

class Use_ternary_operator_correction
{
 public boolean test(String value)
 {
  if(value.equals("AppPerfect"))  // VIOLATION
  {
   return true;
  }
  else
  {
   return false;
  }
 }
}

Should be written as:


class Use_ternary_operator_correction
{
 public boolean test(String value)
 {
  return value.equals("AppPerfect"); // CORRECTION
 }
}


Always declare constant fields Static

public class Always_declare_constant_field_static_violation
{
 final int MAX = 1000; // VIOLATION
 final String NAME = "Noname"; // VIOLATION
}

Should be written as:

public class Always_declare_constant_field_static_correction
{
 static final int MAX = 1000; // CORRECTION
 static final String NAME = "Noname"; // VIOLATION
}

Tuesday, 22 October 2013

Some Reasons to Rename my Blog as BioCode's Notes


Hi Dear Readers:

I’ve decided that it would be prudent, exposure-wise,  to change the name of my professional blog to BioCode's Notes, for a number of reasons:

1. People into bioinformatics comprise a significant part of my –alas, still small- readership. They tend to be always hungry for code tips, language comparisons, and other things that do not fit neatly under the umbrella of “computational proteomics”.

2. My own work is straying more and more from computational proteomics per se into other problems linking biology (Proteomics, Genomics, Life Sciences) with programming (R, Java, Perl, C++). Biocoding is now my bread-and-butter…

3. I need a shorter, catchier name that is easy to use in coffee talks, presentations, or when sharing links with friends.

4. I also decided to add a Blog's mascot, our T-rex:
              Truth    => Science is about Truth.
              Tea: UK Science.
              STaTisTics => OK, this one’s got as many ‘S’ as ‘T’, but the latter is more frequent in English.
              T-rex  => The future belongs to Big Data, which we’ll use (and are already
                                 using) to trace back the march of evolution to our preferred
                                 species, including the dinosaurs. And last, but not least, this is
                                 Abel’s (my son) favorite animal.          

Hope you enjoy this Idea
Yasset

Saturday, 19 October 2013

Which are the best programming languages for a bioinformatician?

This is a basic question when you (as a programmer or biologist or mass spectrometrist) start a career in bioinformatics. What is your favorite programming language in bioinformatics?. This pool will give you a short picture about which languages are mandatory in computational proteomics & bioinformatics. Which languages would you recommend to a student wishing to enter the world of bioinformatics?. We can use this post to comment the strengths and weaknesses of each languages. 






Some Polls and Discussion about this topic can be found in:

Friday, 27 September 2013

Retrieve weka weitghts from Linear Regression

Weka function to retrieve the linear regression weights:

import java.util.List;
import weka.classifiers.Evaluation;
import weka.classifiers.functions.SMOreg;
import weka.classifiers.functions.supportVector.Kernel
.....


public double[] getCoefficients(){
       String svmClassifier = svm.toString();
       List<Double> coefficents = new ArrayList<Double>();
       double[] coeficcientsArray = null;
       if(svmClassifier.contains("weights (not support vectors):")){
          String[] svmClassStrings = svmClassifier.split(System.lineSeparator());
          int i = 0;
          boolean lastFound = false;
          while( i < svmClassStrings.length && !lastFound){
              String currentString = svmClassStrings[i];
              if(currentString.contains("weights (not support vectors):")){
                  i++;
                  while(i < svmClassStrings.length && !lastFound){
                      currentString = svmClassStrings[i];
                      String[] parts = currentString.split("\\s+");
                      if(parts.length < 5){
                          lastFound = true;
                      }else{
                          String number = parts[1] + parts[2];
                          coefficents.add(Double.parseDouble(number));
                      }
                      i++;
                  }
              }
              i++;
          }
        }